コード例 #1
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);
                }
            }
        }