Esempio n. 1
0
        // The following methods are used to insert methods to the bottom of the AST and convert operator to these method calls
        // to support replication on operators
        private static void InsertUnaryOperationMethod(Core core, CodeBlockNode root, UnaryOperator op, PrimitiveType r, PrimitiveType operand)
        {
            FunctionDefinitionNode funcDefNode = new FunctionDefinitionNode();

            funcDefNode.Access          = CompilerDefinitions.AccessModifier.Public;
            funcDefNode.IsAssocOperator = true;
            funcDefNode.IsBuiltIn       = true;
            funcDefNode.Name            = Op.GetUnaryOpFunction(op);
            funcDefNode.ReturnType      = new Type()
            {
                Name = core.TypeSystem.GetType((int)r), UID = (int)r
            };
            ArgumentSignatureNode args = new ArgumentSignatureNode();

            args.AddArgument(new VarDeclNode()
            {
                Access       = CompilerDefinitions.AccessModifier.Public,
                NameNode     = AstFactory.BuildIdentifier("%param"),
                ArgumentType = new Type {
                    Name = core.TypeSystem.GetType((int)operand), UID = (int)operand
                }
            });
            funcDefNode.Signature = args;

            CodeBlockNode  body  = new CodeBlockNode();
            IdentifierNode param = AstFactory.BuildIdentifier("%param");

            body.Body.Add(AstFactory.BuildReturnStatement(new UnaryExpressionNode()
            {
                Expression = param, Operator = op
            }));
            funcDefNode.FunctionBody = body;
            root.Body.Add(funcDefNode);
        }
Esempio n. 2
0
        private ArgumentSignatureNode ParseArgumentSignature(MethodBase method)
        {
            ArgumentSignatureNode argumentSignature = new ArgumentSignatureNode();

            ParameterInfo[] parameters = method.GetParameters();
            foreach (var parameter in parameters)
            {
                var paramNode = ParseArgumentDeclaration(parameter.Name, parameter.ParameterType);
                if (parameter.IsDefined(typeof(Autodesk.DesignScript.Runtime.ArbitraryDimensionArrayImportAttribute), false))
                {
                    var argType = paramNode.ArgumentType;
                    argType.rank           = ProtoCore.DSASM.Constants.kArbitraryRank;
                    paramNode.ArgumentType = argType;
                }

                if (parameter.IsOptional)
                {
                    var lhs = paramNode.NameNode;

                    var defaultValue = parameter.DefaultValue;
                    if (defaultValue != null)
                    {
                        var rhs = AstFactory.BuildPrimitiveNodeFromObject(defaultValue);
                        paramNode.NameNode = AstFactory.BuildBinaryExpression(lhs, rhs, ProtoCore.DSASM.Operator.assign);
                    }
                }
                argumentSignature.AddArgument(paramNode);
            }

            argumentSignature.IsVarArg = parameters.Any() &&
                                         parameters.Last().GetCustomAttributes(typeof(ParamArrayAttribute), false).Any();

            return(argumentSignature);
        }
Esempio n. 3
0
        private static List <TypedParameter> BuildParameters(ArgumentSignatureNode signatureNode)
        {
            var typeParams = new List <TypedParameter>();

            foreach (var arg in signatureNode.Arguments)
            {
                var name = arg.Name;

                // If we canont get the argument name from the Name property
                // we need to check its ASTKind and get it differently based on that.
                // So far only BinaryExpression and Identifier has come up, more can be added if necessary.
                if (string.IsNullOrEmpty(name))
                {
                    switch (arg.NameNode.Kind)
                    {
                    case AstKind.BinaryExpression:
                        name = ((BinaryExpressionNode)arg.NameNode).LeftNode.Name;
                        break;

                    case AstKind.Identifier:
                        name = arg.NameNode.Name;
                        break;
                    }
                }

                typeParams.Add(new TypedParameter(name));
            }

            return(typeParams);
        }
