Ejemplo n.º 1
0
 public LanguageBlockNode()
 {
     CodeBlock    = new ProtoCore.LanguageCodeBlock();
     OpenParenPos = new IDEHelpNode()
     {
         Type = IDEHelpNode.HelpNodeType.PunctuationNode
     };
     CloseParenPos = new IDEHelpNode()
     {
         Type = IDEHelpNode.HelpNodeType.PunctuationNode
     };
     OpenCurlyBracePos = new IDEHelpNode()
     {
         Type = IDEHelpNode.HelpNodeType.PunctuationNode
     };
     CloseCurlyBracePos = new IDEHelpNode()
     {
         Type = IDEHelpNode.HelpNodeType.PunctuationNode
     };
     IdentPos = new IDEHelpNode()
     {
         Type = IDEHelpNode.HelpNodeType.KeywordNode
     };
     ParaPosList    = new List <IDEHelpNode>();
     TextStringList = new List <StringNode>();
 }
        public override bool Compile(
            out int blockId,
            ProtoCore.DSASM.CodeBlock parentBlock,
            ProtoCore.LanguageCodeBlock langBlock,
            ProtoCore.CompileTime.Context callContext,
            ProtoCore.DebugServices.EventSink sink         = null,
            ProtoCore.AST.Node codeBlockNode               = null,
            ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            Validity.Assert(langBlock != null);
            bool buildSucceeded = true;

            blockId = 0;

            core.assocCodegen = new ProtoVHDL.CodeGen(core, callContext, parentBlock);

            System.IO.MemoryStream memstream       = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(langBlock.body));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
            ProtoCore.DesignScriptParser.Parser  p = new ProtoCore.DesignScriptParser.Parser(s, core, core.builtInsLoaded);
            p.Parse();
            core.builtInsLoaded = true;
            codeBlockNode       = p.root;

            List <ProtoCore.AST.Node> astNodes = ProtoCore.Utils.ParserUtils.GetAstNodes(codeBlockNode);

            core.AstNodeList = astNodes;

            core.assocCodegen.Emit(codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode);

            buildSucceeded = core.BuildStatus.BuildSucceeded;
            return(buildSucceeded);
        }
Ejemplo n.º 3
0
        public LanguageCodeBlock(LanguageCodeBlock rhs)
        {
            id          = rhs.id;
            language    = rhs.language;
            fingerprint = rhs.version;
            version     = rhs.version;

            // TODO Jun: copy construct the attributes
            Attributes = new List <AST.Node>();

            body = rhs.body;
        }
