Ejemplo n.º 1
0
        public override AssociativeNode VisitTypedIdentifierNode(TypedIdentifierNode node)
        {
            if (node == null)
            {
                return(null);
            }

            // If type is primitive type
            if (node.datatype.UID != (int)PrimitiveType.InvalidType &&
                node.datatype.UID < (int)PrimitiveType.MaxPrimitive)
            {
                return(node);
            }

            // build an idlistnode from the full type name
            var identListNode = CoreUtils.CreateNodeFromString(node.TypeAlias);

            if (identListNode == null)
            {
                return(node);
            }

            // visit the idlist
            var shortNameNode = identListNode.Accept(this);

            if (shortNameNode == null)
            {
                return(node);
            }


            var resultingNode = new TypedIdentifierNode
            {
                Name     = node.Name,
                Value    = node.Name,
                datatype = node.datatype
            };


            //return a typedIdNode built from the shortNameId returned above.
            resultingNode.TypeAlias = shortNameNode.ToString();

            //modify the AST node that was passed to the visitor.
            node.Name      = resultingNode.Name;
            node.Value     = resultingNode.Value;
            node.datatype  = resultingNode.datatype;
            node.TypeAlias = resultingNode.TypeAlias;

            return(node);
        }
 public virtual Value evaluate(Context cx, TypedIdentifierNode node)
 {
     output("<TypedIdentifierNode position=\"" + node.pos() + "\">");
     indent_Renamed_Field++;
     if (node.identifier != null)
     {
         node.identifier.evaluate(cx, this);
     }
     if (node.type != null)
     {
         node.type.evaluate(cx, this);
     }
     indent_Renamed_Field--;
     output("</TypedIdentifierNode>");
     return(null);
 }
Ejemplo n.º 3
0
        public override AssociativeNode VisitTypedIdentifierNode(TypedIdentifierNode node)
        {
            // If type is primitive type
            if (node.datatype.UID != (int)PrimitiveType.InvalidType &&
                node.datatype.UID < (int)PrimitiveType.MaxPrimitive)
            {
                return(node);
            }

            var identListNode = CoreUtils.CreateNodeFromString(node.TypeAlias);

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

            // Rewrite node with resolved name
            if (identListNode is IdentifierNode)
            {
                identListNode = RewriteIdentifierListNode(identListNode);
            }
            else
            {
                identListNode = identListNode.Accept(this);
            }

            var identListString = identListNode.ToString();
            var type            = new Type
            {
                Name = identListString,
                UID  = classTable.IndexOf(identListString),
                rank = node.datatype.rank
            };

            var typedNode = new TypedIdentifierNode
            {
                Name      = node.Name,
                Value     = node.Name,
                datatype  = type,
                TypeAlias = node.TypeAlias
            };

            NodeUtils.CopyNodeLocation(typedNode, node);
            return(typedNode);
        }
Ejemplo n.º 4
0
        public void VisitTypedIdentifierNodeTest()
        {
            //Arrange
            var engine = CurrentDynamoModel.EngineController;
            ShortestQualifiedNameReplacer replacer = new ShortestQualifiedNameReplacer(engine.LibraryServices.LibraryManagementCore.ClassTable, null);
            TypedIdentifierNode           node     = null;
            IdentifierListNode            node2    = null;

            //Act
            //We need to pass null to both functions in order to reach a specific piece of code wihout coverage
            var response  = replacer.VisitTypedIdentifierNode(node);
            var response2 = replacer.VisitIdentifierListNode(node2);

            //Assert
            //Checking that both functions returned null
            Assert.IsNull(response);
            Assert.IsNull(response2);
        }
