public override void AddNewLine(CodeContextType context)
        {
            CodeContainer container = new CodeContainer(CodeBlockType.CB_NA, this);

            container.AddNewLine();
            m_repository[GetContextIndex(context)].Add(container);
        }
        public override void AddNewLine(int context)
        {
            CodeContainer container = new CodeContainer(CodeBlockType.CB_NA, this);

            container.AddNewLine();
            m_repository[context].Add(container);
        }
        public override void AddCode(string code, CodeContextType context)
        {
            CodeContainer container = new CodeContainer(CodeBlockType.CB_NA, this);

            container.AddCode(code, CodeContextType.CC_NA);
            m_repository[GetContextIndex(context)].Add(container);
        }
        public override void AddCode(string code, int context)
        {
            CodeContainer container = new CodeContainer(CodeBlockType.CB_NA, this);

            container.AddCode(code, -1);
            m_repository[context].Add(container);
        }
示例#5
0
        public override int VisitFunction(CFunction node)
        {
            //1. Create Output File
            CFile                parent     = m_parents.Peek() as CFile;
            CodeContainer        repDeclare = new CodeContainer(CodeBlockType.CB_FILE, parent);
            CCFunctionDefinition rep        = new CCFunctionDefinition(CodeBlockType.CB_FUNCTIONDEFINITION, 2, parent);

            //2. Add Function Definition to the File in the appropriate context
            parent.AddCode(repDeclare, CFile.CB_GLOBALS);
            parent.AddCode(rep, CFile.CB_FUNDEFS);

            m_parents.Push(rep);
            m_parentContexts.Push(CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS);

            //3. Assemble the function header
            CIdentifier id = node.GetChild(CFunction.CT_FNAME, 0) as CIdentifier;

            m_translatedFile.DeclareFunction(id.M_Name);

            rep.AddCode("float " + id.M_Name + "(", CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS);
            repDeclare.AddCode("float " + id.M_Name + "(", CFile.CB_GLOBALS);

            string last = node.GetChildrenContext(CFunction.CT_FARGS).Last().M_GraphVizName;

            foreach (ASTElement s in node.GetChildrenContext(CFunction.CT_FARGS))
            {
                repDeclare.AddCode("float " + s.M_Name, CFile.CB_GLOBALS);
                rep.AddCode("float " + s.M_Name, CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS);

                if (!s.M_GraphVizName.Equals(last))
                {
                    repDeclare.AddCode(", ", CFile.CB_GLOBALS);
                    rep.AddCode(", ", CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS);
                }
                parent.DeclareLocalFunvtionVariable(id.M_Name, s.M_Name);
            }
            repDeclare.AddCode(");\n", CFile.CB_GLOBALS);
            rep.AddCode(")", CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS);

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

            m_parents.Push(rep);
            m_parentContexts.Push(CCFunctionDefinition.CB_FUNCTIONDEFINITION_BODY);
            m_functionNames.Push(id.M_Name);

            foreach (ASTVisitableElement child in node.GetChildrenContext(CFunction.CT_BODY))
            {
                Visit(child);
            }

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

            return(0);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_NA, null);

            rep.AddCode(AssemblyContext(CFile.CB_PREPROCESSOR));
            rep.AddCode(AssemblyContext(CFile.CB_GLOBALS));
            rep.AddCode(AssemblyContext(CFile.CB_FUNDEFS));
            return(rep);
        }
示例#7
0
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_NA, null);

            rep.AddCode(AssemblyContext(CodeContextType.CC_FILE_PREPROCESSOR));
            rep.AddCode(AssemblyContext(CodeContextType.CC_FILE_GLOBALVARS));
            rep.AddCode(AssemblyContext(CodeContextType.CC_FILE_FUNDEF));
            return(rep);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, M_Parent);

            rep.AddCode("printf(\"res=%f\\n\",");
            rep.AddCode(AssemblyContext(CResultStatement.CC_EXPRESSIONSTATEMENT_BODY));
            rep.AddCode(");");
            rep.AddNewLine();
            return(rep);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_WHILESTATEMENT, M_Parent);

            rep.AddCode("while ( ");
            rep.AddCode(AssemblyContext(CWhileStatement.CC_WHILESTATEMENT_CONDITION));
            rep.AddCode(" )");
            rep.AddCode(AssemblyContext(CWhileStatement.CC_WHILESTATEMENT_BODY));
            return(rep);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_FORSTATEMENT, M_Parent);

            rep.AddCode("for ( ");
            rep.AddCode(AssemblyContext(CForStatement.CC_FORARGS_STATEMENT));
            rep.AddCode(" )");
            rep.AddCode(AssemblyContext(CForStatement.CC_FORSTATEMENT_BODY));
            return(rep);
        }
