예제 #1
0
 private void Check(FixedSet <IEntityDeclarationSyntax> entities)
 {
     foreach (var entity in entities)
     {
         ResolveBodyTypes(entity);
     }
 }
예제 #2
0
        /// <remarks>
        /// It wouldn't make sense to get all declarations including non-member because
        /// that includes namespace declarations. However, some namespaces come from
        /// the implicit namespace of a compilation unit or are implicitly declared,
        /// so it wouldn't give a full list of the namespaces.
        /// </remarks>
        private static IEnumerable <IEntityDeclarationSyntax> GetEntityDeclarations(
            FixedSet <ICompilationUnitSyntax> compilationUnits)
        {
            var declarations = new Queue <IDeclarationSyntax>();

            declarations.EnqueueRange(compilationUnits.SelectMany(cu => cu.Declarations));
            while (declarations.TryDequeue(out var declaration))
            {
                switch (declaration)
                {
                default:
                    throw ExhaustiveMatch.Failed(declaration);

                case IMemberDeclarationSyntax syn:
                    yield return(syn);

                    break;

                case IFunctionDeclarationSyntax syn:
                    yield return(syn);

                    break;

                case INamespaceDeclarationSyntax syn:
                    declarations.EnqueueRange(syn.Declarations);
                    break;

                case IClassDeclarationSyntax syn:
                    yield return(syn);

                    declarations.EnqueueRange(syn.Members);
                    break;
                }
            }
        }
예제 #3
0
        private void ResolveReachabilityAnnotation(
            CodeFile file,
            IParameterNameSyntax syntax,
            FixedSet <BindingSymbol> symbols)
        {
            switch (syntax)
            {
            default:
                throw ExhaustiveMatch.Failed(syntax);

            case INamedParameterNameSyntax syn:
            {
                var referencedSymbol = symbols.OfType <VariableSymbol>().SingleOrDefault(s => s.Name == syn.Name);
                syn.ReferencedSymbol.Fulfill(referencedSymbol);
                if (referencedSymbol is null)
                {
                    diagnostics.Add(NameBindingError.CouldNotBindParameterName(file, syn.Span));
                }
            }
            break;

            case ISelfParameterNameSyntax syn:
            {
                var referencedSymbol = symbols.OfType <SelfParameterSymbol>().SingleOrDefault();
                syn.ReferencedSymbol.Fulfill(referencedSymbol);
                if (referencedSymbol is null)
                {
                    diagnostics.Add(NameBindingError.CouldNotBindParameterName(file, syn.Span));
                }
            }
            break;
            }
        }
예제 #4
0
 protected ReachabilityChain(FixedSet <Reference> references)
 {
     if (references.Count == 0)
     {
         throw new ArgumentException("Must not be empty", nameof(references));
     }
     References = references;
 }
 public FunctionSymbol(
     Symbol containingSymbol,
     Name name,
     FixedList <DataType> parameterDataTypes,
     FixedSet <ReachabilityAnnotation>?reachabilityAnnotations = null)
     : this(containingSymbol, name, parameterDataTypes, DataType.Void, reachabilityAnnotations ?? FixedSet <ReachabilityAnnotation> .Empty)
 {
 }
 protected FunctionOrMethodSymbol(
     Symbol containingSymbol,
     Name name,
     FixedList <DataType> parameterDataTypes,
     DataType returnDataType,
     FixedSet <ReachabilityAnnotation> reachabilityAnnotations)
     : base(containingSymbol, name, parameterDataTypes, returnDataType, reachabilityAnnotations)
 {
     Name = name;
 }
 public static void Analyze(
     FixedSet <IExecutableDeclaration> declarations,
     ISymbolTree symbolTree,
     Diagnostics diagnostics)
 {
     foreach (var declaration in declarations)
     {
         new ReachabilityAnalyzer(declaration, symbolTree, diagnostics).Analyze();
     }
 }
 public FunctionSymbol(
     Symbol containingSymbol,
     Name name,
     FixedList <DataType> parameterDataTypes,
     DataType returnDataType,
     FixedSet <ReachabilityAnnotation>?reachabilityAnnotations = null)
     : base(containingSymbol, name, parameterDataTypes, returnDataType, reachabilityAnnotations ?? FixedSet <ReachabilityAnnotation> .Empty)
 {
     Name = name;
 }
 public ConstructorSymbol(
     ObjectTypeSymbol containingSymbol,
     Name?name,
     FixedList <DataType> parameterDataTypes,
     FixedSet <ReachabilityAnnotation>?reachabilityAnnotations = null)
     : base(containingSymbol, name, parameterDataTypes,
            containingSymbol.DeclaresDataType.ToConstructorReturn(),
            reachabilityAnnotations ?? FixedSet <ReachabilityAnnotation> .Empty)
 {
     ContainingSymbol = containingSymbol;
     ReturnDataType   = containingSymbol.DeclaresDataType.ToConstructorReturn();
 }
