Exemplo n.º 1
0
        internal override IEnumerable <AssociativeNode> BuildAst(List <AssociativeNode> inputAstNodes)
        {
            //Do not build if the node is in error.
            if (State == ElementState.Error)
            {
                return(null);
            }

            var resultNodes = new List <AssociativeNode>();

            // Define unbound variables if necessary
            if (inputIdentifiers != null &&
                inputAstNodes != null &&
                inputIdentifiers.Count == inputAstNodes.Count)
            {
                var initStatments = inputIdentifiers.Zip(inputAstNodes,
                                                         (ident, rhs) =>
                {
                    var identNode = AstFactory.BuildIdentifier(ident);
                    MapIdentifiers(identNode);
                    return(AstFactory.BuildAssignment(identNode, rhs));
                });
                resultNodes.AddRange(initStatments);
            }

            foreach (var astNode in codeStatements.Select(stmnt => NodeUtils.Clone(stmnt.AstNode)))
            {
                MapIdentifiers(astNode);
                resultNodes.Add(astNode as AssociativeNode);
            }

            return(resultNodes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// For code block nodes, each output identifier of an output port is mapped.
        /// For an example, "p = 1" would have its internal identifier renamed to
        /// "pXXXX", where "XXXX" is the GUID of the code block node. This mapping is
        /// done to ensure the uniqueness of the output variable name.
        /// </summary>
        /// <param name="portIndex">Output port index</param>
        /// <param name="forRawName">Set this parameter to true to retrieve the
        /// original identifier name "p". If this parameter is false, the mapped
        /// identifer name "pXXXX" is returned instead.</param>
        /// <returns></returns>
        private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName)
        {
            var statement = GetStatementForOutput(portIndex);

            if (statement == null)
            {
                return(null);
            }

            var binExprNode = statement.AstNode as BinaryExpressionNode;

            if (binExprNode == null || (binExprNode.LeftNode == null))
            {
                return(null);
            }

            var identNode   = binExprNode.LeftNode as IdentifierNode;
            var mappedIdent = NodeUtils.Clone(identNode);

            if (!forRawName)
            {
                MapIdentifiers(mappedIdent);
            }

            return(mappedIdent as IdentifierNode);
        }
Exemplo n.º 3
0
 public CodeBlockNode(CodeBlockNode rhs) : base(rhs)
 {
     Body = new List <ImperativeNode>();
     foreach (ImperativeNode aNode in rhs.Body)
     {
         ImperativeNode newNode = NodeUtils.Clone(aNode);
         Body.Add(newNode);
     }
 }
Exemplo n.º 4
0
 public ExprListNode(ExprListNode rhs)
     : base(rhs)
 {
     Exprs = new List <ImperativeNode>();
     foreach (ImperativeNode argNode in rhs.Exprs)
     {
         ImperativeNode tempNode = NodeUtils.Clone(argNode);
         Exprs.Add(tempNode);
     }
 }
Exemplo n.º 5
0
 public WhileStmtNode(WhileStmtNode rhs) : base(rhs)
 {
     Expr = NodeUtils.Clone(rhs.Expr);
     Body = new List <ImperativeNode>();
     foreach (ImperativeNode iNode in rhs.Body)
     {
         ImperativeNode newNode = NodeUtils.Clone(iNode);
         Body.Add(newNode);
     }
 }
Exemplo n.º 6
0
 public FunctionCallNode(FunctionCallNode rhs) : base(rhs)
 {
     Function        = NodeUtils.Clone(rhs.Function);
     FormalArguments = new List <ImperativeNode>();
     foreach (ImperativeNode argNode in rhs.FormalArguments)
     {
         ImperativeNode tempNode = NodeUtils.Clone(argNode);
         FormalArguments.Add(tempNode);
     }
 }
Exemplo n.º 7
0
 public RangeExprNode(RangeExprNode rhs) : base(rhs)
 {
     From = NodeUtils.Clone(rhs.From);
     To   = NodeUtils.Clone(rhs.To);
     if (null != rhs.Step)
     {
         Step = NodeUtils.Clone(rhs.Step);
     }
     StepOperator           = rhs.StepOperator;
     HasRangeAmountOperator = rhs.HasRangeAmountOperator;
 }
Exemplo n.º 8
0
 public LanguageBlockNode(LanguageBlockNode rhs) : base(rhs)
 {
     CodeBlockNode = ProtoCore.Utils.NodeUtils.Clone(rhs.CodeBlockNode);
     codeblock     = new ProtoCore.LanguageCodeBlock(rhs.codeblock);
     Attributes    = new List <ImperativeNode>();
     foreach (ImperativeNode aNode in rhs.Attributes)
     {
         ImperativeNode newNode = ProtoCore.Utils.NodeUtils.Clone(aNode);
         Attributes.Add(newNode);
     }
     CodeBlockNode = NodeUtils.Clone(rhs.CodeBlockNode);
 }
Exemplo n.º 9
0
        /// <summary>
        /// For code block nodes, each output identifier of an output port is mapped.
        /// For an example, "p = 1" would have its internal identifier renamed to
        /// "pXXXX", where "XXXX" is the GUID of the code block node. This mapping is
        /// done to ensure the uniqueness of the output variable name.
        /// </summary>
        /// <param name="portIndex">Output port index</param>
        /// <param name="forRawName">Set this parameter to true to retrieve the
        /// original identifier name "p". If this parameter is false, the mapped
        /// identifer name "pXXXX" is returned instead.</param>
        /// <returns></returns>
        private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName)
        {
            if (State == ElementState.Error)
            {
                return(null);
            }

            // Here the "portIndex" is back mapped to the corresponding "Statement"
            // object. However, not all "Statement" objects produce an output port,
            // so "portIndex" cannot be used directly to index into "codeStatements"
            // list. This loop goes through "codeStatements", decrementing "portIndex"
            // along the way to determine the right "Statement" object matching the
            // port index.
            //
            Statement statement = null;
            var       svs       = CodeBlockUtils.GetStatementVariables(codeStatements, true);

            for (int stmt = 0, port = 0; stmt < codeStatements.Count; stmt++)
            {
                if (CodeBlockUtils.DoesStatementRequireOutputPort(svs, stmt))
                {
                    if (port == portIndex)
                    {
                        statement = codeStatements[stmt];
                        break;
                    }

                    port = port + 1;
                }
            }

            if (statement == null)
            {
                return(null);
            }

            var binExprNode = statement.AstNode as BinaryExpressionNode;

            if (binExprNode == null || (binExprNode.LeftNode == null))
            {
                return(null);
            }

            var identNode   = binExprNode.LeftNode as IdentifierNode;
            var mappedIdent = NodeUtils.Clone(identNode);

            if (!forRawName)
            {
                MapIdentifiers(mappedIdent);
            }

            return(mappedIdent as IdentifierNode);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Apppend replication guide to the input parameter based on lacing
        /// strategy.
        /// </summary>
        /// <param name="inputs"></param>
        /// <returns></returns>
        private void AppendReplicationGuides(List <AssociativeNode> inputs)
        {
            if (inputs == null || !inputs.Any())
            {
                return;
            }

            switch (ArgumentLacing)
            {
            case LacingStrategy.Longest:

                for (int i = 0; i < inputs.Count(); ++i)
                {
                    if (inputs[i] is ArrayNameNode)
                    {
                        var astNode = NodeUtils.Clone(inputs[i]) as ArrayNameNode;
                        astNode.ReplicationGuides = new List <AssociativeNode>();

                        var guideNode = new ReplicationGuideNode
                        {
                            RepGuide  = AstFactory.BuildIdentifier("1"),
                            IsLongest = true
                        };

                        astNode.ReplicationGuides.Add(guideNode);
                        inputs[i] = astNode;
                    }
                }
                break;

            case LacingStrategy.CrossProduct:

                int guide = 1;
                for (int i = 0; i < inputs.Count(); ++i)
                {
                    if (inputs[i] is ArrayNameNode)
                    {
                        var astNode = NodeUtils.Clone(inputs[i]) as ArrayNameNode;
                        astNode.ReplicationGuides = new List <AssociativeNode>();

                        var guideNode = new ReplicationGuideNode
                        {
                            RepGuide = AstFactory.BuildIdentifier(guide.ToString())
                        };

                        astNode.ReplicationGuides.Add(guideNode);
                        inputs[i] = astNode;
                        guide++;
                    }
                }
                break;
            }
        }
Exemplo n.º 11
0
        public ElseIfBlock(ElseIfBlock rhs) : base(rhs)
        {
            Expr = NodeUtils.Clone(rhs.Expr);
            ElseIfBodyPosition = NodeUtils.Clone(rhs.ElseIfBodyPosition);

            Body = new List <ImperativeNode>();
            foreach (ImperativeNode iNode in rhs.Body)
            {
                ImperativeNode newNode = NodeUtils.Clone(iNode);
                Body.Add(newNode);
            }
        }
Exemplo n.º 12
0
        public ForLoopNode(ForLoopNode rhs) : base(rhs)
        {
            Body = new List <ImperativeNode>();
            foreach (ImperativeNode iNode in rhs.Body)
            {
                ImperativeNode newNode = NodeUtils.Clone(iNode);
                Body.Add(newNode);
            }
            LoopVariable = NodeUtils.Clone(rhs.LoopVariable);
            Expression   = NodeUtils.Clone(rhs.Expression);

            KwForLine = rhs.KwForLine;
            KwForCol  = rhs.KwForCol;
            KwInLine  = rhs.KwInLine;
            KwInCol   = rhs.KwInCol;
        }
Exemplo n.º 13
0
        public ArrayNode(ArrayNode rhs)
            : base(rhs)
        {
            Expr = null;
            Type = null;
            if (null != rhs)
            {
                if (null != rhs.Expr)
                {
                    Expr = NodeUtils.Clone(rhs.Expr);
                }

                if (null != rhs.Type)
                {
                    Type = NodeUtils.Clone(rhs.Type);
                }
            }
        }
Exemplo n.º 14
0
        private IdentifierNode GetAstIdentifierForOutputIndexInternal(int portIndex, bool forRawName)
        {
            var ass       = outnodes[portIndex] as AssociativeNode;
            var identNode = ass as IdentifierNode;

            if (identNode == null)
            {
                return(null);
            }

            var mappedIdent = NodeUtils.Clone(identNode);

            if (!forRawName)
            {
                var identMapper = new IdentifierInPlaceMapper(libraryServices.LibraryManagementCore, ShouldBeRenamed, LocalizeIdentifier);
                mappedIdent.Accept(identMapper);
            }

            return(mappedIdent as IdentifierNode);
        }
Exemplo n.º 15
0
        public IfStmtNode(IfStmtNode rhs) : base(rhs)
        {
            //
            IfExprNode = NodeUtils.Clone(rhs.IfExprNode);


            //
            IfBody = new List <ImperativeNode>();
            foreach (ImperativeNode stmt in rhs.IfBody)
            {
                ImperativeNode body = NodeUtils.Clone(stmt);
                IfBody.Add(body);
            }

            //
            IfBodyPosition = NodeUtils.Clone(rhs.IfBodyPosition);

            //
            ElseIfList = new List <ElseIfBlock>();
            foreach (ElseIfBlock elseBlock in rhs.ElseIfList)
            {
                ImperativeNode elseNode = NodeUtils.Clone(elseBlock);
                ElseIfList.Add(elseNode as ElseIfBlock);
            }

            //
            ElseBody = new List <ImperativeNode>();
            foreach (ImperativeNode stmt in rhs.ElseBody)
            {
                ImperativeNode tmpNode = NodeUtils.Clone(stmt);
                ElseBody.Add(tmpNode);
            }

            //
            ElseBodyPosition = NodeUtils.Clone(rhs.ElseBodyPosition);
        }
Exemplo n.º 16
0
 public UnaryExpressionNode(UnaryExpressionNode rhs) : base(rhs)
 {
     Operator   = rhs.Operator;
     Expression = NodeUtils.Clone(rhs.Expression);
 }
Exemplo n.º 17
0
 public BinaryExpressionNode(BinaryExpressionNode rhs) : base(rhs)
 {
     Optr      = rhs.Optr;
     LeftNode  = rhs.LeftNode == null ? null : NodeUtils.Clone(rhs.LeftNode);
     RightNode = rhs.RightNode == null ? null : NodeUtils.Clone(rhs.RightNode);
 }
Exemplo n.º 18
0
 public IdentifierListNode(IdentifierListNode rhs) : base(rhs)
 {
     Optr      = rhs.Optr;
     LeftNode  = NodeUtils.Clone(rhs.LeftNode);
     RightNode = NodeUtils.Clone(rhs.RightNode);
 }