Esempio n. 1
0
            /// <summary>
            /// Returns the static return type of a function given its class, name and arguments
            /// </summary>
            /// <param name="className"></param>
            /// <param name="methodName"></param>
            /// <param name="arguments"></param>
            /// <returns></returns>
            public static ProtoCore.Type?GetType(string className, string methodName, List <ProtoCore.Type> arguments)
            {
                if (!string.IsNullOrEmpty(className))
                {
                    ClassTable classTable = staticCore.ClassTable;
                    int        ci         = classTable.IndexOf(className);

                    if (ci != ProtoCore.DSASM.Constants.kInvalidIndex)
                    {
                        ClassNode classNode = classTable.ClassNodes[ci];

                        MethodMirror mm = FindMethod(methodName, arguments, classNode.vtable.procList);
                        if (mm != null)
                        {
                            return(mm.ReturnType);
                        }
                    }
                }
                else // Check for global functions
                {
                    Validity.Assert(staticCore.CodeBlockList.Count > 0);

                    List <ProcedureNode> procNodes = staticCore.CodeBlockList[0].procedureTable.procList;

                    MethodMirror mm = FindMethod(methodName, arguments, procNodes);
                    if (mm != null)
                    {
                        return(mm.ReturnType);
                    }
                }

                return(null);
            }
Esempio n. 2
0
        /// <summary>
        /// Given a partial class name, get assembly to which the class belongs
        /// </summary>
        /// <param name="classTable"> class table in Core </param>
        /// <param name="className"> class name </param>
        /// <returns> assembly to which the class belongs </returns>
        public static string GetAssemblyFromClassName(ClassTable classTable, string className)
        {
            //throw new NotImplementedException();
            var ci = classTable.IndexOf(className);

            if (ci == DSASM.Constants.kInvalidIndex)
            {
                return(string.Empty);
            }

            var classNode = classTable.ClassNodes[ci];

            return(classNode.ExternLib);
        }
Esempio 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);
        }
Esempio n. 4
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);
                }
            }
        }