当前位置: 首页>>代码示例>>C#>>正文


C# AssociativeAST.CodeBlockNode类代码示例

本文整理汇总了C#中ProtoCore.AST.AssociativeAST.CodeBlockNode的典型用法代码示例。如果您正苦于以下问题:C# CodeBlockNode类的具体用法?C# CodeBlockNode怎么用?C# CodeBlockNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CodeBlockNode类属于ProtoCore.AST.AssociativeAST命名空间,在下文中一共展示了CodeBlockNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InsertBinaryOperationMethod

        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.kPublic;
            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.kPublic,
                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.kPublic,
                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);
        }
开发者ID:nmeek,项目名称:Dynamo,代码行数:33,代码来源:CoreUtils.cs

示例2: InsertPredefinedAndBuiltinMethods

 public static void InsertPredefinedAndBuiltinMethods(Core core, CodeBlockNode root)
 {
     if (DSASM.InterpreterMode.Normal == core.Options.RunMode)
     {
         InsertPredefinedMethod(core, root);
         InsertBuiltInMethods(core, root);
     }
 }
开发者ID:sh4nnongoh,项目名称:Dynamo,代码行数:8,代码来源:CoreUtils.cs

示例3: InsertBuiltInMethods

 private static void InsertBuiltInMethods(Core core, CodeBlockNode root)
 {
     Lang.BuiltInMethods builtInMethods = new Lang.BuiltInMethods(core);
     foreach (Lang.BuiltInMethods.BuiltInMethod method in builtInMethods.Methods)
     {
         root.Body.Add(GenerateBuiltInMethodSignatureNode(method));
     }
 }
开发者ID:nmeek,项目名称:Dynamo,代码行数:8,代码来源:CoreUtils.cs

示例4: InsertUnaryOperationMethod

        // 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);
        }
开发者ID:sh4nnongoh,项目名称:Dynamo,代码行数:25,代码来源:CoreUtils.cs

示例5: InsertInlineConditionOperationMethod

	private static void InsertInlineConditionOperationMethod(Core core, ProtoCore.AST.Node root, PrimitiveType condition, PrimitiveType r)
    {
        ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
        funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic;
        funcDefNode.Name = ProtoCore.DSASM.Constants.kInlineCondition; 
        funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r };
        ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
        args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
        {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, "%condition"),
            ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)condition), UID = (int)condition }
        });
        args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
        {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, "%trueExp"),
            ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r }
        });
        args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
        {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, "%falseExp"),
            ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)r), UID = (int)r }
        });
        funcDefNode.Signature = args;

        ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
        ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn);
        ProtoCore.AST.AssociativeAST.IdentifierNode con = BuildAssocIdentifier(core, "%condition");
        ProtoCore.AST.AssociativeAST.IdentifierNode t = BuildAssocIdentifier(core, "%trueExp");
        ProtoCore.AST.AssociativeAST.IdentifierNode f = BuildAssocIdentifier(core, "%falseExp");

        body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.InlineConditionalNode() { ConditionExpression = con, TrueExpression = t, FalseExpression = f } });
        funcDefNode.FunctionBody = body;
        (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
    }
开发者ID:RobertiF,项目名称:Dynamo,代码行数:40,代码来源:CoreUtils.cs

