Exemplo n.º 1
0
        public override int VisitIDENTIFIER(CIdentifier node)
        {
            int context = m_parentContexts.Peek();
            CEmmitableCodeContainer rep = m_parents.Peek();

            if (m_functionNames.Count != 0)
            {
                string parent_Name = m_functionNames.Peek();

                if (FileBuilder.DeclareLocalFunvtionVariable(parent_Name, node.M_Name))
                {
                    if (m_scopeCompounds.Count != 0)
                    {
                        CCompoundStatement repFunction = m_scopeCompounds.Peek() as CCompoundStatement;
                        repFunction.AddCode("float " + node.M_Name + ";\n", CCompoundStatement.CC_COMPOUNDSTATEMENT_DECLARATIONS);
                    }
                }
                rep.AddCode(node.M_Name, context);
            }
            else
            {
                if (m_functionCalls.Count != 0)
                {
                    rep.AddCode(node.M_Name, context);
                }
                else
                {
                    FileBuilder.DeclareGlobalVariable(node.M_Name);
                    rep.AddCode(node.M_Name, context);
                }
            }

            return(0);
        }
Exemplo n.º 2
0
        public override int VisitCompoundStatement(CCompoundstatement node)
        {
            CEmmitableCodeContainer parent = m_parents.Peek() as CEmmitableCodeContainer;
            CCompoundStatement      rep    = new CCompoundStatement(CodeBlockType.CB_COMPOUNDSTATEMENT, 2, parent);

            parent.AddCode(rep, m_parentContexts.Peek());

            m_parents.Push(rep);
            m_parentContexts.Push(CCompoundStatement.CC_COMPOUNDSTATEMENT_BODY);
            if (m_scopeCompounds.Count() < 1)
            {
                m_scopeCompounds.Push(rep);
            }

            foreach (ASTVisitableElement child in node.GetChildrenContext(CCompoundstatement.CT_BODY))
            {
                Visit(child);
            }
            if (m_scopeCompounds.Count() >= 1)
            {
                m_scopeCompounds.Pop();
            }

            m_parents.Pop();
            m_parentContexts.Pop();

            return(0);
        }