protected DeclarationStatementNodeBase(string identifier)
        {
            if (identifier == null)
                ThrowHelper.ThrowArgumentNullException(() => identifier);

            Identifier = new IdentifierNode(identifier);
            AddChildren(Identifier);
        }
        public void TestDeserializeNullException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = null;
            IVisualNode node = new IdentifierNode(graphController, "a");

            Assert.Throws<ArgumentNullException>(() =>
            {
                node.Deserialize(storage);
            });
        }
        public void IdentifierNodeTest()
        {
            StreamLocation expectedLocation = new StreamLocation(3, 2, 1);
            Field<string> retriever = new IntegerField<string>(s => int.Parse(s));
            ParameterExpression arg = Expression.Parameter(typeof(string), "arg");

            ValueNode sut = new IdentifierNode<string>("identifier", retriever, arg, expectedLocation);

            Assert.AreEqual(TNode.IDENTIFIER, sut.NodeType);
            Assert.AreEqual(expectedLocation, sut.Location);
            Assert.IsTrue(sut.Description.Contains("IDENTIFIER"));
            Assert.AreEqual(FieldValueType.INTEGER, sut.ValueType);
            Assert.IsInstanceOfType(sut.SubExpression, typeof(UnaryExpression));
            Assert.AreEqual(ExpressionType.Convert, sut.SubExpression.NodeType);
            Assert.AreEqual(typeof(long?), sut.SubExpression.Type);
            {
                Expression invokeExpr = ((UnaryExpression)sut.SubExpression).Operand;
                Assert.IsInstanceOfType(invokeExpr, typeof(InvocationExpression));
                Assert.AreEqual(ExpressionType.Invoke, invokeExpr.NodeType);
                Assert.AreEqual(arg, ((InvocationExpression)invokeExpr).Arguments[0]);
            }
        }
Example #4
0
 public virtual void Visit(IdentifierNode node)
 {
     node.Accept(Visitor);
 }
Example #5
0
 /// <summary>
 /// Creates a new type denoter node
 /// </summary>
 /// <param name="identifier">The identifier associated with the node, i.e. the name of the type</param>
 public TypeDenoterNode(IdentifierNode identifier)
 {
     Identifier = identifier;
 }
Example #6
0
        public override object VisitExpr(Z80AsmParser.ExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            // --- Extract the expression text
            var sb = new StringBuilder(400);

            for (var i = 0; i < context.ChildCount; i++)
            {
                var token = context.GetChild(i).GetText();
                sb.Append(token);
            }

            ExpressionNode expr = null;

            switch (context)
            {
            // --- Primary operators
            case Z80AsmParser.BuiltInFunctionExprContext ctx:
                expr = (ExpressionNode)VisitBuiltinFunctionInvocation(ctx.builtinFunctionInvocation());
                break;

            case Z80AsmParser.FunctionInvocationExprContext ctx:
                expr = new FunctionInvocationNode(ctx.functionInvocation(), this);
                break;

            case Z80AsmParser.MacroParamExprContext ctx:
                expr = new MacroParamNode(ctx.macroParam(), this);
                break;

            // --- Unary operators
            case Z80AsmParser.UnaryPlusExprContext ctx:
                expr = new UnaryPlusNode(ctx, this);
                break;

            case Z80AsmParser.UnaryMinusExprContext ctx:
                expr = new UnaryMinusNode(ctx, this);
                break;

            case Z80AsmParser.BinaryNotExprContext ctx:
                expr = new UnaryBitwiseNotNode(ctx, this);
                break;

            case Z80AsmParser.LogicalNotExprContext ctx:
                expr = new UnaryLogicalNotNode(ctx, this);
                break;

            // --- Bracketed/Parenthesized expressions
            case Z80AsmParser.BracketedExprContext ctx:
                expr = (ExpressionNode)VisitExpr(ctx.expr());
                break;

            case Z80AsmParser.ParenthesizedExprContext ctx:
                expr = (ExpressionNode)VisitExpr(ctx.expr());
                break;

            // --- Literals
            case Z80AsmParser.LiteralExprContext ctx:
                expr = (ExpressionNode)VisitLiteral(ctx.literal());
                break;

            case Z80AsmParser.SymbolExprContext ctx:
                if (ctx.ChildCount != 0 && ctx.symbol()?.IDENTIFIER() != null)
                {
                    AddIdentifier(ctx);
                    expr = new IdentifierNode(ctx.symbol());
                }
                break;

            // --- Min/Max operators
            case Z80AsmParser.MinMaxExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<?":
                    expr = new MinOperationNode(ctx, this);
                    break;

                default:
                    expr = new MaxOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Multiplication operators
            case Z80AsmParser.MultExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "*":
                    expr = new MultiplyOperationNode(ctx, this);
                    break;

                case "/":
                    expr = new DivideOperationNode(ctx, this);
                    break;

                default:
                    expr = new ModuloOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Addition operators
            case Z80AsmParser.AddExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "+":
                    expr = new AddOperationNode(ctx, this);
                    break;

                default:
                    expr = new SubtractOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Shift operators
            case Z80AsmParser.ShiftExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<<":
                    expr = new ShiftLeftOperationNode(ctx, this);
                    break;

                default:
                    expr = new ShiftRightOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Relational operators
            case Z80AsmParser.RelExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<":
                    expr = new LessThanOperationNode(ctx, this);
                    break;

                case "<=":
                    expr = new LessThanOrEqualOperationNode(ctx, this);
                    break;

                case ">":
                    expr = new GreaterThanOperationNode(ctx, this);
                    break;

                default:
                    expr = new GreaterThanOrEqualOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Equality operators
            case Z80AsmParser.EquExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "==":
                    expr = new EqualOperationNode(ctx, this);
                    break;

                case "===":
                    expr = new CaseInsensitiveEqualOperationNode(ctx, this);
                    break;

                case "!=":
                    expr = new NotEqualOperationNode(ctx, this);
                    break;

                default:
                    expr = new CaseInsensitiveNotEqualOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Bitwise operators
            case Z80AsmParser.AndExprContext ctx:
                expr = new BitwiseAndOperationNode(ctx, this);
                break;

            case Z80AsmParser.XorExprContext ctx:
                expr = new BitwiseXorOperationNode(ctx, this);
                break;

            case Z80AsmParser.OrExprContext ctx:
                expr = new BitwiseOrOperationNode(ctx, this);
                break;

            // --- Ternary operator
            case Z80AsmParser.TernaryExprContext ctx:
                expr = new ConditionalExpressionNode(ctx, this);
                break;
            }

            if (expr != null)
            {
                expr.SourceText = sb.ToString();
            }
            return(expr);
        }
