Example #1
0
 /// <summary>
 /// 添加一个函数到符号表
 /// </summary>
 /// <param name="fc">待添加函数单元</param>
 /// <returns>操作成功与否</returns>
 public bool addFunction(FunctionCell fc)
 {
     if (fc == null || this.isExistFunction(fc.callname))
     {
         return(false);
     }
     this.callfunContainer.Add(fc);
     return(true);
 }
Example #2
0
        /// <summary>
        /// 初始化代码管理器,获得一棵带有root和main函数块的树
        /// </summary>
        public void initCodeTree()
        {
            // 建立一个根节点
            this.parseTree = new KagaNode("TreeRoot", NodeType.PILE__BLOCK__ROOT, 0, 0, null);
            // 为根节点追加一个main函数节点
            KagaNode     mainFunNode = new KagaNode("main", NodeType.PILE__BLOCK__FUNCTION, 1, 0, this.parseTree);
            FunctionCell mainFunCell = new FunctionCell("main", null, VarType.VOID);

            mainFunNode.funBinding = mainFunCell;
            this.parseTree.children.Add(mainFunNode);
            // 为main函数节点追加代码块光标节点、代码块右边界
            mainFunNode.children.Add(new KagaNode("main___PADDING_CURSOR", NodeType.PILE__PADDING_CURSOR, 2, 0, mainFunNode));
            mainFunNode.children.Add(new KagaNode("main___BRIGHT_BRUCKET", NodeType.PILE__BRIGHT_BRUCKET, 2, 1, mainFunNode));
            // 追加main函数到符号管理器
            symbolMana.addFunction(mainFunCell);
        }
Example #3
0
        /// <summary>
        /// 修改一个函数的签名
        /// </summary>
        /// <param name="fname">查找函数的名称</param>
        /// <param name="nfc">待复制的新函数签名的函数单元</param>
        /// <returns>操作成功与否</returns>
        public bool editFunction(string fname, FunctionCell nfc)
        {
            // 更新
            FunctionCell ofc = this.getFunction(fname);

            if (ofc == null)
            {
                return(false);
            }
            // 复制一个备份等待需要的回滚
            FunctionCell backupOfc = new FunctionCell("_BACKUP_NODE");

            backupOfc.editSign(ofc);
            ofc.editSign(nfc);
            // 检查是否有重复
            bool rollbackFlag = false;

            for (int i = 0; i < this.callfunContainer.Count; i++)
            {
                for (int j = i + 1; j < this.callfunContainer.Count; j++)
                {
                    if (this.callfunContainer[i].callname == this.callfunContainer[j].callname)
                    {
                        rollbackFlag = true;
                        // 弹出两层循环
                        i = j = this.callfunContainer.Count + 1;
                    }
                }
            }
            // 如果重名就要回滚操作
            if (rollbackFlag == true)
            {
                ofc.editSign(backupOfc);
                return(false);
            }
            return(true);
        }