示例6: ImportCodeBlock

        public override CodeBlockNode ImportCodeBlock(string typeName, string alias, CodeBlockNode refNode)
        {
            Type[] types = GetTypes(typeName);
            Type exttype = typeof(IExtensionApplication);
#if PARALLEL
            System.Threading.Tasks.Parallel.ForEach(types, type =>
            {
                //For now there is no support for generic type.
                if (!type.IsGenericType && type.IsPublic && !exttype.IsAssignableFrom(type) && !CLRModuleType.SupressesImport(type))
                {
                    CLRModuleType importedType = CLRModuleType.GetInstance(type, this, alias);
                }
            });
#else
            foreach (var type in types)
            {
                //For now there is no support for generic type.
                if (!type.IsGenericType && type.IsPublic && !exttype.IsAssignableFrom(type) && !CLRModuleType.SupressesImport(type))
                {
                    CLRModuleType importedType = CLRModuleType.GetInstance(type, this, alias);
                    Type[] nestedTypes = type.GetNestedTypes();
                    if (null != nestedTypes && nestedTypes.Length > 0)
                    {
                        foreach (var item in nestedTypes)
                        {
                            importedType = CLRModuleType.GetInstance(item, this, string.Empty);
                        }
                    }
                }
            }
#endif

            CodeBlockNode node = new CodeBlockNode();
            //Get all the types available on this module.
            //TODO: need to optimize for performance.
            List<CLRModuleType> moduleTypes = CLRModuleType.GetTypes((CLRModuleType mtype) => { return mtype.Module == this; });
            foreach (var item in moduleTypes)
            {
                node.Body.Add(item.ClassNode);
                mTypes[item.FullName] = item; //update Type dictionary.
            }

            //Also add all the available empty class nodes.
            List<CLRModuleType> emptyTypes = CLRModuleType.GetEmptyTypes();
            foreach (var item in emptyTypes)
            {
                item.EnsureDisposeMethod(this);
                node.Body.Add(item.ClassNode);
            }

            string ffidump = Environment.GetEnvironmentVariable("FFIDUMP");
            if (string.Compare(ffidump, "1") == 0)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (var item in node.Body)
                {
                    sb.Append(item.ToString());
                    sb.AppendLine();
                }
                using (System.IO.FileStream fs = new System.IO.FileStream(string.Format("{0}.ds", this.Name), System.IO.FileMode.Create))
                {
                    byte[] bytes = System.Text.Encoding.ASCII.GetBytes(sb.ToString());
                    fs.Write(bytes, 0, bytes.Length);
                }
            }

            return node;
        }
开发者ID:whztt07,项目名称:Dynamo,代码行数:68,代码来源:CLRDLLModule.cs

示例7: InsertUnaryOperationMethod

	// 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, ProtoCore.AST.Node root, UnaryOperator op, PrimitiveType r, PrimitiveType operand)
    {
        ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
        funcDefNode.access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic;
        funcDefNode.IsAssocOperator = true;
        funcDefNode.IsBuiltIn = true;
        funcDefNode.Name = Op.GetUnaryOpFunction(op);
        funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)r), UID = (int)r };
        ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
        args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
        {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.CompilerDefinitions.AccessModifier.kPublic,
            NameNode = BuildAssocIdentifier(core, "%param"),
            ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)operand), UID = (int)operand }
        });
        funcDefNode.Signature = args;

        ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
        ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn);
        ProtoCore.AST.AssociativeAST.IdentifierNode param = BuildAssocIdentifier(core, "%param");
        body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = new ProtoCore.AST.AssociativeAST.UnaryExpressionNode() { Expression = param, Operator = op } });
        funcDefNode.FunctionBody = body;
        (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
    }
开发者ID:rafatahmed,项目名称:Dynamo,代码行数:27,代码来源:CoreUtils.cs