Example #7
0
        private bool TryParseInputExpression(string inputSymbol,
                                             out IdentifierNode identifier,
                                             out AssociativeNode defaultValue,
                                             out string comment)
        {
            identifier   = null;
            defaultValue = null;
            comment      = null;

            var parseString = InputSymbol;

            parseString += ";";

            // During loading of symbol node from file, the elementResolver from the workspace is unavailable
            // in which case, a local copy of the ER obtained from the symbol node is used
            var resolver   = workspaceElementResolver ?? ElementResolver;
            var parseParam = new ParseParam(this.GUID, parseString, resolver);

            if (EngineController.CompilationServices.PreCompileCodeBlock(ref parseParam) &&
                parseParam.ParsedNodes.Any())
            {
                var parsedComments = parseParam.ParsedComments;
                if (parsedComments.Any())
                {
                    comment = String.Join("\n", parsedComments.Select(c => (c as CommentNode).Value));
                }

                var node = parseParam.ParsedNodes.First() as BinaryExpressionNode;
                if (node != null)
                {
                    var leftIdent  = node.LeftNode as IdentifierNode;
                    var rightIdent = node.RightNode as IdentifierNode;

                    // "x" will be compiled to "temp_guid = x";
                    if (leftIdent != null && leftIdent.Value.StartsWith(Constants.kTempVarForNonAssignment))
                    {
                        identifier = rightIdent;
                    }
                    // "x:int" will be compiled to "x:int = tTypedIdent0";
                    else if (rightIdent != null && rightIdent.Value.StartsWith(Constants.kTempVarForTypedIdentifier))
                    {
                        identifier = leftIdent;
                    }
                    else
                    {
                        identifier = leftIdent;
                    }

                    if (inputSymbol.Contains('='))
                    {
                        defaultValue = node.RightNode;
                    }

                    if (parseParam.Errors.Any())
                    {
                        this.Error(parseParam.Errors.First().Message);
                    }
                    else if (parseParam.Warnings.Any())
                    {
                        var warnings = parseParam.Warnings.Where(w => w.ID != WarningID.IdUnboundIdentifier);
                        if (warnings.Any())
                        {
                            this.Warning(parseParam.Warnings.First().Message);
                        }
                    }

                    return(identifier != null);
                }
            }

            return(false);
        }
        /// <summary>
        /// Create BinaryExpressionNode
        /// </summary>
        /// <param name="node"></param>
        /// <param name="outnode"></param>
        private void EmitBlockNode(Block node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);

            // TODO: Confirm that these children are returned in the order that they
            // appear in the code
            Dictionary <int, Node> childNodes = node.GetChildrenWithIndices();

            // Parse program statement in node.Name
            string code = node.Name + ";";

            ProtoCore.AST.AssociativeAST.CodeBlockNode commentNode   = null;
            ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockNode = (ProtoCore.AST.AssociativeAST.CodeBlockNode)GraphUtilities.Parse(code, out commentNode);
            Validity.Assert(codeBlockNode != null);

            List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList = codeBlockNode.Body;

            Validity.Assert(astList.Count == 1);

            if (astList[0] is ProtoCore.AST.AssociativeAST.IdentifierNode)
            {
                ProtoCore.AST.AssociativeAST.BinaryExpressionNode ben = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode();
                ben.LeftNode = astList[0];
                ben.Optr     = ProtoCore.DSASM.Operator.assign;
                ProtoCore.AST.AssociativeAST.AssociativeNode statement = null;
                foreach (KeyValuePair <int, Node> kvp in childNodes)
                {
                    DFSTraverse(kvp.Value, out statement);
                }
                ben.RightNode = statement;
                astList[0]    = ben;
            }

            //I don't know what I am doing
            if (astList[0] is BinaryExpressionNode)
            {
                BinaryExpressionNode tempBen = astList[0] as BinaryExpressionNode;
                if (tempBen.LeftNode is IdentifierNode)
                {
                    IdentifierNode identitiferNode = tempBen.LeftNode as IdentifierNode;
                    if (identitiferNode.ArrayDimensions != null)
                    {
                        ArrayIndexerNode arrIndex = new ArrayIndexerNode();
                        arrIndex.ArrayDimensions = identitiferNode.ArrayDimensions;
                        arrIndex.Array           = identitiferNode;
                        tempBen.LeftNode         = arrIndex;
                    }
                }
                if (tempBen.RightNode is IdentifierNode)
                {
                    IdentifierNode identitiferNode = tempBen.RightNode as IdentifierNode;
                    if (identitiferNode.ArrayDimensions != null)
                    {
                        ArrayIndexerNode arrIndex = new ArrayIndexerNode();
                        arrIndex.ArrayDimensions = identitiferNode.ArrayDimensions;
                        arrIndex.Array           = identitiferNode;
                        tempBen.RightNode        = arrIndex;
                    }
                }
                astList[0] = tempBen;
            }
            //it should be correct, if not, debug?

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode bNode = astList[0] as ProtoCore.AST.AssociativeAST.BinaryExpressionNode;
            Validity.Assert(bNode != null);
            bNode.Guid = node.Guid;
            //bNode.SplitFromUID = node.splitFomUint;

            // Child nodes are arguments to expression in bNode.RightNode.
            // Match child nodes with IdentifierNode's in bNode.RightNode - pratapa
            foreach (Node n in childNodes.Values)
            {
                AssociativeNode argNode = null;
                DFSTraverse(n, out argNode);

                // DFS traverse the bNode.RightNode and check for IdentifierNode's
                // and if their names match with the names of argNode, then replace
                // the IdentifierNode in bNode.RightNode with argNode
                BinaryExpressionNode ben = argNode as BinaryExpressionNode;
                Validity.Assert(ben != null);
                //ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(ben);
                AstCodeBlockTraverse sourceGen = new AstCodeBlockTraverse(ben);
                ProtoCore.AST.AssociativeAST.AssociativeNode right = bNode.RightNode;
                sourceGen.DFSTraverse(ref right);
                bNode.RightNode = right;
            }

            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);

            Validity.Assert(gc != null);
            gc.HandleNewNode(bNode);

            outnode = bNode;
        }
Example #9
0
 public virtual void VisitIdentifierNode(IdentifierNode node)
 {
     DefaultVisit(node);
 }