示例#11
0
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, M_Parent);

            rep.AddCode("return ");
            rep.AddCode(AssemblyContext(CodeContextType.CC_RETURNSTATEMENT_BODY));
            rep.AddCode(";");
            rep.AddNewLine();
            return(rep);
        }
        protected virtual CodeContainer AssemblyContext(int ct)
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, this);

            for (int i = 0; i < m_repository[ct].Count; i++)
            {
                rep.AddCode(m_repository[ct][i].AssemblyCodeContainer());
            }

            return(rep);
        }
示例#13
0
        // public DelegateCommand Command { get; private set; }

        public RecentProject(string path, CodeContainer info)
        {
            _path = path;
            _info = info;

            this.Info                   = new FileInfo(path);
            this.IsFavorite             = _info.IsFavorite;
            this.ClassificationCategory = DateClassificationCategory.Get(this);

            // this.Command = new DelegateCommand(this.DoOpenProject);
        }
示例#14
0
        public void DeclareFunction(string funname, string funheader)
        {
            CodeContainer rep;

            if (!m_FunctionsSymbolTable.Contains(funname))
            {
                rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, this);
                m_globalVarSymbolTable.Add(funname);
                rep.AddCode(funheader + ";\n", CodeContextType.CC_FILE_GLOBALVARS);
                AddCode(rep, CodeContextType.CC_FILE_GLOBALVARS);
            }
        }
        public void DeclareGlobalVariable(string varname)
        {
            CodeContainer rep;

            if (!m_globalVarSymbolTable.Contains(varname))
            {
                m_globalVarSymbolTable.Add(varname);
                rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, this);
                rep.AddCode("float " + varname + ";\n", CFile.CB_GLOBALS);
                AddCode(rep, CFile.CB_GLOBALS);
            }
        }
示例#16
0
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_NA, M_Parent);

            // 1. Emmit Header
            rep.AddCode(AssemblyContext(CodeContextType.CC_FUNCTIONDEFINITION_HEADER));

            // 4. Emmit Code Body
            rep.AddCode(AssemblyContext(CodeContextType.CC_FUNCTIONDEFINITION_BODY));
            rep.AddNewLine();

            return(rep);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep        = new CodeContainer(CodeBlockType.CB_NA, null);
            string        mainheader = "int main(int argc, char* argv[]){";

            rep.AddCode(mainheader);
            rep.EnterScope();
            rep.AddCode(AssemblyContext(CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS));
            rep.AddCode(AssemblyContext(CCFunctionDefinition.CB_FUNCTIONDEFINITION_BODY));
            rep.AddCode("return 0;");
            rep.LeaveScope();
            rep.AddCode("}");

            return(rep);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            // throw new NotImplementedException();

            CodeContainer rep = new CodeContainer(CodeBlockType.CB_NA, M_Parent);

            // 1. Emmit Header
            rep.AddCode(AssemblyContext(CCFunctionDefinition.CB_FUNCTIONDEFINITION_DECLARATIONS));

            // 4. Emmit Code Body
            rep.AddCode(AssemblyContext(CCFunctionDefinition.CB_FUNCTIONDEFINITION_BODY));
            rep.AddNewLine();

            return(rep);
        }
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_COMPOUNDSTATEMENT, M_Parent);

            rep.AddCode("{");
            rep.EnterScope();
            rep.AddCode("//  ***** Local declarations *****");
            rep.AddNewLine();
            rep.AddCode(AssemblyContext(CCompoundStatement.CC_COMPOUNDSTATEMENT_DECLARATIONS));
            rep.AddCode("//  ***** Code Body *****");
            rep.AddNewLine();
            rep.AddCode(AssemblyContext(CCompoundStatement.CC_COMPOUNDSTATEMENT_BODY));
            rep.LeaveScope();
            rep.AddCode("}");
            return(rep);
        }