Esempio n. 4
0
        void functiondecl(out Node node)
        {
            FunctionDefinitionNode funcDecl = new FunctionDefinitionNode();

            ProtoCore.Type rtype = new ProtoCore.Type(); rtype.Name = "var"; rtype.UID = 0;
            Expect(18);
            Expect(1);
            funcDecl.Name = t.val;
            if (la.kind == 36)
            {
                Get();
                ReturnType(out rtype);
            }
            funcDecl.ReturnType = rtype;
            Expect(8);
            if (la.kind == 1 || la.kind == 25)
            {
                ArgumentSignatureNode args = new ArgumentSignatureNode();
                Node argdecl;
                ArgDecl(out argdecl);
                args.AddArgument(argdecl as VarDeclNode);
                while (la.kind == 30)
                {
                    Get();
                    ArgDecl(out argdecl);
                    args.AddArgument(argdecl as VarDeclNode);
                }
                funcDecl.Signature = args;
            }
            Expect(9);
            isGlobalScope = false;
            Expect(32);
            funcDecl.FunctionBody = new CodeBlockNode();
            NodeList body = new NodeList();

            stmtlist(out body);
            Expect(33);
            funcDecl.localVars         = localVarCount;
            funcDecl.FunctionBody.Body = body;
            node = funcDecl;

            isGlobalScope = true;
            localVarCount = 0;
        }
Esempio n. 5
0
        private static void InsertBinaryOperationMethod(Core core, CodeBlockNode root, Operator op, PrimitiveType r, PrimitiveType op1, PrimitiveType op2, int retRank = 0, int op1rank = 0, int op2rank = 0)
        {
            FunctionDefinitionNode funcDefNode = new FunctionDefinitionNode();

            funcDefNode.Access          = CompilerDefinitions.AccessModifier.Public;
            funcDefNode.IsAssocOperator = true;
            funcDefNode.IsBuiltIn       = true;
            funcDefNode.Name            = Op.GetOpFunction(op);
            funcDefNode.ReturnType      = new Type()
            {
                Name = core.TypeSystem.GetType((int)r), UID = (int)r, rank = retRank
            };
            ArgumentSignatureNode args = new ArgumentSignatureNode();

            args.AddArgument(new VarDeclNode()
            {
                Access       = CompilerDefinitions.AccessModifier.Public,
                NameNode     = AstFactory.BuildIdentifier(DSASM.Constants.kLHS),
                ArgumentType = new Type {
                    Name = core.TypeSystem.GetType((int)op1), UID = (int)op1, rank = op1rank
                }
            });
            args.AddArgument(new VarDeclNode()
            {
                Access       = CompilerDefinitions.AccessModifier.Public,
                NameNode     = AstFactory.BuildIdentifier(DSASM.Constants.kRHS),
                ArgumentType = new Type {
                    Name = core.TypeSystem.GetType((int)op2), UID = (int)op2, rank = op2rank
                }
            });
            funcDefNode.Signature = args;

            CodeBlockNode body = new CodeBlockNode();

            var lhs        = AstFactory.BuildIdentifier(DSASM.Constants.kLHS);
            var rhs        = AstFactory.BuildIdentifier(DSASM.Constants.kRHS);
            var binaryExpr = AstFactory.BuildBinaryExpression(lhs, rhs, op);

            body.Body.Add(AstFactory.BuildReturnStatement(binaryExpr));

            funcDefNode.FunctionBody = body;
            root.Body.Add(funcDefNode);
        }
Esempio n. 6
0
        private List <ProtoCore.Type> GetArgumentTypes(AssociativeNode node)
        {
            ArgumentSignatureNode sigNode = null;

            if (node is FunctionDefinitionNode)
            {
                sigNode = (node as FunctionDefinitionNode).Signature;
            }
            else if (node is ConstructorDefinitionNode)
            {
                sigNode = (node as ConstructorDefinitionNode).Signature;
            }

            if (sigNode != null && sigNode.Arguments != null)
            {
                return(sigNode.Arguments.Select(arg => arg.ArgumentType).ToList());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
 public virtual void VisitArgumentSignatureNode(ArgumentSignatureNode node)
 {
     DefaultVisit(node);
 }
Esempio n. 8
0
 public virtual TAssociative VisitArgumentSignatureNode(ArgumentSignatureNode node)
 {
     return(VisitAssociativeNode(node));
 }
 public virtual bool VisitArgumentSignatureNode(ArgumentSignatureNode node)
 {
     return(DefaultVisit(node));
 }