Example #10
0
        private static IEnumerable <AST.Node> ParseUserCodeCore(Core core, string expression, string postfixGuid, ref bool parseSuccess)
        {
            List <ProtoCore.AST.Node> astNodes = new List <ProtoCore.AST.Node>();

            core.ResetForPrecompilation();
            core.IsParsingCodeBlockNode = true;
            core.ParsingMode            = ParseMode.AllowNonAssignment;

            ProtoCore.AST.Node codeBlockNode = ProtoCore.Utils.ParserUtils.ParseWithCore(expression, core);
            parseSuccess = true;
            List <ProtoCore.AST.Node> nodes = ParserUtils.GetAstNodes(codeBlockNode);

            Validity.Assert(nodes != null);

            int index = 0;

            foreach (var node in nodes)
            {
                ProtoCore.AST.AssociativeAST.AssociativeNode n = node as ProtoCore.AST.AssociativeAST.AssociativeNode;
                ProtoCore.Utils.Validity.Assert(n != null);

                // Append the temporaries only if it is not a function def or class decl
                bool isFunctionOrClassDef = n is FunctionDefinitionNode || n is ClassDeclNode;

                // Handle non Binary expression nodes separately
                if (n is ProtoCore.AST.AssociativeAST.ModifierStackNode)
                {
                    core.BuildStatus.LogSemanticError("Modifier Blocks are not supported currently.");
                }
                else if (n is ProtoCore.AST.AssociativeAST.ImportNode)
                {
                    core.BuildStatus.LogSemanticError("Import statements are not supported in CodeBlock Nodes.");
                }
                else if (isFunctionOrClassDef)
                {
                    // Add node as it is
                    astNodes.Add(node);
                }
                else
                {
                    // Handle temporary naming for temporary Binary exp. nodes and non-assignment nodes
                    BinaryExpressionNode ben = node as BinaryExpressionNode;
                    if (ben != null && ben.Optr == ProtoCore.DSASM.Operator.assign)
                    {
                        ModifierStackNode mNode = ben.RightNode as ModifierStackNode;
                        if (mNode != null)
                        {
                            core.BuildStatus.LogSemanticError("Modifier Blocks are not supported currently.");
                        }
                        IdentifierNode lNode = ben.LeftNode as IdentifierNode;
                        if (lNode != null && lNode.Value == ProtoCore.DSASM.Constants.kTempProcLeftVar)
                        {
                            string name = string.Format("temp_{0}_{1}", index++, postfixGuid);
                            BinaryExpressionNode newNode = new BinaryExpressionNode(new IdentifierNode(name), ben.RightNode);
                            astNodes.Add(newNode);
                        }
                        else
                        {
                            // Add node as it is
                            astNodes.Add(node);
                        }
                    }
                    else
                    {
                        // These nodes are non-assignment nodes
                        string name = string.Format("temp_{0}_{1}", index++, postfixGuid);
                        BinaryExpressionNode newNode = new BinaryExpressionNode(new IdentifierNode(name), n);
                        astNodes.Add(newNode);
                    }
                }
            }
            return(astNodes);
        }
    // $ANTLR start "primaryExpression"
    // JavaScript.g:330:1: primaryExpression : ( 'this' | Identifier | literal | arrayLiteral | objectLiteral | '(' expression ')' );
    public JavaScriptParser.primaryExpression_return primaryExpression() // throws RecognitionException [1]
    {   
        JavaScriptParser.primaryExpression_return retval = new JavaScriptParser.primaryExpression_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken string_literal396 = null;
        IToken Identifier397 = null;
        IToken char_literal401 = null;
        IToken char_literal403 = null;
        JavaScriptParser.literal_return literal398 = default(JavaScriptParser.literal_return);

        JavaScriptParser.arrayLiteral_return arrayLiteral399 = default(JavaScriptParser.arrayLiteral_return);

        JavaScriptParser.objectLiteral_return objectLiteral400 = default(JavaScriptParser.objectLiteral_return);

        JavaScriptParser.expression_return expression402 = default(JavaScriptParser.expression_return);


        object string_literal396_tree=null;
        object Identifier397_tree=null;
        object char_literal401_tree=null;
        object char_literal403_tree=null;

        try 
    	{
            // JavaScript.g:331:2: ( 'this' | Identifier | literal | arrayLiteral | objectLiteral | '(' expression ')' )
            int alt201 = 6;
            switch ( input.LA(1) ) 
            {
            case 111:
            	{
                alt201 = 1;
                }
                break;
            case Identifier:
            	{
                alt201 = 2;
                }
                break;
            case StringLiteral:
            case NumericLiteral:
            case RegexLiteral:
            case 112:
            case 113:
            case 114:
            	{
                alt201 = 3;
                }
                break;
            case 67:
            	{
                alt201 = 4;
                }
                break;
            case 40:
            	{
                alt201 = 5;
                }
                break;
            case 42:
            	{
                alt201 = 6;
                }
                break;
            	default:
            	    if ( state.backtracking > 0 ) {state.failed = true; return retval;}
            	    NoViableAltException nvae_d201s0 =
            	        new NoViableAltException("", 201, 0, input);

            	    throw nvae_d201s0;
            }

            switch (alt201) 
            {
                case 1 :
                    // JavaScript.g:331:4: 'this'
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	string_literal396=(IToken)Match(input,111,FOLLOW_111_in_primaryExpression3017); if (state.failed) return retval;
                    	if ( state.backtracking == 0 )
                    	{string_literal396_tree = new ThisRef(string_literal396) ;
                    		adaptor.AddChild(root_0, string_literal396_tree);
                    	}

                    }
                    break;
                case 2 :
                    // JavaScript.g:332:4: Identifier
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	Identifier397=(IToken)Match(input,Identifier,FOLLOW_Identifier_in_primaryExpression3026); if (state.failed) return retval;
                    	if ( state.backtracking == 0 )
                    	{Identifier397_tree = new IdentifierNode(Identifier397) ;
                    		adaptor.AddChild(root_0, Identifier397_tree);
                    	}

                    }
                    break;
                case 3 :
                    // JavaScript.g:333:4: literal
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_literal_in_primaryExpression3034);
                    	literal398 = literal();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, literal398.Tree);

                    }
                    break;
                case 4 :
                    // JavaScript.g:334:4: arrayLiteral
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_arrayLiteral_in_primaryExpression3040);
                    	arrayLiteral399 = arrayLiteral();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, arrayLiteral399.Tree);

                    }
                    break;
                case 5 :
                    // JavaScript.g:335:4: objectLiteral
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	PushFollow(FOLLOW_objectLiteral_in_primaryExpression3046);
                    	objectLiteral400 = objectLiteral();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, objectLiteral400.Tree);

                    }
                    break;
                case 6 :
                    // JavaScript.g:336:4: '(' expression ')'
                    {
                    	root_0 = (object)adaptor.GetNilNode();

                    	char_literal401=(IToken)Match(input,42,FOLLOW_42_in_primaryExpression3052); if (state.failed) return retval;
                    	PushFollow(FOLLOW_expression_in_primaryExpression3055);
                    	expression402 = expression();
                    	state.followingStackPointer--;
                    	if (state.failed) return retval;
                    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, expression402.Tree);
                    	char_literal403=(IToken)Match(input,44,FOLLOW_44_in_primaryExpression3057); if (state.failed) return retval;

                    }
                    break;

            }
            retval.Stop = input.LT(-1);

            if ( (state.backtracking==0) )
            {	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);}
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
Example #12
0
        public static IVisualNode Create(IGraphController graphController, IStorage storage)
        {
            if (graphController == null || storage == null)
                throw new ArgumentNullException("graphcontroller, storage");

            storage.Seek(12, SeekOrigin.Current); //Skip NodeSignature
            NodeType type = (NodeType)storage.ReadInteger(FieldCode.NodeType);
            storage.Seek(-24, SeekOrigin.Current); //Shift cursor back to the start point of reading NodeSignature
            VisualNode node = null;
            switch (type)
            {
                case NodeType.CodeBlock:
                    node = new CodeBlockNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Condensed:
                    node = new CondensedNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Driver:
                    node = new DriverNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Function:
                    node = new FunctionNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Identifier:
                    node = new IdentifierNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Property:
                    node = new PropertyNode(graphController);
                    node.Deserialize(storage);
                    break;
                case NodeType.Render:
                    node = new RenderNode(graphController);
                    node.Deserialize(storage);
                    break;
                default:
                    throw new ArgumentException("Invalid 'nodeType'");
            }

            return node;
        }
        public void TestDeserilaizeOperationException()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();
            IVisualNode node = new IdentifierNode(graphController, "a");

            ulong signature = Utilities.MakeEightCC('T', 'E', 'S', 'T', ' ', ' ', ' ', ' ');
            storage.WriteUnsignedInteger(signature, 21);
            storage.Seek(0, SeekOrigin.Begin);

            bool result = node.Deserialize(storage);
            Assert.AreEqual(result, false);
        }
        public void TestSerializeDeserialize()
        {
            IGraphController graphController = new GraphController(null);
            IStorage storage = new BinaryStorage();

            IVisualNode node1 = new IdentifierNode(graphController, "a");
            IVisualNode node2 = new IdentifierNode(graphController, "b");

            node1.Serialize(storage);
            storage.Seek(0, SeekOrigin.Begin);
            node2.Deserialize(storage);

            Assert.AreEqual(NodeType.Identifier, node2.VisualType);
            Assert.AreEqual(node1.NodeId, node2.NodeId);
            Assert.AreEqual(true, ((IdentifierNode)node2).Dirty);
            Assert.AreEqual(((IdentifierNode)node1).Text, ((IdentifierNode)node2).Text);
            Assert.AreEqual(((IdentifierNode)node1).Caption, ((IdentifierNode)node2).Caption);
            Assert.AreEqual(node1.X, node2.X);
            Assert.AreEqual(node1.Y, node2.Y);
            Assert.AreEqual(1, node2.GetInputSlots().Length);
            Assert.AreEqual(1, node2.GetOutputSlots().Length);
        }
 public MarkupExtensionNode(IdentifierNode identifier) : this(identifier, new OptionsCollection())
 {            
 }
 public virtual bool VisitIdentifierNode(IdentifierNode node)
 {
     return(DefaultVisit(node));
 }
