コード例 #1
0
ファイル: UsingNode.cs プロジェクト: fugaku/scriptsharp
 public UsingNode(Token token,
                  ParseNode guard,
                  ParseNode body)
     : base(ParseNodeType.Using, token) {
     _guard = GetParentedNode(guard);
     _body = GetParentedNode(body);
 }
コード例 #2
0
ファイル: ParseNode.cs プロジェクト: mobilligy/scriptsharp
 protected ParseNode GetParentedNode(ParseNode child)
 {
     if (child != null) {
         child.SetParent(this);
     }
     return child;
 }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
 public BinaryExpressionNode(ParseNode leftChild, TokenType operatorType, ParseNode rightChild)
     : base(ParseNodeType.BinaryExpression, leftChild.token)
 {
     _leftChild = GetParentedNode(leftChild);
     _operatorType = operatorType;
     _rightChild = GetParentedNode(rightChild);
 }
コード例 #5
0
        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 {
                    }
                }
            }
        }
コード例 #6
0
 public ConstantFieldDeclarationNode(Token token,
                                     ParseNodeList attributes,
                                     Modifiers modifiers,
                                     ParseNode type,
                                     ParseNodeList initializers)
     : base(ParseNodeType.ConstFieldDeclaration, token, attributes, modifiers, type, initializers, false) {
 }
コード例 #7
0
 public ConditionalNode(ParseNode condition, ParseNode trueValue, ParseNode falseValue)
     : base(ParseNodeType.Conditional, condition.token)
 {
     _condition = GetParentedNode(condition);
     _trueValue = GetParentedNode(trueValue);
     _falseValue = GetParentedNode(falseValue);
 }
コード例 #8
0
ファイル: SwitchNode.cs プロジェクト: fugaku/scriptsharp
 public SwitchNode(Token token,
                   ParseNode condition,
                   ParseNodeList cases)
     : base(ParseNodeType.Switch, token) {
     _condition = GetParentedNode(condition);
     _cases = GetParentedNodeList(cases);
 }
コード例 #9
0
 public void Append(ParseNode node)
 {
     if (node != null) {
         EnsureListCreated();
         _list.Add(node);
     }
 }
コード例 #10
0
        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;
        }
コード例 #11
0
ファイル: LockNode.cs プロジェクト: fugaku/scriptsharp
 public LockNode(Token token,
                 ParseNode monitor,
                 ParseNode body)
     : base(ParseNodeType.Lock, token) {
     this.monitor = GetParentedNode(monitor);
     this.body = GetParentedNode(body);
 }
コード例 #12
0
        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;
        }
コード例 #13
0
ファイル: FixedNode.cs プロジェクト: fugaku/scriptsharp
 public FixedNode(Token token,
                  VariableDeclarationNode declaration,
                  ParseNode body)
     : base(ParseNodeType.Fixed, token) {
     _declaration = (VariableDeclarationNode)GetParentedNode(declaration);
     _body = GetParentedNode(body);
 }
コード例 #14
0
        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;
        }
コード例 #15
0
ファイル: DoWhileNode.cs プロジェクト: fugaku/scriptsharp
 public DoWhileNode(Token token,
               ParseNode body,
               ParseNode condition)
     : base(ParseNodeType.DoWhile, token) {
     _body = GetParentedNode(body);
     _condition = GetParentedNode(condition);
 }
コード例 #16
0
ファイル: ParseNodeList.cs プロジェクト: fugaku/scriptsharp
 internal void SetParent(ParseNode parent) {
     if (_list != null) {
         _list.TrimToSize();
         foreach (ParseNode child in this) {
             child.SetParent(parent);
         }
     }
 }
コード例 #17
0
ファイル: CatchNode.cs プロジェクト: fugaku/scriptsharp
 public CatchNode(Token token, ParseNode type,
                  AtomicNameNode name,
                  ParseNode body)
     : base(ParseNodeType.Catch, token) {
     _type = GetParentedNode(type);
     _name = (AtomicNameNode)GetParentedNode(name);
     _body = GetParentedNode(body);
 }
コード例 #18
0
 public VariableDeclarationNode(Token token,
                                ParseNodeList attributes,
                                Modifiers modifiers,
                                ParseNode type,
                                ParseNodeList initializers,
                                bool isFixed)
     : this(ParseNodeType.VariableDeclaration, token, attributes, modifiers, type, initializers, isFixed) {
 }
コード例 #19
0
        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;
        }
コード例 #20
0
ファイル: TryNode.cs プロジェクト: fugaku/scriptsharp
 public TryNode(Token token,
                ParseNode body,
                ParseNodeList catchClauses,
                ParseNode finallyClause)
     : base(ParseNodeType.Try, token) {
     _body = GetParentedNode(body);
     _catchClauses = GetParentedNodeList(catchClauses);
     _finallyClause = GetParentedNode(finallyClause);
 }
コード例 #21
0
ファイル: IfElseNode.cs プロジェクト: fugaku/scriptsharp
 public IfElseNode(Token token,
               ParseNode condition,
               ParseNode ifBlock,
               ParseNode elseBlock)
     : base(ParseNodeType.IfElse, token) {
     _condition = GetParentedNode(condition);
     _ifBlock = GetParentedNode(ifBlock);
     _elseBlock = GetParentedNode(elseBlock);
 }
コード例 #22
0
ファイル: ArrayNewNode.cs プロジェクト: fugaku/scriptsharp
 public ArrayNewNode(Token token,
                     ParseNode typeReference,
                     ParseNode expressionList,
                     ParseNode initializerExpression)
     : base(ParseNodeType.ArrayNew, token) {
     _typeReference = GetParentedNode(typeReference);
     _expressionList = GetParentedNode(expressionList);
     _initializerExpression = GetParentedNode(initializerExpression);
 }
コード例 #23
0
        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;
        }
コード例 #24
0
 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;
 }
コード例 #25
0
        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;
        }
コード例 #26
0
        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;
        }
コード例 #27
0
        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;
        }
コード例 #28
0
        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;
        }
コード例 #29
0
ファイル: ParameterNode.cs プロジェクト: fugaku/scriptsharp
 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);
 }
コード例 #30
0
 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);
 }
コード例 #31
0
 public UnsafeNode(Token token, ParseNode body)
     : base(ParseNodeType.UnsafeStatement, token)
 {
     _body = body;
 }
コード例 #32
0
 public NewNode(Token token, ParseNode typeReference, ParseNode arguments)
     : base(ParseNodeType.New, token)
 {
     _typeReference = GetParentedNode(typeReference);
     _arguments     = GetParentedNode(arguments);
 }
コード例 #33
0
 public ReturnNode(Token token, ParseNode value)
     : base(ParseNodeType.Return, token)
 {
     _value = GetParentedNode(value);
 }
コード例 #34
0
 public ThrowNode(Token token, ParseNode value)
     : base(ParseNodeType.Throw, token)
 {
     _value = GetParentedNode(value);
 }