internal static void checkDeclComment(Symbol s) { /*if( comments != null ) { * int last_offset = ((DocCommentNode)comments.nodes[comments.nodes.Count-1]).end.offset; * if( this.text.Substring( last_offset, s.pos.offset - last_offset ).Trim().Length != 0 ) * comments = null; * }*/ }
internal static ExprNode Expr(Kind k, Symbol s) { ExprNode res = new ExprNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; return(res); }
internal static PointerType PointerType(TypeNode parent, Symbol s) { PointerType res = new PointerType(); res.kind = Kind.PointerType; res.start = s.pos; res.end = s.endpos; res.parent = parent; return(res); }
internal static TypeName TypeName(IdentNode typename, Symbol s) { TypeName res = new TypeName(); res.kind = Kind.TypeName; res.start = s.pos; res.end = s.endpos; res.typename = typename; return(res); }
internal static BaseType BaseType(BaseTypes typeid, Symbol s) { BaseType res = new BaseType(); res.kind = Kind.BaseType; res.start = s.pos; res.end = s.endpos; res.typeid = typeid; return(res); }
internal static DimSpecNode DimSpec(int count, Symbol s) { DimSpecNode res = new DimSpecNode(); res.kind = Kind.DimSpecifier; res.start = s.pos; res.end = s.endpos; res.count = count; return(res); }
internal static IdentNode Ident(string identifier, Symbol s) { IdentNode res = new IdentNode(); res.kind = Kind.Identifier; res.start = s.pos; res.end = s.endpos; res.identifier = identifier; return(res); }
internal static void Pos(ref Symbol s) { Node n = s.sym as Node; if (n != null) { n.start = s.pos; n.end = s.endpos; } }
internal static UnaryNode Unary(Kind k, ExprNode expr, Symbol s) { UnaryNode res = new UnaryNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; return(res); }
internal static ArrayType ListArrayType(TypeNode parent, ListNode dims, Symbol s) { TypeNode current = parent; foreach (DimSpecNode n in dims.nodes) { current = OneArrayType(current, n, s); } return((ArrayType)current); }
internal static ConstantNode Constant(IdentNode name, ExprNode constant, Symbol s) { ConstantNode res = new ConstantNode(); res.kind = Kind.Constant; res.start = s.pos; res.end = s.endpos; res.name = name; res.constant = constant; return(res); }
internal static VariableNode Variable(IdentNode name, InitializerNode init, Symbol s) { VariableNode res = new VariableNode(); res.kind = Kind.Variable; res.start = s.pos; res.end = s.endpos; res.name = name; res.init = init; return(res); }
// {{Methods}} internal static ListNode List(Node first, Symbol s) { ListNode res = new ListNode(); res.kind = Kind.List; res.start = s.pos; res.end = s.endpos; res.nodes = new ArrayList(); res.nodes.Add(first); return(res); }
internal static TypeExprNode TypeExpr(ExprNode expr, DimSpecNode spec, Symbol s) { TypeExprNode res = new TypeExprNode(); res.kind = Kind.DimmedExpr; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.spec = spec; return(res); }
internal static AssignNode Assign(Kind k, ExprNode dest, ExprNode source, Symbol s) { AssignNode res = new AssignNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.dest = dest; res.source = source; return(res); }
internal static LiteralNode Literal(LiteralNode.Type type, object value, Symbol s) { LiteralNode res = new LiteralNode(); res.kind = Kind.Literal; res.start = s.pos; res.end = s.endpos; res.type = type; res.value = value; return(res); }
internal static ModifiersNode Modifiers(int value, Symbol s) { ModifiersNode res = new ModifiersNode(); res.kind = Kind.Modifiers; res.start = s.pos; res.end = s.endpos; res.value = value; res.start_pos.Add(s.pos.offset); return(res); }
internal static ArrayType ArrayType(TypeNode parent, DimSpecNode dim, Symbol s) { ArrayType res = new ArrayType(); res.kind = Kind.ArrayType; res.start = s.pos; res.end = s.endpos; res.parent = parent; res.dim = dim; return(res); }
internal static BinaryNode Binary(Kind k, ExprNode left, ExprNode right, Symbol s) { BinaryNode res = new BinaryNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.left = left; res.right = right; return(res); }
internal static AttributeNode Attribute(IdentNode name, ListNode parms, Symbol s) { AttributeNode res = new AttributeNode(); res.kind = Kind.Attribute; res.start = s.pos; res.end = s.endpos; res.name = name; res.parms = parms; return(res); }
internal static void Comment(string name, Symbol s) { /*DocCommentNode com = new DocCommentNode( ref s, text ); * * if( comments != null ) { * int last_offset = ((DocCommentNode)comments.nodes[comments.nodes.Count-1]).end.offset; * if( this.text.Substring( last_offset, s.pos.offset - last_offset ).Trim().Length != 0 ) * comments = null; * } * if( comments == null ) * comments = new ListNode( ref s, com ); * else * comments.Add( ref s, com );*/ }
internal static ArrayType OneArrayType(TypeNode parent, DimSpecNode dim, Symbol s) { if (parent.kind != Kind.ArrayType) { return(ArrayType(parent, dim, s)); } else { ArrayType p = (ArrayType)parent; while (p.parent.kind == Kind.ArrayType) { p = (ArrayType)p.parent; } p.parent = Make.ArrayType(p.parent, dim, s); return((ArrayType)parent); } }
internal static TypeNode type_from_expr(ExprNode expr) { Symbol s = new Symbol(); s.pos = expr.start; s.endpos = expr.end; switch (expr.kind) { case Kind.Identifier: return(Make.TypeName((IdentNode)expr, s)); case Kind.Dot: case Kind.TypeDot: string id = String.Empty; while (expr.kind == Kind.Dot) { IdentNode idn = ((BinaryNode)expr).right as IdentNode; id = "." + idn.identifier + id; expr = ((BinaryNode)expr).left; } if (expr.kind == Kind.TypeDot) { // types like: int.A ExprAndTypeNode etn = (ExprAndTypeNode)expr; id = (etn.type as BaseType).typeid.ToString().Substring(1) + "." + (etn.expr as IdentNode).identifier + id; return(Make.TypeName(Make.Ident(id, s), s)); } else if (expr.kind == Kind.Identifier) { // types like: a.b.c ((IdentNode)expr).identifier += id; return(Make.TypeName((IdentNode)expr, s)); } return(null); case Kind.DimmedExpr: TypeExprNode ten = (TypeExprNode)expr; return(Make.OneArrayType(type_from_expr(ten.expr), ten.spec, s)); } return(null); }
internal static ParameterNode Parameter( ListNode attributes, ModifiersNode modifiers, TypeNode type, IdentNode name, Symbol s ) { ParameterNode res = new ParameterNode(); res.kind = Kind.Param; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.type = type; res.name = name; return res; }
internal static void Pos( ref Symbol s ) { Node n = s.sym as Node; if( n != null ) { n.start = s.pos; n.end = s.endpos; } }
internal static NamespaceDecl Namespace( IdentNode name, ListNode usings, ListNode members, Symbol s ) { NamespaceDecl res = new NamespaceDecl(); res.kind = Kind.Namespace; res.start = s.pos; res.end = s.endpos; res.name = name; res.usings = usings; res.members = members; return res; }
internal static ArrayType OneArrayType( TypeNode parent, DimSpecNode dim, Symbol s ) { if( parent.kind != Kind.ArrayType ) return ArrayType( parent, dim, s ); else { ArrayType p = (ArrayType)parent; while( p.parent.kind == Kind.ArrayType ) p = (ArrayType)p.parent; p.parent = Make.ArrayType( p.parent, dim, s ); return (ArrayType)parent; } }
internal static ArrayType ListArrayType( TypeNode parent, ListNode dims, Symbol s ) { TypeNode current = parent; foreach( DimSpecNode n in dims.nodes ) current = OneArrayType( current, n, s ); return (ArrayType)current; }
internal static MethodDecl Method( Kind k, ListNode attributes, ModifiersNode modifiers, IdentNode name, TypeNode return_type, ListNode parameters, StatementNode body, ConstructorInitializerNode base_init, Symbol s ) { MethodDecl res = new MethodDecl(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.name = name; res.return_type = return_type; res.parameters = parameters; res.body = body; res.base_init = base_init; return res; }
internal static InitializerNode Initializer(Kind k, ExprNode expr, ListNode subinits, Symbol s) { InitializerNode res = new InitializerNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.subinits = subinits; return(res); }
internal static MethodDecl Operator(ModifiersNode mod, TypeNode type, IdentNode name, ParameterNode op1, ParameterNode op2, Symbol s) { ListNode ln = new ListNode(); ln.nodes = new ArrayList(); ln.nodes.Add(op1); if (op2 != null) { ln.nodes.Add(op2); } ln.start = op1.start; ln.end = op2 != null ? op2.end : op1.end; ln.kind = Kind.List; return(Method(name == null ? Kind.ConversionOperator : op2 == null ? Kind.UnaryOperator : Kind.BinaryOperator, null, mod, name, type, ln, null, null, s)); }
internal static ConstructorInitializerNode ConstructorInitializer(Kind k, ListNode args, Symbol s) { ConstructorInitializerNode res = new ConstructorInitializerNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.args = args; return(res); }
internal static TypeExprNode TypeExpr( ExprNode expr, DimSpecNode spec, Symbol s ) { TypeExprNode res = new TypeExprNode(); res.kind = Kind.DimmedExpr; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.spec = spec; return res; }
internal static AttributeSectionNode AttributeSection(IdentNode target, ListNode attrs, Symbol s) { AttributeSectionNode res = new AttributeSectionNode(); res.kind = Kind.AttributeSection; res.start = s.pos; res.end = s.endpos; res.target = target; res.attrs = attrs; return(res); }
// {{End}} #endregion #region Hand-made modification routines internal static void AddList(ListNode list, Node next, Symbol s) { list.nodes.Add(next); list.end = s.endpos; }
internal static void AddModifier(ModifiersNode mod, int next, int next_offset, Symbol s) { mod.value |= next; mod.start_pos.Add(next_offset); mod.end = s.endpos; }
internal static StatementNode Statement( Kind k, ExprNode expr, IdentNode label, StatementNode stmt1, StatementNode stmt2, ListNode stmts, Symbol s ) { StatementNode res = new StatementNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.label = label; res.stmt1 = stmt1; res.stmt2 = stmt2; res.stmts = stmts; return res; }
internal static EnumDecl Enum( ListNode attributes, ModifiersNode modifiers, IdentNode name, TypeNode basetype, ListNode children, Symbol s ) { EnumDecl res = new EnumDecl(); res.kind = Kind.Enum; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.name = name; res.basetype = basetype; res.children = children; return res; }
internal static TypeAndListNode TypeAndList( Kind k, TypeNode type, ListNode list, Symbol s ) { TypeAndListNode res = new TypeAndListNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.type = type; res.list = list; return res; }
internal static EnumValueNode EnumValue( ListNode attributes, IdentNode name, ExprNode expr, Symbol s ) { EnumValueNode res = new EnumValueNode(); res.kind = Kind.EnumValue; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.name = name; res.expr = expr; return res; }
// {{Methods}} internal static ListNode List( Node first, Symbol s ) { ListNode res = new ListNode(); res.kind = Kind.List; res.start = s.pos; res.end = s.endpos; res.nodes = new ArrayList(); res.nodes.Add(first); return res; }
internal static EventNode Event( Kind k, ListNode attributes, ModifiersNode modifiers, TypeNode type, IdentNode name, ListNode accessors, ListNode vars, Symbol s ) { EventNode res = new EventNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.type = type; res.name = name; res.accessors = accessors; res.vars = vars; return res; }
internal static LiteralNode Literal( LiteralNode.Type type, object value, Symbol s ) { LiteralNode res = new LiteralNode(); res.kind = Kind.Literal; res.start = s.pos; res.end = s.endpos; res.type = type; res.value = value; return res; }
internal static ExprNode Expr( Kind k, Symbol s ) { ExprNode res = new ExprNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; return res; }
internal static ModifiersNode Modifiers( int value, Symbol s ) { ModifiersNode res = new ModifiersNode(); res.kind = Kind.Modifiers; res.start = s.pos; res.end = s.endpos; res.value = value; res.start_pos.Add( s.pos.offset ); return res; }
internal static ExprAndListNode ExprAndList( Kind k, ExprNode expr, ListNode list, Symbol s ) { ExprAndListNode res = new ExprAndListNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.list = list; return res; }
internal static NewArrayNode NewArray( TypeNode type, ListNode exprlist, ListNode ranks, Node arrayinit, Symbol s ) { NewArrayNode res = new NewArrayNode(); res.kind = Kind.NewArray; res.start = s.pos; res.end = s.endpos; res.type = type; res.exprlist = exprlist; res.ranks = ranks; res.arrayinit = arrayinit; return res; }
internal static ExprAndTypeNode ExprAndType( Kind k, ExprNode expr, TypeNode type, Symbol s ) { ExprAndTypeNode res = new ExprAndTypeNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.type = type; return res; }
internal static MethodDecl Operator( ModifiersNode mod, TypeNode type, IdentNode name, ParameterNode op1, ParameterNode op2, Symbol s ) { ListNode ln = new ListNode(); ln.nodes = new ArrayList(); ln.nodes.Add( op1 ); if( op2 != null ) ln.nodes.Add( op2 ); ln.start = op1.start; ln.end = op2 != null ? op2.end : op1.end; ln.kind = Kind.List; return Method( name == null ? Kind.ConversionOperator : op2 == null ? Kind.UnaryOperator : Kind.BinaryOperator, null, mod, name, type, ln, null, null, s ); }
internal static FieldsDecl Fields( Kind k, ListNode attributes, ModifiersNode modifiers, TypeNode type, ListNode declarators, Symbol s ) { FieldsDecl res = new FieldsDecl(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.type = type; res.declarators = declarators; return res; }
internal static PointerType PointerType( TypeNode parent, Symbol s ) { PointerType res = new PointerType(); res.kind = Kind.PointerType; res.start = s.pos; res.end = s.endpos; res.parent = parent; return res; }
internal static IdentNode Ident( string identifier, Symbol s ) { IdentNode res = new IdentNode(); res.kind = Kind.Identifier; res.start = s.pos; res.end = s.endpos; res.identifier = identifier; return res; }
internal static PropertyNode Property( ListNode attributes, ModifiersNode modifiers, TypeNode type, IdentNode name, ListNode accessors, Symbol s ) { PropertyNode res = new PropertyNode(); res.kind = Kind.Property; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.type = type; res.name = name; res.accessors = accessors; return res; }
internal static IndexerNode Indexer( ListNode attributes, ModifiersNode modifiers, TypeNode type, IdentNode name, ListNode formal_params, ListNode accessors, Symbol s ) { IndexerNode res = new IndexerNode(); res.kind = Kind.Indexer; res.start = s.pos; res.end = s.endpos; res.attributes = attributes; res.modifiers = modifiers; res.type = type; res.name = name; res.formal_params = formal_params; res.accessors = accessors; return res; }
internal static TriplexNode Triplex( ExprNode cond, ExprNode Then, ExprNode Else, Symbol s ) { TriplexNode res = new TriplexNode(); res.kind = Kind.Triplex; res.start = s.pos; res.end = s.endpos; res.cond = cond; res.Then = Then; res.Else = Else; return res; }
internal static InitializerNode Initializer( Kind k, ExprNode expr, ListNode subinits, Symbol s ) { InitializerNode res = new InitializerNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.subinits = subinits; return res; }
internal static TypedStatementNode TypedStatement( Kind k, ExprNode expr, IdentNode label, StatementNode stmt1, StatementNode stmt2, ListNode stmts, TypeNode type, Symbol s ) { TypedStatementNode res = new TypedStatementNode(); res.kind = k; res.start = s.pos; res.end = s.endpos; res.expr = expr; res.label = label; res.stmt1 = stmt1; res.stmt2 = stmt2; res.stmts = stmts; res.type = type; return res; }
internal static void AddIdent(IdentNode id, string postfix, Symbol s) { id.identifier += postfix; id.end = s.endpos; }
internal static TypeName TypeName( IdentNode typename, Symbol s ) { TypeName res = new TypeName(); res.kind = Kind.TypeName; res.start = s.pos; res.end = s.endpos; res.typename = typename; return res; }
internal static DimSpecNode DimSpec( int count, Symbol s ) { DimSpecNode res = new DimSpecNode(); res.kind = Kind.DimSpecifier; res.start = s.pos; res.end = s.endpos; res.count = count; return res; }