public UsingNode(Token token, ParseNode guard, ParseNode body) : base(ParseNodeType.Using, token) { _guard = GetParentedNode(guard); _body = GetParentedNode(body); }
protected ParseNode GetParentedNode(ParseNode child) { if (child != null) { child.SetParent(this); } return child; }
private void Visit(ParseNode node) { bool recurse = ProcessNode(node); if (recurse) { StartChildren(String.Empty); Type nodeType = node.GetType(); foreach (PropertyInfo propertyInfo in nodeType.GetProperties()) { string propertyName = propertyInfo.Name; if (propertyName.Equals("NodeType")) { continue; } if (propertyName.Equals("Parent")) { continue; } if (propertyName.Equals("Token")) { continue; } Visit(node, propertyInfo); } EndChildren(); } }
public BinaryExpressionNode(ParseNode leftChild, TokenType operatorType, ParseNode rightChild) : base(ParseNodeType.BinaryExpression, leftChild.token) { _leftChild = GetParentedNode(leftChild); _operatorType = operatorType; _rightChild = GetParentedNode(rightChild); }
public EnumerationFieldNode(ParseNodeList attributes, AtomicNameNode name, ParseNode value) : base(ParseNodeType.EnumerationFieldDeclaration, name.token) { _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes)); _name = (AtomicNameNode)GetParentedNode(name); if (value is LiteralNode) { LiteralNode literalNode = (LiteralNode)value; _value = ((LiteralToken)literalNode.Token).LiteralValue; } else { // TODO: Clearly we need something more general... // C# allows expressions. Likely expressions to be used // include negative values, binary OR'd values, // expressions involving other enum members (esp. hard to deal with) // For now, just adding support for negative numbers, as // everything else can be worked around in source code. UnaryExpressionNode expressionNode = value as UnaryExpressionNode; if ((expressionNode != null) && (expressionNode.Operator == TokenType.Minus) && (expressionNode.Child is LiteralNode)) { try { LiteralToken literalToken = (LiteralToken)((LiteralNode)expressionNode.Child).Token; int numericValue = (int)Convert.ChangeType(literalToken.LiteralValue, typeof(int)); _value = -numericValue; } catch { } } } }
public ConstantFieldDeclarationNode(Token token, ParseNodeList attributes, Modifiers modifiers, ParseNode type, ParseNodeList initializers) : base(ParseNodeType.ConstFieldDeclaration, token, attributes, modifiers, type, initializers, false) { }
public ConditionalNode(ParseNode condition, ParseNode trueValue, ParseNode falseValue) : base(ParseNodeType.Conditional, condition.token) { _condition = GetParentedNode(condition); _trueValue = GetParentedNode(trueValue); _falseValue = GetParentedNode(falseValue); }
public SwitchNode(Token token, ParseNode condition, ParseNodeList cases) : base(ParseNodeType.Switch, token) { _condition = GetParentedNode(condition); _cases = GetParentedNodeList(cases); }
public void Append(ParseNode node) { if (node != null) { EnsureListCreated(); _list.Add(node); } }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { CompilationUnitNode compilationUnitNode = (CompilationUnitNode)node; foreach (AttributeBlockNode attribBlock in compilationUnitNode.Attributes) { AttributeNode scriptNamespaceNode = AttributeNode.FindAttribute(attribBlock.Attributes, "ScriptNamespace"); if (scriptNamespaceNode != null) { string scriptNamespace = (string)((LiteralNode)scriptNamespaceNode.Arguments[0]).Value; if (Utility.IsValidScriptNamespace(scriptNamespace) == false) { errorHandler.ReportError("A script namespace must be a valid script identifier.", scriptNamespaceNode.Token.Location); } } } foreach (ParseNode childNode in compilationUnitNode.Members) { if (!(childNode is NamespaceNode)) { errorHandler.ReportError("Non-namespaced types are not supported.", childNode.Token.Location); return false; } } return true; }
public LockNode(Token token, ParseNode monitor, ParseNode body) : base(ParseNodeType.Lock, token) { this.monitor = GetParentedNode(monitor); this.body = GetParentedNode(body); }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { NewNode newNode = (NewNode)node; // TODO: This is somewhat hacky - it only looks for any type named Dictionary // rather than resolving the type and checking if its actually // System.Dictionary. // This is because validators don't have a reference to the SymbolSet. NameNode typeNode = newNode.TypeReference as NameNode; if ((typeNode != null) && (typeNode.Name.Equals("Dictionary"))) { if (newNode.Arguments != null) { Debug.Assert(newNode.Arguments is ExpressionListNode); ParseNodeList arguments = ((ExpressionListNode)newNode.Arguments).Expressions; if (arguments.Count != 0) { if (arguments.Count % 2 != 0) { errorHandler.ReportError("Missing value parameter for the last name parameter in Dictionary instantiation.", newNode.Token.Location); } for (int i = 0; i < arguments.Count; i += 2) { ParseNode nameArgumentNode = arguments[i]; if ((nameArgumentNode.NodeType != ParseNodeType.Literal) || (((LiteralNode)nameArgumentNode).Literal.LiteralType != LiteralTokenType.String)) { errorHandler.ReportError("Name parameters in Dictionary instantiation must be string literals.", nameArgumentNode.Token.Location); } } } } } return true; }
public FixedNode(Token token, VariableDeclarationNode declaration, ParseNode body) : base(ParseNodeType.Fixed, token) { _declaration = (VariableDeclarationNode)GetParentedNode(declaration); _body = GetParentedNode(body); }
public Expression BuildExpression(ParseNode node) { Expression expression = null; switch (node.NodeType) { case ParseNodeType.Literal: expression = ProcessLiteralNode((LiteralNode)node); break; case ParseNodeType.Name: case ParseNodeType.GenericName: expression = ProcessNameNode((NameNode)node); break; case ParseNodeType.Typeof: expression = ProcessTypeofNode((TypeofNode)node); break; case ParseNodeType.This: expression = ProcessThisNode((ThisNode)node); break; case ParseNodeType.Base: expression = ProcessBaseNode((BaseNode)node); break; case ParseNodeType.UnaryExpression: expression = ProcessUnaryExpressionNode((UnaryExpressionNode)node); break; case ParseNodeType.BinaryExpression: expression = ProcessBinaryExpressionNode((BinaryExpressionNode)node); break; case ParseNodeType.Conditional: expression = ProcessConditionalNode((ConditionalNode)node); break; case ParseNodeType.New: expression = ProcessNewNode((NewNode)node); break; case ParseNodeType.ArrayNew: expression = ProcessArrayNewNode((ArrayNewNode)node); break; case ParseNodeType.ArrayInitializer: expression = ProcessArrayInitializerNode((ArrayInitializerNode)node); break; case ParseNodeType.ArrayType: expression = ProcessArrayTypeNode((ArrayTypeNode)node); break; case ParseNodeType.PredefinedType: expression = ProcessIntrinsicType((IntrinsicTypeNode)node); break; case ParseNodeType.Cast: expression = ProcessCastNode((CastNode)node); break; case ParseNodeType.AnonymousMethod: expression = ProcessAnonymousMethodNode((AnonymousMethodNode)node); break; default: Debug.Fail("Unhandled Expression Node: " + node.NodeType); break; } if ((node is ExpressionNode) && ((ExpressionNode)node).Parenthesized) { expression.AddParenthesisHint(); } return expression; }
public DoWhileNode(Token token, ParseNode body, ParseNode condition) : base(ParseNodeType.DoWhile, token) { _body = GetParentedNode(body); _condition = GetParentedNode(condition); }
internal void SetParent(ParseNode parent) { if (_list != null) { _list.TrimToSize(); foreach (ParseNode child in this) { child.SetParent(parent); } } }
public CatchNode(Token token, ParseNode type, AtomicNameNode name, ParseNode body) : base(ParseNodeType.Catch, token) { _type = GetParentedNode(type); _name = (AtomicNameNode)GetParentedNode(name); _body = GetParentedNode(body); }
public VariableDeclarationNode(Token token, ParseNodeList attributes, Modifiers modifiers, ParseNode type, ParseNodeList initializers, bool isFixed) : this(ParseNodeType.VariableDeclaration, token, attributes, modifiers, type, initializers, isFixed) { }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { MethodDeclarationNode methodNode = (MethodDeclarationNode)node; if (((methodNode.Modifiers & Modifiers.Static) == 0) && ((methodNode.Modifiers & Modifiers.New) != 0)) { errorHandler.ReportError("The new modifier is not supported on instance members.", methodNode.Token.Location); return false; } if ((methodNode.Modifiers & Modifiers.Extern) != 0) { AttributeNode altSigAttribute = AttributeNode.FindAttribute(methodNode.Attributes, "AlternateSignature"); if (altSigAttribute == null) { errorHandler.ReportError("Extern methods should only be used to declare alternate signatures and marked with [AlternateSignature].", methodNode.Token.Location); return false; } CustomTypeNode typeNode = (CustomTypeNode)methodNode.Parent; MethodDeclarationNode implMethodNode = null; if (methodNode.NodeType == ParseNodeType.MethodDeclaration) { foreach (MemberNode memberNode in typeNode.Members) { if ((memberNode.NodeType == ParseNodeType.MethodDeclaration) && ((memberNode.Modifiers & Modifiers.Extern) == 0) && memberNode.Name.Equals(methodNode.Name, StringComparison.Ordinal)) { implMethodNode = (MethodDeclarationNode)memberNode; break; } } } else if (methodNode.NodeType == ParseNodeType.ConstructorDeclaration) { foreach (MemberNode memberNode in typeNode.Members) { if ((memberNode.NodeType == ParseNodeType.ConstructorDeclaration) && ((memberNode.Modifiers & Modifiers.Extern) == 0)) { implMethodNode = (MethodDeclarationNode)memberNode; break; } } } if (implMethodNode == null) { errorHandler.ReportError("Extern methods used to declare alternate signatures should have a corresponding non-extern implementation as well.", methodNode.Token.Location); return false; } if ((methodNode.Modifiers & (Modifiers.Static | Modifiers.AccessMask)) != (implMethodNode.Modifiers & (Modifiers.Static | Modifiers.AccessMask))) { errorHandler.ReportError("The implemenation method and associated alternate signature methods should have the same access type.", methodNode.Token.Location); } } return true; }
public TryNode(Token token, ParseNode body, ParseNodeList catchClauses, ParseNode finallyClause) : base(ParseNodeType.Try, token) { _body = GetParentedNode(body); _catchClauses = GetParentedNodeList(catchClauses); _finallyClause = GetParentedNode(finallyClause); }
public IfElseNode(Token token, ParseNode condition, ParseNode ifBlock, ParseNode elseBlock) : base(ParseNodeType.IfElse, token) { _condition = GetParentedNode(condition); _ifBlock = GetParentedNode(ifBlock); _elseBlock = GetParentedNode(elseBlock); }
public ArrayNewNode(Token token, ParseNode typeReference, ParseNode expressionList, ParseNode initializerExpression) : base(ParseNodeType.ArrayNew, token) { _typeReference = GetParentedNode(typeReference); _expressionList = GetParentedNode(expressionList); _initializerExpression = GetParentedNode(initializerExpression); }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { ArrayTypeNode typeNode = (ArrayTypeNode)node; if (typeNode.Rank != 1) { errorHandler.ReportError("Only single dimensional arrays are supported.", typeNode.Token.Location); } return true; }
public OperatorDeclarationNode(Token token, ParseNodeList attributes, Modifiers modifiers, TokenType operatorNodeType, ParseNode returnType, ParseNodeList formals, BlockStatementNode body) : base(ParseNodeType.OperatorDeclaration, token, attributes, modifiers, returnType, /* name */ null, formals, body) { this.operatorTokenType = operatorNodeType; }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { NameNode nameNode = (NameNode)node; if (Utility.IsKeyword(nameNode.Name)) { errorHandler.ReportError(nameNode.Name + " is a reserved word.", nameNode.Token.Location); } return true; }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { TryNode tryNode = (TryNode)node; if ((tryNode.CatchClauses != null) && (tryNode.CatchClauses.Count > 1)) { errorHandler.ReportError("Try/Catch statements are limited to a single catch clause.", tryNode.Token.Location); return false; } return true; }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { ParameterNode paramNode = (ParameterNode)node; if (paramNode.Flags != ParameterFlags.None) { errorHandler.ReportError("Out, Ref and Params style of parameters are not yet implemented.", paramNode.Token.Location); return false; } return true; }
bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler) { ThrowNode throwNode = (ThrowNode)node; if (throwNode.Value == null) { errorHandler.ReportError("Throw statements must specify an exception object.", throwNode.Token.Location); return false; } return true; }
public ParameterNode(Token token, ParseNodeList attributes, ParameterFlags flags, ParseNode type, AtomicNameNode name) : base(ParseNodeType.FormalParameter, token) { _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes)); _flags = flags; _type = GetParentedNode(type); _name = (AtomicNameNode)GetParentedNode(name); }
public PropertyDeclarationNode(Token token, ParseNodeList attributes, Modifiers modifiers, ParseNode type, NameNode interfaceType, AtomicNameNode name, AccessorNode getOrRemove, AccessorNode setOrAdd) : this(ParseNodeType.PropertyDeclaration, token, attributes, modifiers, type, interfaceType, getOrRemove, setOrAdd) { _name = (AtomicNameNode)GetParentedNode(name); }
public UnsafeNode(Token token, ParseNode body) : base(ParseNodeType.UnsafeStatement, token) { _body = body; }
public NewNode(Token token, ParseNode typeReference, ParseNode arguments) : base(ParseNodeType.New, token) { _typeReference = GetParentedNode(typeReference); _arguments = GetParentedNode(arguments); }
public ReturnNode(Token token, ParseNode value) : base(ParseNodeType.Return, token) { _value = GetParentedNode(value); }
public ThrowNode(Token token, ParseNode value) : base(ParseNodeType.Throw, token) { _value = GetParentedNode(value); }