示例8: CompileCodeBlockAST

        private static bool CompileCodeBlockAST(Core core, ParseParam parseParams)
        {
            var unboundIdentifiers = new Dictionary<int, List<VariableLine>>();

            ProtoCore.BuildStatus buildStatus = null;
            try
            {
                int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;
                

                bool parsingPreloadFlag = core.IsParsingPreloadedAssembly;
                bool parsingCbnFlag = core.IsParsingPreloadedAssembly;
                core.IsParsingPreloadedAssembly = false;
                core.IsParsingCodeBlockNode = true;

                core.ResetForPrecompilation();

                var astNodes = parseParams.ParsedNodes;

                // Lookup namespace resolution map in elementResolver to rewrite 
                // partial classnames with their fully qualified names in ASTs
                // before passing them for pre-compilation. If partial class is not found in map, 
                // update Resolution map in elementResolver with fully resolved name from compiler.
                var reWrittenNodes = ElementRewriter.RewriteElementNames(core.ClassTable,  
                    parseParams.ElementResolver, astNodes, core.BuildStatus.LogSymbolConflictWarning);

                // Clone a disposable copy of AST nodes for PreCompile() as Codegen mutates AST's
                // while performing SSA transforms and we want to keep the original AST's
                var codeblock = new CodeBlockNode();
                var nodes = reWrittenNodes.OfType<AssociativeNode>().Select(NodeUtils.Clone).ToList();
                codeblock.Body.AddRange(nodes);

                buildStatus = PreCompile(string.Empty, core, codeblock, out blockId);

                core.IsParsingCodeBlockNode = parsingCbnFlag;
                core.IsParsingPreloadedAssembly = parsingPreloadFlag;

                parseParams.AppendErrors(buildStatus.Errors);
                parseParams.AppendWarnings(buildStatus.Warnings);

                if (buildStatus.ErrorCount > 0)
                {
                    return false;
                }
                IEnumerable<BuildData.WarningEntry> warnings = buildStatus.Warnings;

                // Get the unboundIdentifiers from the warnings
                GetInputLines(parseParams.ParsedNodes, warnings, unboundIdentifiers);
                foreach (KeyValuePair<int, List<VariableLine>> kvp in unboundIdentifiers)
                {
                    foreach (VariableLine vl in kvp.Value)
                        parseParams.AppendUnboundIdentifier(vl.displayName, vl.variable);
                }

                return true;
            }
            catch (Exception)
            {
                buildStatus = null;
                return false;
            }
        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:62,代码来源:CompilerUtils.cs

示例9: Compile

 internal ImportNode Compile(ImportModuleHandler importer)
 {
     ImportNode impNode = null;
     ProtoCore.AST.AssociativeAST.CodeBlockNode code = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
     foreach (var item in mData)
     {
         SortedSet<Type> types = GetTypesForImport(item.Value.Data);
         foreach (var type in types)
         {
             if (CLRObjectMarshler.IsMarshaledAsNativeType(type))
                 continue;
             ImportNode node = importer.Import(type.Assembly.Location, type.FullName, "");
             if (impNode != null && node != null)
                 impNode.CodeNode.Body.AddRange(node.CodeNode.Body);
             else
                 impNode = node;
         }
         if (impNode == null)
             impNode = new ImportNode() { ModuleName="ExternalContext", CodeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode() };
         impNode.CodeNode.Body.Add(ContextDataMethodCallNode(item.Value));
     }
     return impNode;
 }
开发者ID:algobasket,项目名称:Dynamo,代码行数:23,代码来源:ContextDataManager.cs

示例10: Import

        public ProtoCore.AST.AssociativeAST.ImportNode Import(string moduleName, string typeName, string alias, int line = -1, int col = -1)
        {
            curLine = line;
            curCol = col;

            moduleName = moduleName.Replace("\"", String.Empty);
            ProtoCore.AST.AssociativeAST.ImportNode node = new ProtoCore.AST.AssociativeAST.ImportNode();
            node.ModuleName = moduleName;

            string modulePathFileName = FileUtils.GetDSFullPathName(moduleName, _coreObj.Options);

            // Tracking directory paths for all imported DS files during preload assembly stage so that they can be accessed by Graph compiler before execution - pratapa
            if (_coreObj.IsParsingPreloadedAssembly)
            {
                string dirName = Path.GetDirectoryName(modulePathFileName);
                if (!string.IsNullOrEmpty(dirName) && !_coreObj.Options.IncludeDirectories.Contains(dirName))
                    _coreObj.Options.IncludeDirectories.Add(dirName);
            }

            if (string.IsNullOrEmpty(typeName))
            {
                //Check if moduleName is a type name with namespace.
                Type type = Type.GetType(moduleName);
                if (type != null)
                {
                    typeName = type.FullName;
                    modulePathFileName = type.Assembly.Location;
                }
            }

            if (modulePathFileName == null || !File.Exists(modulePathFileName))
            {
                System.Diagnostics.Debug.Write(@"Cannot import file: '" + modulePathFileName);
                _coreObj.LogWarning(ProtoCore.BuildData.WarningID.FileNotFound, string.Format(Resources.kFileNotFound, modulePathFileName));
                return null;
            }

            node.ModulePathFileName = modulePathFileName;
            node.CodeNode = null;
            if (typeName.Length > 0)
                node.Identifiers.Add(typeName);

            ProtoCore.AST.AssociativeAST.ImportNode importedNode = null;
            if (TryGetImportNode(modulePathFileName, typeName, out importedNode))
            {
                node.HasBeenImported = true;
                return node;
            }

            ProtoCore.AST.AssociativeAST.CodeBlockNode codeNode = null;
            if (importedNode == null)
                codeNode = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
            else
                codeNode = importedNode.CodeNode;

            try
            {
                codeNode = ImportCodeBlock(modulePathFileName, typeName, alias, codeNode);
            }
            catch (System.Exception ex)
            {
                if (ex.InnerException != null)
                    _coreObj.BuildStatus.LogSemanticError(ex.InnerException.Message);
                _coreObj.BuildStatus.LogSemanticError(ex.Message);
            }

            //Cache the codeblock of root import node.
            CodeBlockNode rootImportCodeBlock = mRootImportNode.CodeNode;
            mRootImportNode.CodeNode = new CodeBlockNode(); //reset with the new one.

            //Remove all empty nodes and add to root import node.
            codeNode.Body.RemoveAll(AddToRootImportNodeIfEmpty);

            if (mRootImportNode.CodeNode.Body.Count == 0) //empty
                mRootImportNode.CodeNode = rootImportCodeBlock; //reset the old one.

            if (importedNode != null)
            {
                //module has import node, but type is not imported yet.
                //MergeCodeBlockNode(ref importedNode, codeBlockNode);

                //update existing import node and return null.
                importedNode.CodeNode = codeNode;
                return null; 
            }

            node.CodeNode = codeNode;
            mModuleTable.Add(modulePathFileName, node);
            return node;
        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:90,代码来源:ImportModuleHandler.cs

示例11: Parser

 public Parser(Scanner scanner, ProtoLanguage.CompileStateTracker cs, bool _builtinMethodsLoaded = false)
 {
     this.scanner = scanner;
     errors = new Errors();
     errors.compileState = cs;
     this.compileState = cs;
     builtinMethodsLoaded = _builtinMethodsLoaded;
     commentNode = new CodeBlockNode();
 }
开发者ID:samuto,项目名称:designscript,代码行数:9,代码来源:Parser.cs

示例12: TestBuildAST_01

        public void TestBuildAST_01()
        {
            //==============================================
            //
            // import("ProtoGeometry.dll");
            // p = Point.Bycoordinates(0.0, 2.0, 1.0);
            // xval = p.X;
            //
            //==============================================


            //==============================================
            // Build the import Nodes
            //==============================================
            ProtoScript.Runners.ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner();

            List<string> libs = new List<string>();
            libs.Add("ProtoGeometry.dll");
            liveRunner.ResetVMAndImportLibrary(libs);

            string type = "Point";
            long hostInstancePtr = 0;
            string functionName = "ByCoordinates";
            List<IntPtr> userDefinedArgs = null;
            List<string> primitiveArgs = new List<string>();
            primitiveArgs.Add("0");
            primitiveArgs.Add("2");
            primitiveArgs.Add("1");
            string formatString = "ddd";
            string symbolName = "";
            string code = ""; 

            AssociativeNode assign1 = ASTCompilerUtils.BuildAST(type, hostInstancePtr, functionName, userDefinedArgs, primitiveArgs, formatString, liveRunner.Core, 
                ref symbolName, ref code);

            liveRunner.UpdateGraph(assign1);

            primitiveArgs.Clear();
            primitiveArgs.Add("10");
            primitiveArgs.Add("0");
            primitiveArgs.Add("0");
            
            functionName = "Translate";
            AssociativeNode assign2 = ASTCompilerUtils.BuildAST(symbolName, hostInstancePtr, functionName, userDefinedArgs, primitiveArgs, formatString, liveRunner.Core,
                ref symbolName, ref code);

            liveRunner.UpdateGraph(assign2);

            //==============================================
            // Build a binary expression to retirieve the x property
            // xval = p.X;
            //==============================================
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();

            ProtoCore.AST.AssociativeAST.IdentifierListNode identListNode = new ProtoCore.AST.AssociativeAST.IdentifierListNode();
            identListNode.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode(symbolName);
            identListNode.Optr = ProtoCore.DSASM.Operator.dot;
            identListNode.RightNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("X");
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("xval"),
                identListNode,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(stmt2);
            //==============================================
            //
            // import("ProtoGeometry.dll");
            // p = Point.Bycoordinates(0.0, 20.0, 1.0);
            // q = p.Translate(10.0, 0.0, 0.0);
            // xval = p.X;
            //
            //==============================================

            // update graph
            CodeBlockNode cNode = new CodeBlockNode();
            cNode.Body = astList;
            liveRunner.UpdateGraph(cNode);

            ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("xval");
            Assert.IsTrue((double)mirror.GetData().Data == 10.0);
        }
开发者ID:heegwon,项目名称:Dynamo,代码行数:80,代码来源:ASTCompilerUtilsTests.cs

示例13: CodeBlockNode

 public CodeBlockNode(CodeBlockNode rhs) : base(rhs)
 {
     Body = new List<AssociativeNode>();
     foreach (AssociativeNode aNode in rhs.Body)
     {
         AssociativeNode newNode = NodeUtils.Clone(aNode);
         Body.Add(newNode);
     }
 }
开发者ID:qingemeng,项目名称:designscript,代码行数:9,代码来源:AssociativeAST.cs

示例14: InsertDotMemVarMethod

        private static void InsertDotMemVarMethod(Core core, ProtoCore.AST.Node root)
        {
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.access = ProtoCore.DSASM.AccessSpecifier.kPublic;
            funcDefNode.Name = ProtoCore.DSASM.Constants.kDotArgMethodName;
            funcDefNode.ReturnType = new ProtoCore.Type() { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar };
            ProtoCore.AST.AssociativeAST.ArgumentSignatureNode args = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kLHS),
            ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeVar), UID = (int)PrimitiveType.kTypeVar }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, ProtoCore.DSASM.Constants.kRHS),
            ArgumentType = new ProtoCore.Type { Name = core.TypeSystem.GetType((int)PrimitiveType.kTypeInt), UID = (int)PrimitiveType.kTypeInt }
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, "%rhsDimExprList"),
            ArgumentType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 1)
            });
            args.AddArgument(new ProtoCore.AST.AssociativeAST.VarDeclNode()
            {
            memregion = ProtoCore.DSASM.MemoryRegion.kMemStack,
            access = ProtoCore.DSASM.AccessSpecifier.kPublic,
            NameNode = BuildAssocIdentifier(core, "%rhsDim"),
            ArgumentType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 0)
            });
            funcDefNode.Signature = args;

            ProtoCore.AST.AssociativeAST.CodeBlockNode body = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
            ProtoCore.AST.AssociativeAST.IdentifierNode _return = BuildAssocIdentifier(core, ProtoCore.DSDefinitions.Keyword.Return, ProtoCore.PrimitiveType.kTypeReturn);

            ProtoCore.AST.AssociativeAST.DotFunctionBodyNode dotNode = new ProtoCore.AST.AssociativeAST.DotFunctionBodyNode(args.Arguments[0].NameNode, args.Arguments[1].NameNode, args.Arguments[2].NameNode, args.Arguments[3].NameNode);
            body.Body.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode() { LeftNode = _return, Optr = ProtoCore.DSASM.Operator.assign, RightNode = dotNode});
            funcDefNode.FunctionBody = body;
            (root as ProtoCore.AST.AssociativeAST.CodeBlockNode).Body.Add(funcDefNode);
        }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:45,代码来源:CoreUtils.cs