Example #17
0
 protected bool Equals(IdentifierNode other)
 {
     return string.Equals(Prefix, other.Prefix) && string.Equals(TypeName, other.TypeName);
 }
        public IArithmeticNode Factor()
        {
            IArithmeticNode factorNode = new BlankNode();

            switch (curTokenType)
            {
                case TokenType.LPAREN:
                    Match(ref matchToken, TokenType.LPAREN);
                    factorNode = BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    break;
                case TokenType.ID:
                    String idName = lookAheadToken.getValue();
                    factorNode = new IdentifierNode(idName, IdentifierType.UNKNOWN);
                    Match(ref matchToken, TokenType.ID);
                    /*if (lookAheadToken.getType() == TokenType.LPAREN)
                    {
                        Match(ref matchToken, TokenType.LPAREN);
                        ITreeNode argument = BooleanExpression();
                        Match(ref matchToken, TokenType.RPAREN);
                        factorNode = new FunctionCallNode(idName, argument);
                    }*/
                    break;
                case TokenType.INTEGER:
                    factorNode = new IntegerNode(int.Parse(lookAheadToken.getValue()));
                    Match(ref matchToken, TokenType.INTEGER);
                    break;
                case TokenType.MINUS:       //unary minus
                    Match(ref matchToken, TokenType.MINUS);
                    IArithmeticNode tempNode = Expression();
                    tempNode.setNegative();
                    factorNode = tempNode;
                    break;
                default:
                    Expect(TokenType.UNKNOWN, lookAheadToken);
                    break;
            }
            return factorNode;
        }
