Example #1
0
 public void Build(IEnumerable <IDeclaration> declarations, ISymbolTree symbolTree)
 {
     foreach (var declaration in declarations)
     {
         Build(declaration, symbolTree);
     }
 }
Example #2
0
 public IForwardDataFlowAnalysis <VariableFlags> BeginAnalysis(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     return(new DefiniteAssignmentAnalysis(declaration, symbolTree, diagnostics));
 }
Example #3
0
 public IBackwardDataFlowAnalysis <VariableFlags> BeginAnalysis(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics _)
 {
     return(new LivenessAnalysis(declaration, symbolTree));
 }
        public VariableFlags(IExecutableDeclaration declaration, ISymbolTree symbolTree, bool defaultValue)
        {
            var invocableSymbol = declaration.Symbol;

            symbolMap = symbolTree.Children(invocableSymbol).Cast <BindingSymbol>().Enumerate().ToFixedDictionary();
            flags     = new BitArray(symbolMap.Count, defaultValue);
        }
Example #5
0
 public IForwardDataFlowAnalysis <VariableFlags> BeginAnalysis(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     return(new UseOfMovedValueAnalysis(declaration, symbolTree, diagnostics));
 }
 public BindingMutabilityAnalysis(IExecutableDeclaration declaration, ISymbolTree symbolTree, Diagnostics diagnostics)
 {
     this.declaration = declaration;
     this.symbolTree  = symbolTree;
     file             = declaration.File;
     this.diagnostics = diagnostics;
 }
Example #7
0
 public IForwardDataFlowAnalysis <VariableFlags> BeginAnalysis(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     return(new BindingMutabilityAnalysis(declaration, symbolTree, diagnostics));
 }
Example #8
0
        private DeclarationIL Build(IDeclaration declaration, ISymbolTree symbolTree)
        {
            if (declarationsIL.TryGetValue(declaration.Symbol, out var declarationIL))
            {
                return(declarationIL);
            }

            switch (declaration)
            {
            default:
                throw ExhaustiveMatch.Failed(declaration);

            case IFunctionDeclaration function:
            {
                var il = ilFactory.CreateGraph(function);
                declarationIL = new FunctionIL(false, false, function.Symbol, BuildParameters(function.Parameters), il);
                break;
            }

            case IAssociatedFunctionDeclaration associatedFunction:
            {
                var il = ilFactory.CreateGraph(associatedFunction);
                declarationIL = new FunctionIL(false, true, associatedFunction.Symbol, BuildParameters(associatedFunction.Parameters), il);
                break;
            }

            case IConcreteMethodDeclaration method:
            {
                var il = ilFactory.CreateGraph(method);
                declarationIL = new MethodDeclarationIL(method.Symbol, BuildParameter(method.SelfParameter), BuildParameters(method.Parameters), il);
                break;
            }

            case IAbstractMethodDeclaration method:
            {
                declarationIL = new MethodDeclarationIL(method.Symbol, BuildParameter(method.SelfParameter), BuildParameters(method.Parameters), null);
                break;
            }

            case IConstructorDeclaration constructor:
            {
                var il                   = ilFactory.CreateGraph(constructor);
                var parameters           = BuildConstructorParameters(constructor);
                var fieldInitializations = BuildFieldInitializations(constructor);
                declarationIL = new ConstructorIL(constructor.Symbol, parameters, fieldInitializations, il);
                break;
            }

            case IFieldDeclaration fieldDeclaration:
                declarationIL = new FieldIL(fieldDeclaration.Symbol);
                break;

            case IClassDeclaration classDeclaration:
                declarationIL = new ClassIL(classDeclaration.Symbol,
                                            BuildClassMembers(classDeclaration, symbolTree));
                break;
            }
            declarationsIL.Add(declaration.Symbol, declarationIL);
            return(declarationIL);
        }