Ejemplo n.º 5
0
        public override AssociativeNode VisitTypedIdentifierNode(TypedIdentifierNode node)
        {
            // If type is primitive type
            if (node.datatype.UID != (int)PrimitiveType.InvalidType &&
                node.datatype.UID < (int)PrimitiveType.MaxPrimitive)
                return node;

            var identListNode = CoreUtils.CreateNodeFromString(node.TypeAlias);

            // Rewrite node with resolved name
            if (identListNode is IdentifierNode)
            {
                identListNode = RewriteIdentifierListNode(identListNode);
            }
            else
                identListNode = identListNode.Accept(this);

            var identListString = identListNode.ToString();
            var type = new Type
            {
                Name = identListString,
                UID = classTable.IndexOf(identListString),
                rank = node.datatype.rank
            };

            var typedNode = new TypedIdentifierNode
            {
                Name = node.Name,
                Value = node.Name,
                datatype = type,
                TypeAlias = node.TypeAlias
            };

            NodeUtils.CopyNodeLocation(typedNode, node);
            return typedNode;
        }
Ejemplo n.º 6
0
        private FunctionDefinitionNode EmitSetterFunction(ProtoCore.DSASM.SymbolNode prop, ProtoCore.Type argType)
        {
            var argument = new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
                Access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
                NameNode =AstFactory.BuildIdentifier(Constants.kTempArg),
                ArgumentType = argType
            };
            var argumentSingature = new ArgumentSignatureNode();
            argumentSingature.AddArgument(argument);

            FunctionDefinitionNode setter = new FunctionDefinitionNode
            {
                Name = ProtoCore.DSASM.Constants.kSetterPrefix + prop.name,
                Signature = argumentSingature,
                Pattern = null,
                ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0),
                FunctionBody = new CodeBlockNode(),
                IsExternLib = false,
                IsDNI = false,
                ExternLibName = null,
                Access = prop.access,
                IsStatic = prop.isStatic,
                IsAutoGenerated = true
            };

            // property = %tmpArg
            var propIdent = new TypedIdentifierNode();
            propIdent.Name = propIdent.Value = prop.name;
            propIdent.datatype = prop.datatype;

            var tmpArg =AstFactory.BuildIdentifier(Constants.kTempArg);
            var assignment = AstFactory.BuildBinaryExpression(propIdent, tmpArg, Operator.assign);
            setter.FunctionBody.Body.Add(assignment);

            // return = null;
            var returnNull = AstFactory.BuildReturnStatement(new NullNode()); 
            setter.FunctionBody.Body.Add(returnNull);

            return setter;
        }
Ejemplo n.º 7
0
 public virtual void VisitTypedIdentifierNode(TypedIdentifierNode node)
 {
     DefaultVisit(node);
 }
Ejemplo n.º 8
0
 public virtual TAssociative VisitTypedIdentifierNode(TypedIdentifierNode node)
 {
     return(VisitAssociativeNode(node));
 }
Ejemplo n.º 9
0
 public override AssociativeNode VisitTypedIdentifierNode(TypedIdentifierNode node)
 {
     return(VisitIdentifierNode(node));
 }
 public virtual bool VisitTypedIdentifierNode(TypedIdentifierNode node)
 {
     return(DefaultVisit(node));
 }