Example #19
0
        private static void ParseUserCodeCore(Core core, string expression, out List <AssociativeNode> astNodes, out List <AssociativeNode> commentNodes)
        {
            astNodes = new List <AssociativeNode>();

            core.ResetForPrecompilation();
            core.IsParsingCodeBlockNode = true;
            core.ParsingMode            = ParseMode.AllowNonAssignment;

            ParseResult parseResult = ParserUtils.ParseWithCore(expression, core);

            commentNodes = ParserUtils.GetAstNodes(parseResult.CommentBlockNode);
            var nodes = ParserUtils.GetAstNodes(parseResult.CodeBlockNode);

            Validity.Assert(nodes != null);

            int index           = 0;
            int typedIdentIndex = 0;

            foreach (var node in nodes)
            {
                var n = node as AssociativeNode;
                Validity.Assert(n != null);

                // Append the temporaries only if it is not a function def or class decl
                bool isFunctionOrClassDef = n is FunctionDefinitionNode;

                if (n is ImportNode)
                {
                    core.BuildStatus.LogSemanticError(Resources.ImportStatementNotSupported);
                }
                else if (n is ClassDeclNode)
                {
                    core.BuildStatus.LogSemanticError(Resources.ClassDeclarationNotSupported);
                }
                else if (isFunctionOrClassDef)
                {
                    // Add node as it is
                    astNodes.Add(node);
                }
                else
                {
                    // Handle temporary naming for temporary Binary exp. nodes and non-assignment nodes
                    var ben = node as BinaryExpressionNode;
                    if (ben != null && ben.Optr == Operator.assign)
                    {
                        var lNode = ben.LeftNode as IdentifierNode;
                        if (lNode != null && lNode.Value == Constants.kTempProcLeftVar)
                        {
                            string name    = Constants.kTempVarForNonAssignment + index;
                            var    newNode = new BinaryExpressionNode(new IdentifierNode(name), ben.RightNode);
                            astNodes.Add(newNode);
                            index++;
                        }
                        else
                        {
                            // Add node as it is
                            astNodes.Add(node);
                            index++;
                        }
                    }
                    else
                    {
                        if (node is TypedIdentifierNode)
                        {
                            // e.g. a : int = %tTypedIdent_<Index>;
                            var ident = new IdentifierNode(Constants.kTempVarForTypedIdentifier + typedIdentIndex);
                            NodeUtils.CopyNodeLocation(ident, node);
                            var typedNode = new BinaryExpressionNode(node as TypedIdentifierNode, ident, Operator.assign);
                            NodeUtils.CopyNodeLocation(typedNode, node);
                            astNodes.Add(typedNode);
                            typedIdentIndex++;
                        }
                        else
                        {
                            string name    = Constants.kTempVarForNonAssignment + index;
                            var    newNode = new BinaryExpressionNode(new IdentifierNode(name), n);
                            astNodes.Add(newNode);
                            index++;
                        }
                    }
                }
            }
        }
        public ITreeNode Program()
        {
            ITreeNode programNode = new ErrorNode();

            switch (curTokenType)
            {
                case TokenType.BEGINBL:
                    Match(ref matchToken, TokenType.BEGINBL);
                    ITreeNode someStatement = Program();
                    BlockNode block = new BlockNode();
                    block.addStatement(someStatement);
                    while (curTokenType != TokenType.ENDBL)
                    {
                        someStatement = Program();
                        block.addStatement(someStatement);
                    }
                    Match(ref matchToken, TokenType.ENDBL);
                    programNode = block;
                    break;
                case TokenType.LABEL:
                    Match(ref matchToken, TokenType.LABEL);
                    LabelNode labeledBlock = new LabelNode(matchToken.getValue());
                    ITreeNode labeledStatement;
                    do
                    {
                        labeledStatement = Program();
                        labeledBlock.addStatement(labeledStatement);
                    }
                    while (curTokenType != TokenType.EOF);
                    programNode = labeledBlock;
                    break;
                case TokenType.INTDEC:
                    Match(ref matchToken, TokenType.INTDEC);
                    Match(ref matchToken, TokenType.ID);
                    programNode = new IdentifierDeclarationNode(IdentifierType.INT, matchToken.getValue());
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.BOOLDEC:
                    Match(ref matchToken, TokenType.BOOLDEC);
                    Match(ref matchToken, TokenType.ID);
                    programNode = new IdentifierDeclarationNode(IdentifierType.BOOL, matchToken.getValue());
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.FOR:
                    Match(ref matchToken, TokenType.FOR);
                    Match(ref matchToken, TokenType.LPAREN);
                    AssignmentNode init = (AssignmentNode)Program();
                    AssignmentNode step = (AssignmentNode)Program();
                    BooleanExpressionNode condition = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    BlockNode forBody = (BlockNode)Program();
                    programNode = new ForNode(init, step, condition, forBody);
                    break;
                /*case TokenType.FUN:
                    Match(ref matchToken, TokenType.FUN);
                    IdentifierNode id = (IdentifierNode)Factor();
                    programNode = new FunctionNode(id);
                    Match(ref matchToken, TokenType.EOS);
                    break;*/
                case TokenType.GOTO:
                    Match(ref matchToken, TokenType.GOTO);
                    Match(ref matchToken, TokenType.ID);
                    IdentifierNode gotoLabel = new IdentifierNode(matchToken.getValue(), IdentifierType.LABEL);
                    programNode = new GotoNode(gotoLabel);
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.ID:
                    Match(ref matchToken, TokenType.ID);
                    IdentifierNode assignId = new IdentifierNode(matchToken.getValue(), IdentifierType.UNKNOWN);
                    Match(ref matchToken, TokenType.ASSIGN);
                    BooleanExpressionNode assignValue = (BooleanExpressionNode)BooleanExpression();
                    programNode = new AssignmentNode(assignId, assignValue);
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.IF:
                    Match(ref matchToken, TokenType.IF);
                    ITreeNode thenBranch;
                    ITreeNode elseBranch;

                    Match(ref matchToken, TokenType.LPAREN);
                    BooleanExpressionNode ifCondition = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    Match(ref matchToken, TokenType.THEN);
                    thenBranch = (BlockNode)Program();
                    if (curTokenType == TokenType.ELSE)
                    {
                        Match(ref matchToken, TokenType.ELSE);
                        elseBranch = (BlockNode)Program();
                    }
                    else
                    {
                        elseBranch = new BlankNode();
                    }
                    programNode = new IfNode(ifCondition, thenBranch, elseBranch);
                    break;
                /*case TokenType.LET:
                    Match(ref matchToken, TokenType.LET);
                    IdentifierNode shortId = (IdentifierNode)Factor();
                    Match(ref matchToken, TokenType.ASSIGN);
                    BooleanExpressionNode subst = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.IN);
                    BooleanExpressionNode target = (BooleanExpressionNode)BooleanExpression();
                    programNode = new LetNode(shortId, subst, target);
                    Match(ref matchToken, TokenType.EOS);
                    break;*/
                case TokenType.PRINT:
                    Match(ref matchToken, TokenType.PRINT);
                    Match(ref matchToken, TokenType.LPAREN);
                    BooleanExpressionNode printArgument = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    programNode = new PrintNode(printArgument);
                    Match(ref matchToken, TokenType.EOS);
                    break;
                case TokenType.WHILE:
                    Match(ref matchToken, TokenType.WHILE);
                    Match(ref matchToken, TokenType.LPAREN);
                    BooleanExpressionNode whileCondition = (BooleanExpressionNode)BooleanExpression();
                    Match(ref matchToken, TokenType.RPAREN);
                    BlockNode whileBody = (BlockNode)Program();
                    programNode = new WhileNode(whileCondition, whileBody);
                    break;
                case TokenType.EOF:
                    programNode = new BlankNode();
                    break;
                default:
                    Expect(TokenType.UNKNOWN, lookAheadToken);
                    break;
            }
            return programNode;
        }
Example #21
0
 public override object VisitIdentifier(IdentifierNode identifierNode, TData data)
 {
     return(null);
 }
		public virtual Value evaluate(Context cx, IdentifierNode node)
		{
			output("<IdentifierNode name=\"" + node.name + "\"/>");
			return null;
		}
 public MarkupExtensionNode(IdentifierNode identifier, OptionsCollection options)
 {
     Options = new OptionsCollection(options);
     Identifier = identifier;
 }
Example #24
0
        public IdentifierNode(IdentifierNode rhs) : base(rhs)
        {
            datatype = new ProtoCore.Type
            {
                UID = rhs.datatype.UID,
                rank = rhs.datatype.rank,
                Name = rhs.datatype.Name
            };

            Value = rhs.Value;
            IsLocal = false;
        }