예제 #10
0
 public PackageSyntax(
     Name name,
     FixedSet <ICompilationUnitSyntax> compilationUnits,
     FixedDictionary <Name, PackageIL> references)
 {
     Symbol                = new PackageSymbol(name);
     SymbolTree            = new SymbolTreeBuilder(Symbol);
     CompilationUnits      = compilationUnits;
     AllEntityDeclarations = GetEntityDeclarations(CompilationUnits).ToFixedSet();
     References            = references;
     SymbolTrees           = new SymbolForest(Primitive.SymbolTree, SymbolTree, ReferencedPackages.Select(p => p.SymbolTree));
     Diagnostics           = new Diagnostics(CompilationUnits.SelectMany(cu => cu.Diagnostics));
 }
예제 #11
0
 public MethodSymbol(
     TypeSymbol containingSymbol,
     Name name,
     DataType selfDataType,
     FixedList <DataType> parameterDataTypes,
     DataType returnDataType,
     FixedSet <ReachabilityAnnotation>?reachabilityAnnotations = null)
     : base(containingSymbol, name, parameterDataTypes, returnDataType, reachabilityAnnotations ?? FixedSet <ReachabilityAnnotation> .Empty)
 {
     ContainingSymbol = containingSymbol;
     Name             = name;
     SelfDataType     = selfDataType;
 }
예제 #12
0
 public PackageIL(
     FixedSymbolTree symbolTree,
     FixedList <Diagnostic> diagnostics,
     FixedSet <PackageIL> references,
     IEnumerable <DeclarationIL> declarations,
     FunctionIL entryPoint)
 {
     Symbol       = symbolTree.Package;
     SymbolTree   = symbolTree;
     Diagnostics  = diagnostics;
     References   = references;
     EntryPoint   = entryPoint;
     Declarations = declarations.ToFixedSet();
 }
예제 #13
0
        private void Build(FixedSet <IEntityDeclarationSyntax> entities)
        {
            // Process all classes first because they may be referenced by functions etc.
            foreach (var @class in entities.OfType <IClassDeclarationSyntax>())
            {
                BuildClassSymbol(@class);
            }

            // Now resolve all other symbols (class declarations will already have symbols and won't be processed again)
            foreach (var entity in entities)
            {
                BuildEntitySymbol(entity);
            }
        }
예제 #14
0
 protected InvocableSymbol(
     Symbol containingSymbol,
     Name?name,
     FixedList <DataType> parameterDataTypes,
     DataType returnDataType,
     FixedSet <ReachabilityAnnotation> reachabilityAnnotations)
     : base(containingSymbol, name)
 {
     ContainingSymbol        = containingSymbol;
     Name                    = name;
     ParameterDataTypes      = parameterDataTypes;
     ReturnDataType          = returnDataType;
     ReachabilityAnnotations = reachabilityAnnotations;
 }
        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);
            }
        }
예제 #16
0
 public PrimitiveSymbolTree(FixedDictionary <Symbol, FixedSet <Symbol> > symbolChildren)
 {
     this.symbolChildren = symbolChildren;
     GlobalSymbols       = symbolChildren.Keys.Where(s => s.ContainingSymbol is null).ToFixedSet();
 }
 public ReachabilityAnnotation(FixedSet <Reference> references, ReachabilityChain canReach)
     : base(references)
 {
     CanReach = canReach;
 }
 public ReachableReferences(FixedSet <Reference> references)
     : base(references)
 {
 }