internal ContainerBinder(Binder containingScope, NamespaceReference mergedContainer, IEnumerable<ImportedSymbol> imports)
     : base(containingScope)
 {
     this.mergedContainer = mergedContainer;
     foreach(var import in imports)
         this.imports.Add(import.AliasName, import);
 }
 internal NamespaceBinder(Binder containingScope, NamespaceReference mergedContainer, IEnumerable<ImportedSymbol> imports)
     : base(containingScope, mergedContainer, imports)
 {
 }
 private void Build(ExpressionSyntax expression, Binder containingScope)
 {
     expression.Match()
         .With<AssignmentSyntax>(assignment =>
         {
             Build(assignment.LValue, containingScope);
             Build(assignment.RValue, containingScope);
         })
         .With<MemberAccessSyntax>(memberExpression =>
         {
             Build(memberExpression.Expression, containingScope);
         })
         .With<SelfSyntax, IdentifierNameSyntax>(variableExpression =>
         {
             binders.Add(variableExpression, containingScope);
         })
         .With<CallSyntax>(call =>
         {
             Build(call.Expression, containingScope);
             foreach(var argument in call.Arguments)
                 Build(argument, containingScope);
         })
         .With<CastSyntax>(cast =>
         {
             Build(cast.Expression, containingScope);
             Build(cast.Type, containingScope);
         })
         .Ignore<LiteralSyntax>()
         .Exhaustive();
 }
        private IEnumerable<ImportedSymbol> GatherImportedSymbols(UsingSyntax usingDirective, Binder scope)
        {
            var lookup = scope.LookupInGlobalNamespace(usingDirective.Name, package);

            if(!lookup.IsViable)
                diagnostics.AddBindingError(compilationUnit.SourceFile, usingDirective.Name.Position, $"Could not bind using statement for {usingDirective.Name}");

            var symbol = lookup.Symbols.Single();
            var @namespace = symbol as NamespaceReference;
            if(@namespace != null)
                return @namespace.GetMembers().Select(m => new ImportedSymbol(m, null));

            return new[] { new ImportedSymbol(symbol, null) };
        }
 private Binder Build(StatementSyntax statement, Binder containingScope)
 {
     return statement.Match().Returning<Binder>()
         .With<ExpressionStatementSyntax>(expressionStatement =>
         {
             Build(expressionStatement.Expression, containingScope);
             return containingScope;
         })
         .With<ReturnSyntax>(returnStatement =>
         {
             Build(returnStatement.Expression, containingScope);
             return containingScope;
         })
         .Exhaustive();
 }
 private void Build(ValueTypeSyntax type, Binder containingScope)
 {
     type.Match()
         .With<PredefinedTypeSyntax>(predefinedType =>
         {
             // Not really sure this makes sense since a predefined type is a keyword
             binders.Add(predefinedType, containingScope);
         })
         .With<GenericNameSyntax>(genericName =>
         {
             binders.Add(genericName, containingScope);
             // TODO associate the type parameters
         })
         .With<IdentifierNameSyntax>(identifierName =>
         {
             binders.Add(identifierName, containingScope);
         })
         .Exhaustive();
 }
Ejemplo n.º 7
0
 public FunctionBinder(Binder containingScope)
     : base(containingScope)
 {
 }
 protected Binder(Binder containingScope)
 {
     ContainingScope = containingScope;
 }
 public ClassBinder(Binder containingScope, ClassSyntax @class)
     : base(containingScope)
 {
 }