示例#1
0
        /// <summary>
        /// Gets the size to be used for runtime tables of symbols, procedures and instruction streams.
        /// Note: since blocks are stored consecutively but may have gaps due to procedures being deleted,
        /// this is based on largest id rather than amount of blocks.
        /// </summary>
        internal int GetRuntimeTableSize()
        {
            // Due to the way this list is constructed, the largest id is the one of the last block.
            var lastBlock = CompleteCodeBlockList.LastOrDefault();

            // If there are no code blocks yet, then the required size for tables is 0.
            // This happens when the first code block is being created and its id is being generated.
            if (lastBlock == null)
            {
                return(0);
            }

            // If the last block has children, then its last child has the largest id.
            if (lastBlock.children.Count > 0)
            {
                lastBlock = lastBlock.children.Last();
            }
            return(lastBlock.codeBlockId + 1);
        }
示例#2
0
        /// <summary>
        /// Sets the function to an inactive state where it can no longer be used by the front-end and backend
        /// </summary>
        /// <param name="functionDef"></param>
        public void SetFunctionInactive(FunctionDefinitionNode functionDef)
        {
            // DS language only supports function definition on the global and first language block scope
            // TODO Jun: Determine if it is still required to combine function tables in the codeblocks and callsite

            // Update the functiond definition in the codeblocks
            int hash = CoreUtils.GetFunctionHash(functionDef);

            ProcedureNode procNode = null;

            foreach (CodeBlock block in CodeBlockList)
            {
                // Update the current function definition in the current block
                procNode = block.procedureTable.Procedures.FirstOrDefault(p => p.HashID == hash);
                int index = procNode == null ? Constants.kInvalidIndex: procNode.ID;
                if (Constants.kInvalidIndex == index)
                {
                    continue;
                }

                procNode.IsActive = false;

                // Remove staled graph nodes
                var graph = block.instrStream.dependencyGraph;
                graph.GraphList.RemoveAll(g => g.classIndex == ClassIndex &&
                                          g.procIndex == index);
                graph.RemoveNodesFromScope(Constants.kGlobalScope, index);

                // Make a copy of all symbols defined in this function
                var localSymbols = block.symbolTable.symbolList.Values
                                   .Where(n =>
                                          n.classScope == Constants.kGlobalScope &&
                                          n.functionIndex == index)
                                   .ToList();

                foreach (var symbol in localSymbols)
                {
                    block.symbolTable.UndefineSymbol(symbol);
                }

                break;
            }

            if (null != procNode)
            {
                // Remove codeblock defined in procNode from CodeBlockList and CompleteCodeBlockList
                foreach (int cbID in procNode.ChildCodeBlocks)
                {
                    CompleteCodeBlockList.RemoveAll(x => x.codeBlockId == cbID);

                    foreach (CodeBlock cb in CodeBlockList)
                    {
                        cb.children.RemoveAll(x => x.codeBlockId == cbID);
                    }
                }
            }


            // Update the function definition in global function tables
            foreach (KeyValuePair <int, Dictionary <string, FunctionGroup> > functionGroupList in DSExecutable.FunctionTable.GlobalFuncTable)
            {
                foreach (KeyValuePair <string, FunctionGroup> functionGroup in functionGroupList.Value)
                {
                    functionGroup.Value.FunctionEndPoints.RemoveAll(func => func.procedureNode.HashID == hash);
                }
            }
        }