Ejemplo n.º 11
0
        private void DfsTraverse(ref AssociativeNode astNode, ICollection <AssociativeNode> classIdentifiers,
                                 Queue <string> resolvedNames)
        {
            if (astNode is BinaryExpressionNode)
            {
                var             bnode     = astNode as BinaryExpressionNode;
                AssociativeNode leftNode  = bnode.LeftNode;
                AssociativeNode rightNode = bnode.RightNode;
                DfsTraverse(ref leftNode, classIdentifiers, resolvedNames);
                DfsTraverse(ref rightNode, classIdentifiers, resolvedNames);

                bnode.LeftNode  = leftNode;
                bnode.RightNode = rightNode;
            }
            else if (astNode is FunctionCallNode)
            {
                var fCall = astNode as FunctionCallNode;
                for (int n = 0; n < fCall.FormalArguments.Count; ++n)
                {
                    AssociativeNode argNode = fCall.FormalArguments[n];
                    DfsTraverse(ref argNode, classIdentifiers, resolvedNames);
                    fCall.FormalArguments[n] = argNode;
                }
            }
            else if (astNode is ExprListNode)
            {
                var exprList = astNode as ExprListNode;
                for (int n = 0; n < exprList.list.Count; ++n)
                {
                    AssociativeNode exprNode = exprList.list[n];
                    DfsTraverse(ref exprNode, classIdentifiers, resolvedNames);
                    exprList.list[n] = exprNode;
                }
            }
            else if (astNode is InlineConditionalNode)
            {
                var             inlineNode = astNode as InlineConditionalNode;
                AssociativeNode condition  = inlineNode.ConditionExpression;
                AssociativeNode trueBody   = inlineNode.TrueExpression;
                AssociativeNode falseBody  = inlineNode.FalseExpression;

                DfsTraverse(ref condition, classIdentifiers, resolvedNames);
                DfsTraverse(ref trueBody, classIdentifiers, resolvedNames);
                DfsTraverse(ref falseBody, classIdentifiers, resolvedNames);

                inlineNode.ConditionExpression = condition;
                inlineNode.FalseExpression     = falseBody;
                inlineNode.TrueExpression      = trueBody;
            }
            else if (astNode is TypedIdentifierNode)
            {
                var typedNode = astNode as TypedIdentifierNode;

                // If type is primitive type
                if (typedNode.datatype.UID != (int)PrimitiveType.kInvalidType &&
                    typedNode.datatype.UID < (int)PrimitiveType.kMaxPrimitives)
                {
                    return;
                }

                var identListNode = CoreUtils.CreateNodeFromString(typedNode.TypeAlias);

                // Rewrite node with resolved name
                if (resolvedNames.Any())
                {
                    if (identListNode is IdentifierNode)
                    {
                        identListNode = RewriteIdentifierListNode(identListNode, resolvedNames);
                    }
                    else
                    {
                        DfsTraverse(ref identListNode, classIdentifiers, resolvedNames);
                    }

                    var    identListString = identListNode.ToString();
                    int    indx            = identListString.LastIndexOf('.');
                    string name            = indx >= 0 ? identListString.Remove(indx) : identListString;

                    var type = new Type
                    {
                        Name = name,
                        UID  = classTable.IndexOf(name),
                        rank = typedNode.datatype.rank
                    };

                    typedNode = new TypedIdentifierNode
                    {
                        Name     = astNode.Name,
                        Value    = astNode.Name,
                        datatype = type
                    };

                    NodeUtils.CopyNodeLocation(typedNode, astNode);
                    astNode = typedNode;
                }
                else if (identListNode is IdentifierNode)
                {
                    classIdentifiers.Add(identListNode);
                }
                else
                {
                    DfsTraverse(ref identListNode, classIdentifiers, resolvedNames);
                }
            }
            else if (astNode is IdentifierListNode)
            {
                var identListNode = astNode as IdentifierListNode;
                var rightNode     = identListNode.RightNode;

                if (rightNode is FunctionCallNode)
                {
                    DfsTraverse(ref rightNode, classIdentifiers, resolvedNames);
                }
                if (resolvedNames.Any())
                {
                    astNode = RewriteIdentifierListNode(identListNode, resolvedNames);
                }
                else
                {
                    classIdentifiers.Add(identListNode);
                }
            }
        }
		public virtual Value evaluate(Context cx, TypedIdentifierNode node)
		{
			output("<TypedIdentifierNode position=\"" + node.pos() + "\">");
			indent_Renamed_Field++;
			if (node.identifier != null)
			{
				node.identifier.evaluate(cx, this);
			}
			if (node.type != null)
			{
				node.type.evaluate(cx, this);
			}
			indent_Renamed_Field--;
			output("</TypedIdentifierNode>");
			return null;
		}