Example #25
0
        private bool TryParseOutputExpression(string expression, out IdentifierNode outputIdentifier, out string comment)
        {
            outputIdentifier = null;
            comment          = null;

            var resolver   = workspaceElementResolver ?? ElementResolver;
            var parseParam = new ParseParam(GUID, expression + ";", resolver);

            EngineController.CompilationServices.PreCompileCodeBlock(ref parseParam);
            if (parseParam.ParsedNodes.Any())
            {
                var parsedComments = parseParam.ParsedComments;
                if (parsedComments.Any())
                {
                    comment = String.Join("\n", parsedComments.Select(c => (c as CommentNode).Value));
                }

                if (parseParam.ParsedNodes.Count() > 1)
                {
                    this.Warning(Properties.Resources.WarningInvalidOutput);
                }

                var node = parseParam.ParsedNodes.First() as BinaryExpressionNode;
                if (node == null)
                {
                    if (parseParam.Errors.Any())
                    {
                        this.Error(Properties.Resources.WarningInvalidOutput);
                    }
                }
                else
                {
                    var leftIdent  = node.LeftNode as IdentifierNode;
                    var rightIdent = node.RightNode as IdentifierNode;

                    // "x" will be compiled to "temp_guid = x;"
                    if (leftIdent != null && leftIdent.Value.StartsWith(Constants.kTempVarForNonAssignment))
                    {
                        outputIdentifier = rightIdent;
                    }
                    // "x:int" will be compiled to "x:int = tTypedIdent0;"
                    else if (rightIdent != null && rightIdent.Value.StartsWith(Constants.kTempVarForTypedIdentifier))
                    {
                        outputIdentifier = leftIdent;
                    }
                    else
                    {
                        if (parseParam.Errors.Any())
                        {
                            this.Error(parseParam.Errors.First().Message);
                        }
                        else
                        {
                            this.Warning(Properties.Resources.WarningInvalidOutput);
                        }
                        outputIdentifier = leftIdent;
                    }
                    return(outputIdentifier != null);
                }
            }

            return(false);
        }
Example #26
0
        // Factor = [ "-" ], Number | Identifier | ParenExpression | FunctionCall
        private Node ParseFactor()
        {
            if (tokenStream.Consume("-"))
                return new UnaryMinusNode(ParseFactor());

            Node factor = null;

            if (tokenStream.Consume(TokenType.Number))
            {
                Double termValue = Convert.ToDouble(ConsumedToken.Value, CultureInfo.InvariantCulture);

                factor = new NumberNode(termValue);
            }
            else if (CurrentToken.Type == TokenType.Identifier)
            {
                var lookAhead = tokenStream.LookAhead();
                if (lookAhead != null && lookAhead.Value == "(")
                    return ParseFunctionCall();

                tokenStream.Consume();
                factor = new IdentifierNode(tokenStream.ConsumedToken.Value);
            }
            else if (tokenStream.Consume("("))
            {
                factor = ParseExpression();

                tokenStream.Expect(")");
            }

            if (factor == null)
                throw new Exception("Number, identifier or function call expected");

            return factor;
        }
 public AstNode VisitIdentifier(IdentifierNode n)
 {
     Append(n.Id);
     return(n);
 }
Example #28
0
 public IdExpressionNode(IdentifierNode identifier, IParameterNode parameterNode)
 {
     Identifier    = identifier;
     ParameterNode = parameterNode;
 }
        public static ProtoCore.AST.AssociativeAST.FunctionDotCallNode GenerateCallDotNode(ProtoCore.AST.AssociativeAST.AssociativeNode lhs,
                                                                                           ProtoCore.AST.AssociativeAST.FunctionCallNode rhsCall, Core core = null)
        {
            // The function name to call
            string rhsName = rhsCall.Function.Name;
            int    argNum  = rhsCall.FormalArguments.Count;

            ProtoCore.AST.AssociativeAST.ExprListNode argList = new ProtoCore.AST.AssociativeAST.ExprListNode();
            foreach (ProtoCore.AST.AssociativeAST.AssociativeNode arg in rhsCall.FormalArguments)
            {
                // The function arguments
                argList.list.Add(arg);
            }


            FunctionCallNode funCallNode = new FunctionCallNode();
            IdentifierNode   funcName    = new IdentifierNode {
                Value = Constants.kDotArgMethodName, Name = Constants.kDotArgMethodName
            };

            funCallNode.Function = funcName;
            funCallNode.Name     = Constants.kDotArgMethodName;

            NodeUtils.CopyNodeLocation(funCallNode, lhs);
            int    rhsIdx  = ProtoCore.DSASM.Constants.kInvalidIndex;
            string lhsName = string.Empty;

            if (lhs is ProtoCore.AST.AssociativeAST.IdentifierNode)
            {
                lhsName = (lhs as ProtoCore.AST.AssociativeAST.IdentifierNode).Name;
                if (lhsName == ProtoCore.DSDefinitions.Keyword.This)
                {
                    lhs = new ProtoCore.AST.AssociativeAST.ThisPointerNode();
                }
            }

            if (core != null)
            {
                DynamicFunction func;
                if (core.DynamicFunctionTable.TryGetFunction(rhsName, 0, Constants.kInvalidIndex, out func))
                {
                    rhsIdx = func.Index;
                }
                else
                {
                    func   = core.DynamicFunctionTable.AddNewFunction(rhsName, 0, Constants.kInvalidIndex);
                    rhsIdx = func.Index;
                }
            }

            // The first param to the dot arg (the pointer or the class name)
            funCallNode.FormalArguments.Add(lhs);

            // The second param which is the dynamic table index of the function to call
            var rhs = new IntNode(rhsIdx);

            funCallNode.FormalArguments.Add(rhs);

            // The array dimensions
            ProtoCore.AST.AssociativeAST.ExprListNode arrayDimExperList = new ProtoCore.AST.AssociativeAST.ExprListNode();
            int dimCount = 0;

            if (rhsCall.Function is ProtoCore.AST.AssociativeAST.IdentifierNode)
            {
                // Number of dimensions
                ProtoCore.AST.AssociativeAST.IdentifierNode fIdent = rhsCall.Function as ProtoCore.AST.AssociativeAST.IdentifierNode;
                if (fIdent.ArrayDimensions != null)
                {
                    arrayDimExperList = ProtoCore.Utils.CoreUtils.BuildArrayExprList(fIdent.ArrayDimensions);
                    dimCount          = arrayDimExperList.list.Count;
                }
                else if (rhsCall.ArrayDimensions != null)
                {
                    arrayDimExperList = ProtoCore.Utils.CoreUtils.BuildArrayExprList(rhsCall.ArrayDimensions);
                    dimCount          = arrayDimExperList.list.Count;
                }
                else
                {
                    arrayDimExperList = new ProtoCore.AST.AssociativeAST.ExprListNode();
                }
            }

            funCallNode.FormalArguments.Add(arrayDimExperList);

            // Number of dimensions
            var dimNode = new IntNode(dimCount);

            funCallNode.FormalArguments.Add(dimNode);

            if (argNum >= 0)
            {
                funCallNode.FormalArguments.Add(argList);
                funCallNode.FormalArguments.Add(new IntNode(argNum));
            }

            var funDotCallNode = new FunctionDotCallNode(rhsCall);

            funDotCallNode.DotCall = funCallNode;
            funDotCallNode.FunctionCall.Function = rhsCall.Function;

            // Consider the case of "myClass.Foo(a, b)", we will have "DotCall" being
            // equal to "myClass" (in terms of its starting line/column), and "rhsCall"
            // matching with the location of "Foo(a, b)". For execution cursor to cover
            // this whole statement, the final "DotCall" function call node should
            // range from "lhs.col" to "rhs.col".
            //
            NodeUtils.SetNodeEndLocation(funDotCallNode.DotCall, rhsCall);
            NodeUtils.CopyNodeLocation(funDotCallNode, funDotCallNode.DotCall);


            return(funDotCallNode);
        }