示例15: GraphILTest_FFIClassUsage_02_astInput

        public void GraphILTest_FFIClassUsage_02_astInput()
        {
            ProtoScript.Runners.ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner();

            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            //==============================================
            // Build the import Nodes
            //==============================================
            List<string> libs = new List<string>();
            libs.Add("ProtoGeometry.dll");
            List<LibraryMirror> libMirrors = liveRunner.ResetVMAndImportLibrary(libs);

            //==============================================
            // Build the constructor call nodes
            // Point.ByCoordinates(10,10,10)
            //==============================================
            ProtoCore.AST.AssociativeAST.FunctionCallNode constructorCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            constructorCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("ByCoordinates");
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> listArgs = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(10.0));
            listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(10.0));
            listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(10.0));
            constructorCall.FormalArguments = listArgs;

            string className = "Point";
            ProtoCore.AST.AssociativeAST.IdentifierNode inode = new ProtoCore.AST.AssociativeAST.IdentifierNode(className);

            ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCall = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(inode, constructorCall, liveRunner.Core);

            //==============================================
            // Build the binary expression 
            // p = Point.ByCoordinates(10,10,10)
            //==============================================
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("p"),
                dotCall,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(stmt1);
            //==============================================
            // Translate the point
            // newPoint = p.Translate(1,2,3);
            //==============================================
            ProtoCore.AST.AssociativeAST.FunctionCallNode functionCallTranslate = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            functionCallTranslate.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("Translate");
            listArgs = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(1.0));
            listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(2.0));
            listArgs.Add(new ProtoCore.AST.AssociativeAST.DoubleNode(3.0));
            functionCallTranslate.FormalArguments = listArgs;

            //ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCallTranslate = new ProtoCore.AST.AssociativeAST.FunctionDotCallNode("p", functionCallTranslate);
            className = "p";
            inode = new ProtoCore.AST.AssociativeAST.IdentifierNode(className);

            ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCallTranslate = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(inode, functionCallTranslate, liveRunner.Core);

            //==============================================
            // Build the binary expression 
            //==============================================
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("newPoint"),
                dotCallTranslate,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(stmt2);

            //==============================================
            // Build a binary expression to retirieve the x property
            // xval = newPoint.X
            //==============================================
            ProtoCore.AST.AssociativeAST.IdentifierListNode identListNode = new ProtoCore.AST.AssociativeAST.IdentifierListNode();
            identListNode.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("newPoint");
            identListNode.Optr = ProtoCore.DSASM.Operator.dot;
            identListNode.RightNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("X");
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt3 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("xval"),
                identListNode,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(stmt3);
            //==============================================
            // 
            // import ("ProtoGeometry.dll");
            // p = Point.Bycoordinates(10.0, 10.0, 10.0);
            // newPoint = p.Translate(1.0,2.0,3.0);
            // xval = newPoint.X;
            //
            //==============================================

            // update graph
            CodeBlockNode cNode = new CodeBlockNode();
            cNode.Body = astList;
            liveRunner.UpdateGraph(cNode);

            ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("xval");
            Assert.IsTrue((double)mirror.GetData().Data == 11.0);

        }
开发者ID:algobasket,项目名称:Dynamo,代码行数:96,代码来源:MicroFeatureTests.cs


注:本文中的ProtoCore.AST.AssociativeAST.CodeBlockNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。