示例#20
0
        public override CodeContainer AssemblyCodeContainer()
        {
            CodeContainer rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, M_Parent);

            rep.AddCode("if ( ");
            rep.AddCode(AssemblyContext(CodeContextType.CC_IFSTATEMENT_CONDITION));
            rep.AddCode(" )");
            rep.AddCode(AssemblyContext(CodeContextType.CC_IFSTATEMENT_IFBODY));
            if (GetContextChildren(CodeContextType.CC_IFSTATEMENT_ELSEBODY).Length != 0)
            {
                rep.AddCode("else");
                rep.AddCode(AssemblyContext(CodeContextType.CC_IFSTATEMENT_ELSEBODY));
            }

            return(rep);
        }
示例#21
0
        static int CodeContainerComparison(CodeContainer a, CodeContainer b)
        {
            if (a.IsFavorite == b.IsFavorite)
            {
                return(a.LastAccessed.CompareTo(b.LastAccessed));
            }

            if (a.IsFavorite)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }
示例#22
0
        //..............
        public override int VisitAssignment(CAssignment node)
        {
            CEmmitableCodeContainer parent = m_parents.Peek() as CEmmitableCodeContainer;
            int context = m_parentContexts.Peek();

            CodeContainer rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, parent);

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

            m_parents.Push(rep);
            m_parentContexts.Push(context);

            foreach (ASTVisitableElement child in
                     node.GetChildrenContext(CAssignment.CT_LEFT))
            {
                Visit(child);
            }
            m_parents.Pop();
            m_parentContexts.Pop();

            rep.AddCode("=", context);

            m_parents.Push(rep);
            m_parentContexts.Push(context);
            // Visit Statements Context and emmit code to main functions
            foreach (ASTVisitableElement child in
                     node.GetChildrenContext(CAssignment.CT_RIGHT))
            {
                Visit(child);
            }
            m_parents.Pop();
            m_parentContexts.Pop();

            //..........
            if (m_for.Count == 0)
            {
                rep.AddCode(";");
                rep.AddNewLine();
            }
            //..........

            // rep.AddCode(";");
            // rep.AddNewLine();

            return(0);
        }
示例#23
0
        public virtual void DeclareVariable(string varname, bool isread)
        {
            CodeContainer rep;

            if (!m_localSymbolTable.Contains(varname))
            {
                if (isread)
                {
                    m_file.DeclareGlobalVariable(varname);
                }
                else
                {
                    rep = new CodeContainer(CodeBlockType.CB_CODEREPOSITORY, this);
                    m_localSymbolTable.Add(varname);

                    rep.AddCode("float " + varname + ";\n", CodeContextType.CC_NA);
                    CEmmitableCodeContainer compoundst = GetChild(CodeContextType.CC_FUNCTIONDEFINITION_BODY);
                    compoundst.AddCode(rep, CodeContextType.CC_COMPOUNDSTATEMENT_DECLARATIONS);
                }
            }
        }
示例#24
0
        static void Main(string[] args)
        {
            StreamReader      AStream          = new StreamReader(args[0]);
            AntlrInputStream  antlrInputStream = new AntlrInputStream(AStream);
            MINICLexer        lexer            = new MINICLexer(antlrInputStream);
            CommonTokenStream tokens           = new CommonTokenStream(lexer);
            MINICParser       parser           = new MINICParser(tokens);
            IParseTree        tree             = parser.compileUnit();

            Console.WriteLine(tree.ToStringTree());

            STPrinterVisitor stPrinter = new STPrinterVisitor();

            stPrinter.Visit(tree);

            ASTGenerator astgen = new ASTGenerator();

            astgen.Visit(tree);

            ASTPrinterVisitor astPrinterVisitor = new ASTPrinterVisitor("test.ast.dot");

            astPrinterVisitor.Visit(astgen.M_Root);

            MINICTranslation cGenerator = new MINICTranslation();

            cGenerator.Visit(astgen.M_Root);
            CodeContainer file = cGenerator.FileBuilder.AssemblyCodeContainer();

            Console.WriteLine(file.ToString());

            StreamWriter m_streamWriter = new StreamWriter("CodeStructure.dot");

            cGenerator.FileBuilder.PrintStructure(m_streamWriter);

            MINICPrinter m_minicPrinter = new MINICPrinter("CodeStructure.c", file);

            m_minicPrinter.printer();
        }
示例#25
0
 public Task <CodeContainer> AcquireCodeContainerAsync(CodeContainer onlineCodeContainer, IProgress <ServiceProgressData> downloadProgress, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
示例#26
0
 public MINICPrinter(string dotFileName, CodeContainer rep)
 {
     m_ostream = new StreamWriter(dotFileName);
     m_dotName = dotFileName;
     m_rep     = rep;
 }