Example #30
0
 public ParameterNode(TypeDeclarationNode type, IdentifierNode identifier)
 {
     this.type       = type;
     this.identifier = identifier;
 }
Example #31
0
        /// <summary>
        /// Carries out identification on an identifier node
        /// </summary>
        /// <param name="identifier">The node to perform identification on</param>
        private void PerformIdentificationOnIdentifier(IdentifierNode identifier)
        {
            IDeclarationNode declaration = SymbolTable.Retrieve(identifier.IdentifierToken.Spelling);

            identifier.Declaration = declaration;
        }
Example #32
0
 public void Visit(Node node)
 {
     if (node is ArgumentsListNode)
     {
         VisitSubnodes(node);
     }
     else if (node is BinaryOperationNode)
     {
         BinaryOperationNode binop = (BinaryOperationNode)node;
         if (binop.BinaryOperation == BinaryOperation.Assignment)
         {
             if (binop.Left is IdentifierNode)
             {
                 IdentifierNode ident = (IdentifierNode)binop.Left;
                 if (!symbolTable.IsSymbolDefined(ident.Name))
                 {
                     symbolTable.AddSymbol(ident.Name);
                 }
             }
         }
         VisitSubnodes(node);
     }
     else if (node is ClassDeclarationNode)
     {
         throw new System.Exception("Can't define an class inside of an function.");
     }
     else if (node is CodeBlock)
     {
         VisitSubnodes(node);
     }
     else if (node is EnumDeclarationNode)
     {
         symbolTable.AddSymbol(((EnumDeclarationNode)node).Name);
     }
     else if (node is ExpressionNode)
     {
         VisitSubnodes(node);
     }
     else if (node is ForNode)
     {
         VisitSubnodes(node);
     }
     else if (node is FunctionCallNode)
     {
         VisitSubnodes(node);
     }
     else if (node is FunctionDeclarationNode)
     {
         throw new System.Exception("Can't define an function inside of an function.");
     }
     else if (node is GetAttributeNode)
     {
         VisitSubnodes(node);
     }
     else if (node is IfNode)
     {
         VisitSubnodes(node);
     }
     else if (node is IndexerNode)
     {
         VisitSubnodes(node);
     }
     else if (node is ReturnNode)
     {
         VisitSubnodes(node);
     }
     else if (node is ScopeNode)
     {
         symbolTable.BeginScope();
         VisitSubnodes(node);
         symbolTable.EndScope();
     }
     else if (node is FunctionDeclarationNode)
     {
         throw new System.Exception("Using statement is not valid inside function body.");
     }
     else if (node is WhileNode)
     {
         VisitSubnodes(node);
     }
 }
Example #33
0
 public virtual TAssociative VisitIdentifierNode(IdentifierNode node)
 {
     return(VisitAssociativeNode(node));
 }
Example #34
0
        public static FunctionDotCallNode GenerateCallDotNode(AssociativeNode lhs,
                                                              FunctionCallNode rhsCall, Core core = null)
        {
            // The function name to call
            string       rhsName = rhsCall.Function.Name;
            int          argNum  = rhsCall.FormalArguments.Count;
            ExprListNode argList = new ExprListNode();

            foreach (AssociativeNode arg in rhsCall.FormalArguments)
            {
                // The function arguments
                argList.Exprs.Add(arg);
            }

            var arguments = new List <AssociativeNode>();

            int    rhsIdx  = DSASM.Constants.kInvalidIndex;
            string lhsName = string.Empty;

            if (lhs is IdentifierNode)
            {
                lhsName = (lhs as IdentifierNode).Name;
                if (lhsName == DSDefinitions.Keyword.This)
                {
                    lhs = new ThisPointerNode();
                }
            }

            if (core != null)
            {
                DynamicFunction func;
                if (core.DynamicFunctionTable.TryGetFunction(rhsName, 0, Constants.kInvalidIndex, out func))
                {
                    rhsIdx = func.Index;
                }
                else
                {
                    func   = core.DynamicFunctionTable.AddNewFunction(rhsName, 0, Constants.kInvalidIndex);
                    rhsIdx = func.Index;
                }
            }

            // The first param to the dot arg (the pointer or the class name)
            arguments.Add(lhs);

            // The second param which is the dynamic table index of the function to call
            arguments.Add(new IntNode(rhsIdx));

            // The array dimensions
            ExprListNode arrayDimExperList = new ExprListNode();
            int          dimCount          = 0;

            if (rhsCall.Function is IdentifierNode)
            {
                // Number of dimensions
                IdentifierNode fIdent = rhsCall.Function as IdentifierNode;
                if (fIdent.ArrayDimensions != null)
                {
                    arrayDimExperList = CoreUtils.BuildArrayExprList(fIdent.ArrayDimensions);
                    dimCount          = arrayDimExperList.Exprs.Count;
                }
                else if (rhsCall.ArrayDimensions != null)
                {
                    arrayDimExperList = CoreUtils.BuildArrayExprList(rhsCall.ArrayDimensions);
                    dimCount          = arrayDimExperList.Exprs.Count;
                }
                else
                {
                    arrayDimExperList = new ExprListNode();
                }
            }

            arguments.Add(arrayDimExperList);

            // Number of dimensions
            var dimNode = new IntNode(dimCount);

            arguments.Add(dimNode);

            if (argNum >= 0)
            {
                arguments.Add(argList);
                arguments.Add(new IntNode(argNum));
            }

            var funDotCallNode = new FunctionDotCallNode(rhsCall, arguments);

            // funDotCallNode.FunctionCall.Function = rhsCall.Function;
            NodeUtils.SetNodeEndLocation(funDotCallNode, rhsCall);
            return(funDotCallNode);
        }
