Example #1
0
        private static void CFGReducibility_DominatorTree_PrettyPrinter_Demonstration()
        {
            string fpath = @"..\..\..\CodeSamples\reducibilityBadSample.txt";

            astRoot = AST(fpath);
            if (astRoot == null)
            {
                return;
            }
            var tacodeVisitor = new TACodeVisitor();

            astRoot.Visit(tacodeVisitor);
            var prettyPrinter = new PrettyPrintVisitor();

            astRoot.Visit(prettyPrinter);
            var cfg     = new ControlFlowGraph(tacodeVisitor.Code);
            var domTree = new DominatorTree(cfg);

            Console.WriteLine("###### CFG Reducibility(#59 by APC TEAM) based on DominatorTree(#56 by ДВП)");
            Console.WriteLine("###### and PrettyPrinter(#5 by APC TEAM) DEMONSTARTION:");
            Console.WriteLine("######       Sample 1:");
            Console.WriteLine(prettyPrinter.Text);
            Console.WriteLine("###### Dominator Tree Matrix:");
            Console.WriteLine(domTree.ToString());
            Console.WriteLine($"###### CFG is reducible: {cfg.IsReducible}");
            Console.WriteLine($"###### CFG depth is: {cfg.Depth}");


            fpath   = @"..\..\..\CodeSamples\reducibilityGoodSample.txt";
            astRoot = null;
            astRoot = AST(fpath);
            if (astRoot == null)
            {
                return;
            }
            tacodeVisitor = new TACodeVisitor();
            astRoot.Visit(tacodeVisitor);
            prettyPrinter = new PrettyPrintVisitor();
            astRoot.Visit(prettyPrinter);
            cfg     = new ControlFlowGraph(tacodeVisitor.Code);
            domTree = new DominatorTree(cfg);
            Console.WriteLine("###########################################");
            Console.WriteLine("######       Sample 2:");
            Console.WriteLine("###### Program text from PrettyPrinter:\n");
            Console.WriteLine(prettyPrinter.Text);
            Console.WriteLine("###### Dominator Tree Matrix:");
            Console.WriteLine(domTree.ToString());
            Console.WriteLine($"###### CFG is reducible: {cfg.IsReducible}");
        }
Example #2
0
 public FunctionNode(Token token, VariableIdNode idNode, ParametersNode parametersNode, BlockNode block, Scope scope)
     : base(token, scope)
 {
     this.block      = block;
     this.parameters = parametersNode;
     this.returnType = idNode != null ? idNode.VariableType : TokenType.UNDEFINED;
     this.idNode     = idNode;
 }
Example #3
0
 public ProgramNode CreateProgramNode(Token token, Dictionary <string, FunctionNode> functions, BlockNode mainBlock, Scope scope)
 {
     return(new ProgramNode(token, functions, mainBlock, scope));
 }
Example #4
0
 public FunctionNode CreateFunctionNode(Token token, INameFactory labelFactory, VariableIdNode idNode, ParametersNode parameters, BlockNode blockNode, Scope scope)
 {
     return(new FunctionNode(token, idNode, parameters, blockNode, scope));
 }
Example #5
0
 public ProgramNode(Token token, Dictionary <string, FunctionNode> functionNodes, BlockNode mainBlock, Scope scope)
     : base(token, scope: scope)
 {
     this.mainBlock = mainBlock;
     this.functions = functionNodes;
 }
Example #6
0
 public ProcedureNode(Token token, INameFactory labelFactory, VariableIdNode idNode, ParametersNode parametersNode, BlockNode block, Scope scope)
     : base(token, idNode, parametersNode, block, scope)
 {
 }
Example #7
0
 public void VisitBlockNode(BlockNode node)
 {
 }