Ejemplo n.º 4
0
        public LanguageCodeBlock(LanguageCodeBlock rhs)
        {
            id = rhs.id;
            language = rhs.language;
            fingerprint = rhs.version;
            version = rhs.version;

            // TODO Jun: copy construct the attributes
            Attributes = new List<AST.Node>();

            body = rhs.body;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Equality check for properties of a language block
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(LanguageCodeBlock other)
        {
            // Attributes, fingerprint, body and version are not yet used/set for language blocks
            // They only have default values.
            bool eqAttributes = true;
            bool eqProperties = fingerprint == other.version && version == other.version;
            bool eqBody       = string.Equals(body, other.body);

            return
                (language == other.language &&
                 eqProperties &&
                 eqAttributes &&
                 eqBody);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Equality check for properties of a language block
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool Equals(LanguageCodeBlock other)
        {
            // Attributes, fingerprint, body and version are not yet used/set for language blocks 
            // They only have default values.
            bool eqAttributes = true; 
            bool eqProperties = fingerprint == other.version && version == other.version;
            bool eqBody = string.Equals(body, other.body);

            return 
                language == other.language 
                && eqProperties 
                && eqAttributes 
                && eqBody;
        }
Ejemplo n.º 7
0
        public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink = null, ProtoCore.AST.Node codeBlockNode = null, ProtoCore.AssociativeGraph.GraphNode graphNode = null)
        {
            Validity.Assert(langBlock != null);
            blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

            bool buildSucceeded  = false;
            bool isLangSignValid = core.Langverify.Verify(langBlock);

            if (isLangSignValid)
            {
                try
                {
                    ProtoCore.CodeGen oldCodegen = core.assocCodegen;

                    if (ProtoCore.DSASM.InterpreterMode.kNormal == core.ExecMode)
                    {
                        if ((core.IsParsingPreloadedAssembly || core.IsParsingCodeBlockNode) && parentBlock == null)
                        {
                            if (core.CodeBlockList.Count == 0)
                            {
                                core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock);
                            }
                            else
                            {
                                // We reuse the existing toplevel CodeBlockList's for the procedureTable's
                                // by calling this overloaded constructor - pratapa
                                core.assocCodegen = new ProtoAssociative.CodeGen(core);
                            }
                        }
                        else
                        {
                            core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock);
                        }
                    }

                    if (null != core.AssocNode)
                    {
                        ProtoCore.AST.AssociativeAST.CodeBlockNode cnode = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
                        cnode.Body.Add(core.AssocNode as ProtoCore.AST.AssociativeAST.AssociativeNode);

                        core.assocCodegen.context = callContext;

                        blockId = core.assocCodegen.Emit((cnode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode);
                    }
                    else
                    {
                        //if not null, Compile has been called from DfsTraverse. No parsing is needed.
                        if (codeBlockNode == null)
                        {
                            var p = ParserUtils.CreateParser(langBlock.body, core);
                            p.Parse();

                            // TODO Jun: Set this flag inside a persistent object
                            core.builtInsLoaded = true;

                            codeBlockNode = p.root;

                            //core.AstNodeList = p.GetParsedASTList(codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode);
                            List <ProtoCore.AST.Node> astNodes = ProtoCore.Utils.ParserUtils.GetAstNodes(codeBlockNode);
                            core.AstNodeList = astNodes;
                        }
                        else
                        {
                            if (!core.builtInsLoaded)
                            {
                                // Load the built-in methods manually
                                ProtoCore.Utils.CoreUtils.InsertPredefinedAndBuiltinMethods(core, codeBlockNode, false);
                                core.builtInsLoaded = true;
                            }
                        }

                        core.assocCodegen.context = callContext;

                        //Temporarily change the code block for code gen to the current block, in the case it is an imperative block
                        //CodeGen for ProtoImperative is modified to passing in the core object.
                        ProtoCore.DSASM.CodeBlock oldCodeBlock = core.assocCodegen.codeBlock;
                        if (core.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter)
                        {
                            int tempBlockId = core.GetCurrentBlockId();

                            ProtoCore.DSASM.CodeBlock tempCodeBlock = core.GetCodeBlock(core.CodeBlockList, tempBlockId);
                            while (null != tempCodeBlock && tempCodeBlock.blockType != ProtoCore.DSASM.CodeBlockType.kLanguage)
                            {
                                tempCodeBlock = tempCodeBlock.parent;
                            }
                            core.assocCodegen.codeBlock = tempCodeBlock;
                        }
                        core.assocCodegen.codeBlock.EventSink = sink;
                        if (core.BuildStatus.ErrorCount == 0) //if there is syntax error, no build needed
                        {
                            blockId = core.assocCodegen.Emit((codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode);
                        }
                        if (core.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter)
                        {
                            blockId = core.assocCodegen.codeBlock.codeBlockId;
                            //Restore the code block.
                            core.assocCodegen.codeBlock = oldCodeBlock;
                        }
                    }

                    // @keyu: we have to restore asscoCodegen here. It may be
                    // reused later on. Suppose for an inline expression
                    // "x = 1 == 2 ? 3 : 4", we dynamically create assocCodegen
                    // to compile true and false expression in this inline
                    // expression, and if we don't restore assocCodegen, the pc
                    // is totally messed up.
                    //
                    // But if directly replace with old assocCodegen, will it
                    // replace some other useful information? Need to revisit it.
                    //
                    // Also refer to defect IDE-2120.
                    if (oldCodegen != null && core.assocCodegen != oldCodegen)
                    {
                        core.assocCodegen = oldCodegen;
                    }
                }
                catch (ProtoCore.BuildHaltException)
                {
#if DEBUG
                    //core.BuildStatus.LogSemanticError(e.errorMsg);
#endif
                }

                buildSucceeded = core.BuildStatus.BuildSucceeded;
            }

            return(buildSucceeded);
        }
Ejemplo n.º 8
0
 public LanguageBlockNode()
 {
     codeblock = new ProtoCore.LanguageCodeBlock();
 }
Ejemplo n.º 9
0
 public LanguageBlockNode()
 {
     codeblock = new ProtoCore.LanguageCodeBlock();
 }
Ejemplo n.º 10
0
 public LanguageBlockNode()
 {
     CodeBlock = new ProtoCore.LanguageCodeBlock();
     OpenParenPos = new IDEHelpNode() { Type = IDEHelpNode.HelpNodeType.PunctuationNode };
     CloseParenPos = new IDEHelpNode() { Type = IDEHelpNode.HelpNodeType.PunctuationNode };
     OpenCurlyBracePos = new IDEHelpNode() { Type = IDEHelpNode.HelpNodeType.PunctuationNode };
     CloseCurlyBracePos = new IDEHelpNode() { Type = IDEHelpNode.HelpNodeType.PunctuationNode };
     IdentPos = new IDEHelpNode() { Type = IDEHelpNode.HelpNodeType.KeywordNode };
     ParaPosList = new List<IDEHelpNode>();
     TextStringList = new List<StringNode>();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Equality check for properties of a language block
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(LanguageCodeBlock other)
 {
     return Language == other.Language && String.Equals(Code, other.Code);
 }
Ejemplo n.º 12
0
 public LanguageCodeBlock(LanguageCodeBlock rhs)
 {
     Language = rhs.Language;
     Code = rhs.Code;
 }
Ejemplo n.º 13
0
 public LanguageBlockNode()
 {
     languageblock = new LanguageCodeBlock(); 
     openBracket = new IDEHelpNode(IDEHelpNode.NodeType.PunctuationNode);
     language = new IDEHelpNode(IDEHelpNode.NodeType.KeywordNode);
     closeBracket = new IDEHelpNode(IDEHelpNode.NodeType.PunctuationNode);
     property = new List<IDEHelpNode>();
     propertyValue = new List<StringNode>();
     openBrace = new IDEHelpNode(IDEHelpNode.NodeType.PunctuationNode);
     closeBrace = new IDEHelpNode(IDEHelpNode.NodeType.PunctuationNode);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Equality check for properties of a language block
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(LanguageCodeBlock other)
 {
     return(Language == other.Language && String.Equals(Code, other.Code));
 }
Ejemplo n.º 15
0
 public LanguageCodeBlock(LanguageCodeBlock rhs)
 {
     Language = rhs.Language;
     Code     = rhs.Code;
 }