Example #35
0
 public MethodParameterNode(TypeNode type, IdentifierNode ident, SourceCodePosition pos)
     : base(pos)
 {
     Type       = type;
     Identifier = ident;
 }
 public static string NotDeclaredVariable(IdentifierNode node)
 {
     return($"({node.Line}, {node.Column}) - Semantic Error: The name " +
            $"'{node.Text}' does not exist in the current context."
            );
 }
 public void Visit(IdentifierNode node)
 {
     node.Accept(_visitor);
 }
 public static string RepeatedVariable(IdentifierNode node)
 {
     return($"({node.Line}, {node.Column}) - Semantic Error" +
            $" The variable '{node.Text}' is already defined in this scope."
            );
 }
Example #39
0
        /// <summary>
        /// Check does some sanity check, e.g., if a variable is re-defined.
        /// </summary>
        /// <param name="asts"></param>
        private static List <WarningEntry> Check(IEnumerable <AssociativeNode> asts)
        {
            var warnings = new List <WarningEntry>();

            HashSet <string> scope = new HashSet <string>();

            foreach (var node in asts)
            {
                BinaryExpressionNode bnode = node as BinaryExpressionNode;
                if (bnode == null || bnode.Optr != Operator.assign)
                {
                    var fNode = node as FunctionDefinitionNode;
                    if (fNode != null)
                    {
                        var fbody = NodeUtils.Clone(fNode.FunctionBody) as CodeBlockNode;
                        var body  = fbody.Body;

                        warnings.AddRange(Check(body));

                        fNode.FunctionBody.Body.Clear();
                        fNode.FunctionBody.Body.AddRange(body.Where(n => !n.skipMe));
                    }

                    continue;
                }

                IdentifierNode ident = bnode.LeftNode as IdentifierNode;
                if (ident == null)
                {
                    continue;
                }

                var variable = ident.Value;

                if (!scope.Contains(variable))
                {
                    scope.Add(variable);

                    VariableFinder finder = new VariableFinder(variable);

                    var langNode = bnode.RightNode as LanguageBlockNode;
                    if (langNode != null)
                    {
                        var cbn = langNode.CodeBlockNode as CodeBlockNode;
                        if (cbn != null)
                        {
                            var copy = NodeUtils.Clone(cbn) as CodeBlockNode;

                            warnings.AddRange(Check(copy.Body));

                            cbn.Body.Clear();
                            cbn.Body.AddRange(copy.Body.Where(n => !n.skipMe));
                        }
                        continue;
                    }
                    bnode.RightNode.Accept(finder);

                    if (finder.Found)
                    {
                        warnings.Add(new WarningEntry
                        {
                            Message = String.Format(Resources.VariableRecursiveReference, variable),
                        });
                        node.skipMe = true;
                    }
                }
                else if (ident.ArrayDimensions == null)
                {
                    warnings.Add(new WarningEntry
                    {
                        Message = String.Format(Resources.VariableRedifinitionError, variable),
                    });
                    node.skipMe = true;
                }
            }

            return(warnings);
        }
Example #40
0
 public void Visit(IdentifierNode node)
 {
 }
Example #41
0
 public override dynamic Visit(IdentifierNode node)
 {
     return(node.Token.Content);
 }
Example #42
0
 public void Visit(IdentifierNode node)
 {
     Nodes.Push(new IdentifierNode(node.Name));
 }
Example #43
0
 public BoolType(IdentifierNode identifier) : this()
 {
     this.identifier = identifier;
 }
Example #44
0
        void ArgDecl(out Node node)
        {
            IdentifierNode tNode       = null;
            VarDeclNode    varDeclNode = new ProtoImperative.AST.VarDeclNode();

            varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;

            if (la.kind == 25)
            {
                Get();
                varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemHeap;
            }
            if (isArrayAccess())
            {
                arrayident(out node);
                tNode = node as IdentifierNode;
                varDeclNode.NameNode = tNode;
            }
            else if (la.kind == 1)
            {
                Get();
                tNode = new IdentifierNode()
                {
                    Value    = t.val,
                    Name     = t.val,
                    type     = (int)ProtoCore.PrimitiveType.kTypeVar,
                    datatype = ProtoCore.PrimitiveType.kTypeVar
                };
                varDeclNode.NameNode = tNode;
            }
            else
            {
                SynErr(68);
            }
            ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = "var"; argtype.rank = 0; argtype.UID = 0;
            if (la.kind == 36)
            {
                Get();
                Expect(1);
                argtype.Name = t.val;
                if (la.kind == 6)
                {
                    argtype.IsIndexable = true;
                    Get();
                    Expect(7);
                    argtype.rank = 1;
                    if (la.kind == 6 || la.kind == 17 || la.kind == 31)
                    {
                        if (la.kind == 17)
                        {
                            Get();
                            Expect(6);
                            Expect(7);
                            argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank;
                        }
                        else
                        {
                            while (la.kind == 6)
                            {
                                Get();
                                Expect(7);
                                argtype.rank++;
                            }
                        }
                    }
                }
            }
            varDeclNode.ArgumentType = argtype;
            if (la.kind == 31)
            {
                Get();
                Node rhsNode;
                expr(out rhsNode);
                BinaryExpressionNode bNode = new BinaryExpressionNode();
                bNode.LeftNode       = tNode;
                bNode.RightNode      = rhsNode;
                bNode.Optr           = Operator.assign;
                varDeclNode.NameNode = bNode;
            }
            node = varDeclNode;
            if (!isGlobalScope)
            {
                localVarCount++;
            }
        }
Example #45
0
 public ParameterNode(ASTNode typeNode, IdentifierNode identifier, SourcePosition position) : base(position, identifier.Content, LexTokenType.None)
 {
     this.Type       = typeNode;
     this.Identifier = identifier;
 }
        public void TestHandleSaveGraphAndLoadGraph()
        {
            try
            {
                GraphController graphController1 = new GraphController(null);
                IVisualNode node1 = new CodeBlockNode(graphController1, "Double Click and Type");
                IVisualNode node2 = new DriverNode(graphController1, Configurations.DriverInitialTextValue);
                IVisualNode node3 = new FunctionNode(graphController1, "", "-", "double,double");
                IVisualNode node4 = new IdentifierNode(graphController1, "c");

                string filePath = Path.GetTempPath() + "test.bin";
                graphController1.DoSaveGraph(filePath);
                GraphController graphController2 = new GraphController(null, filePath);

                Assert.AreEqual(4, graphController2.GetVisualNodes().Count);
            }
            finally
            {
                File.Delete(Path.GetTempPath() + "test.bin");
            }
        }