Example #9
0
 public ForwardDataFlowAnalyzer(
     IForwardDataFlowAnalyzer <TState> strategy,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     this.strategy    = strategy;
     this.symbolTree  = symbolTree;
     this.diagnostics = diagnostics;
 }
 public UseOfMovedValueAnalysis(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     this.declaration = declaration;
     this.symbolTree  = symbolTree;
     file             = declaration.File;
     this.diagnostics = diagnostics;
 }
 public DefiniteAssignmentAnalysis(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     this.declaration = declaration;
     this.symbolTree  = symbolTree;
     this.file        = declaration.File;
     this.diagnostics = diagnostics;
 }
 private ReachabilityAnalyzer(
     IExecutableDeclaration declaration,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     this.declaration = declaration;
     this.symbolTree  = symbolTree;
     file             = declaration.File;
     this.diagnostics = diagnostics;
 }
 public static void Analyze(
     FixedSet <IExecutableDeclaration> declarations,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     foreach (var declaration in declarations)
     {
         new ReachabilityAnalyzer(declaration, symbolTree, diagnostics).Analyze();
     }
 }
Example #14
0
        private FixedList <DeclarationIL> BuildClassMembers(
            IClassDeclaration classDeclaration,
            ISymbolTree symbolTree)
        {
            var members            = BuildList(classDeclaration.Members, symbolTree);
            var defaultConstructor = BuildDefaultConstructor(classDeclaration, symbolTree);

            if (!(defaultConstructor is null))
            {
                members = members.Append(defaultConstructor).ToFixedList();
            }
            return(members.ToFixedList());
        }
        public static void Check <TState>(
            IBackwardDataFlowAnalyzer <TState> strategy,
            FixedSet <IExecutableDeclaration> declarations,
            ISymbolTree symbolTree,
            Diagnostics diagnostics)
            where TState : class
        {
            var dataFlowAnalyzer = new BackwardDataFlowAnalyzer <TState>(strategy, symbolTree, diagnostics);

            foreach (var invocableDeclaration in declarations)
            {
                dataFlowAnalyzer.Check(invocableDeclaration);
            }
        }
Example #16
0
        private DeclarationIL?BuildDefaultConstructor(
            IClassDeclaration classDeclaration,
            ISymbolTree symbolTree)
        {
            var constructorSymbol = classDeclaration.DefaultConstructorSymbol;

            if (constructorSymbol is null)
            {
                return(null);
            }

            if (declarationsIL.TryGetValue(constructorSymbol, out var declaration))
            {
                return(declaration);
            }

            var selfParameterSymbol = symbolTree.Children(constructorSymbol).OfType <SelfParameterSymbol>().Single();
            var selfParameter       = new SelfParameterIL(selfParameterSymbol);
            var parameters          = selfParameter.Yield().ToFixedList <ParameterIL>();

            var graph = new ControlFlowGraphBuilder(classDeclaration.File);

            graph.AddSelfParameter(selfParameterSymbol);
            var block = graph.NewBlock();

            block.End(new ReturnVoidInstruction(classDeclaration.NameSpan, Scope.Outer));

            //var il = new ControlFlowGraphBuilder(classDeclaration.File);
            //il.AddSelfParameter(selfType);
            //var block = il.NewBlock();
            //block.End(classDeclaration.NameSpan, Scope.Outer);

            var defaultConstructor = new ConstructorIL(// TODO how to get a name
                constructorSymbol,
                parameters, FixedList <FieldInitializationIL> .Empty, graph.Build());

            //defaultConstructor.ControlFlowOld.InsertedDeletes = new InsertedDeletes();
            declarationsIL.Add(constructorSymbol, defaultConstructor);
            return(defaultConstructor);
        }
 public SymbolValidator(ISymbolTree symbolTree)
 {
     this.symbolTree = symbolTree;
 }
Example #18
0
 public LivenessAnalysis(IExecutableDeclaration declaration, ISymbolTree symbolTree)
 {
     this.declaration = declaration;
     this.symbolTree  = symbolTree;
 }
Example #19
0
 private FixedList <DeclarationIL> BuildList(
     IEnumerable <IMemberDeclaration> memberDeclarations,
     ISymbolTree symbolTree)
 {
     return(memberDeclarations.Select(e => Build(e, symbolTree)).ToFixedList());
 }