Esempio n. 1
0
 private BoundNode BindGlobalDeclaration(SyntaxNode declaration, Symbol parent)
 {
     switch (declaration.Kind)
     {
         case SyntaxKind.VariableDeclarationStatement:
             return BindVariableDeclarationStatement((VariableDeclarationStatementSyntax) declaration, parent);
         case SyntaxKind.FunctionDeclaration:
             return BindFunctionDeclaration((FunctionDeclarationSyntax) declaration, parent);
         case SyntaxKind.FunctionDefinition:
             return BindFunctionDefinition((FunctionDefinitionSyntax) declaration, parent);
         case SyntaxKind.ConstantBufferDeclaration:
             return BindConstantBufferDeclaration((ConstantBufferSyntax) declaration);
         case SyntaxKind.TypeDeclarationStatement:
             return BindTypeDeclaration((TypeDeclarationStatementSyntax) declaration, parent);
         case SyntaxKind.Namespace:
             return BindNamespace((NamespaceSyntax) declaration);
         case SyntaxKind.TechniqueDeclaration:
             return BindTechniqueDeclaration((TechniqueSyntax) declaration);
         case SyntaxKind.TypedefStatement:
             return BindTypedefStatement((TypedefStatementSyntax) declaration);
         case SyntaxKind.EmptyStatement:
             return BindEmptyStatement((EmptyStatementSyntax) declaration);
         default:
             throw new ArgumentOutOfRangeException(declaration.Kind.ToString());
     }
 }
Esempio n. 2
0
 private BoundStatement BindStatement(StatementSyntax syntax, Symbol parent)
 {
     switch (syntax.Kind)
     {
         case SyntaxKind.Block:
             return BindBlock((BlockSyntax) syntax, parent);
         case SyntaxKind.BreakStatement:
             return BindBreakStatement((BreakStatementSyntax) syntax);
         case SyntaxKind.DiscardStatement:
             return BindDiscardStatement((DiscardStatementSyntax) syntax);
         case SyntaxKind.DoStatement:
             return BindDoStatement((DoStatementSyntax) syntax, parent);
         case SyntaxKind.ExpressionStatement:
             return BindExpressionStatement((ExpressionStatementSyntax) syntax);
         case SyntaxKind.ForStatement:
             return BindForStatement((ForStatementSyntax) syntax, parent);
         case SyntaxKind.IfStatement:
             return BindIfStatement((IfStatementSyntax) syntax, parent);
         case SyntaxKind.ReturnStatement:
             return BindReturnStatement((ReturnStatementSyntax) syntax);
         case SyntaxKind.VariableDeclarationStatement:
             return BindVariableDeclarationStatement((VariableDeclarationStatementSyntax) syntax, parent);
         case SyntaxKind.SwitchStatement:
             return BindSwitchStatement((SwitchStatementSyntax) syntax, parent);
         case SyntaxKind.WhileStatement:
             return BindWhileStatement((WhileStatementSyntax) syntax, parent);
         case SyntaxKind.EmptyStatement:
             return BindEmptyStatement((EmptyStatementSyntax) syntax);
         default:
             throw new NotSupportedException("Not supported: " + syntax.Kind);
     }
 }
Esempio n. 3
0
 internal Symbol(SymbolKind kind, string name, string documentation, Symbol parent)
 {
     Kind = kind;
     Name = name;
     Documentation = documentation;
     Parent = parent;
 }
Esempio n. 4
0
 protected bool EqualsImpl(Symbol other)
 {
     return Kind == other.Kind
         && string.Equals(Name, other.Name)
         && (Parent == null) == (other.Parent == null)
         && (Parent == null || Parent.EqualsImpl(other.Parent));
 }
Esempio n. 5
0
        private BoundStatement BindDoStatement(DoStatementSyntax syntax, Symbol parent)
        {
            BindAttributes(syntax.Attributes);

            return new BoundDoStatement(
                Bind(syntax.Condition, BindExpression),
                Bind(syntax.Statement, x => BindStatement(x, parent)));
        }
Esempio n. 6
0
        internal ParameterSymbol(string name, string documentation, Symbol parent, TypeSymbol valueType, ParameterDirection direction = ParameterDirection.In)
            : base(SymbolKind.Parameter, name, documentation, parent, valueType)
        {
            if (valueType == null)
                throw new ArgumentNullException(nameof(valueType));

            Direction = direction;
        }
Esempio n. 7
0
 public CompletionItem(string displayText, string insertionText, string description, Glyph? glyph, Symbol symbol, bool isBuilder)
 {
     DisplayText = displayText;
     InsertionText = insertionText;
     Description = description;
     Glyph = glyph;
     Symbol = symbol;
     IsBuilder = isBuilder;
 }
Esempio n. 8
0
        private BoundStatement BindSwitchStatement(SwitchStatementSyntax syntax, Symbol parent)
        {
            BindAttributes(syntax.Attributes);

            var switchBinder = new Binder(_sharedBinderState, this);
            var boundSections = syntax.Sections.Select(x => switchBinder.Bind(x, y => switchBinder.BindSwitchSection(y, parent))).ToImmutableArray();

            return new BoundSwitchStatement(
                Bind(syntax.Expression, BindExpression),
                boundSections);
        }
Esempio n. 9
0
        internal InvocableSymbol(SymbolKind kind, string name, string documentation, Symbol parent, TypeSymbol returnType, Func<InvocableSymbol, IEnumerable<ParameterSymbol>> lazyParameters = null)
            : base(kind, name, documentation, parent)
        {
            if (returnType == null)
                throw new ArgumentNullException(nameof(returnType));

            _parameters = new List<ParameterSymbol>();

            if (lazyParameters != null)
                foreach (var parameter in lazyParameters(this))
                    AddParameter(parameter);

            ReturnType = returnType;
        }
Esempio n. 10
0
        public static IEnumerable<SymbolSpan> FindUsages(this SemanticModel semanticModel, Symbol symbol)
        {
            if (semanticModel == null)
                throw new ArgumentNullException(nameof(semanticModel));

            if (symbol == null)
                throw new ArgumentNullException(nameof(symbol));

            var syntaxTree = semanticModel.SyntaxTree;

            return from n in syntaxTree.Root.DescendantNodes()
                from s in GetSymbolSpans(semanticModel, n)
                where s.Symbol.Equals(symbol)
                select s;
        }
Esempio n. 11
0
        private BoundType BindType(TypeSyntax syntax, Symbol parent)
        {
            switch (syntax.Kind)
            {
                case SyntaxKind.PredefinedScalarType:
                    return BindScalarType((ScalarTypeSyntax) syntax);
                case SyntaxKind.PredefinedVectorType:
                    return BindVectorType((VectorTypeSyntax) syntax);
                case SyntaxKind.PredefinedGenericVectorType:
                    return BindGenericVectorType((GenericVectorTypeSyntax) syntax);
                case SyntaxKind.PredefinedMatrixType:
                    return BindMatrixType((MatrixTypeSyntax) syntax);
                case SyntaxKind.PredefinedGenericMatrixType:
                    return BindGenericMatrixType((GenericMatrixTypeSyntax) syntax);
                case SyntaxKind.PredefinedObjectType:
                    return new BoundObjectType(BindObjectType((PredefinedObjectTypeSyntax) syntax));
                case SyntaxKind.StructType:
                    {
                        // Inline struct.
                        return BindStructDeclaration((StructTypeSyntax) syntax, parent);
                    }
                case SyntaxKind.IdentifierName:
                    {
                        var identifierName = (IdentifierNameSyntax) syntax;
                        var symbols = LookupTypeSymbol(identifierName.Name).ToImmutableArray();
                        if (symbols.Length == 0)
                        {
                            Diagnostics.ReportUndeclaredType(syntax);
                            return new BoundUnknownType();
                        }

                        if (symbols.Length > 1)
                            Diagnostics.ReportAmbiguousType(identifierName.Name, symbols);

                        return new BoundName(symbols.First());
                    }
                case SyntaxKind.QualifiedName:
                    {
                        var qualifiedName = (QualifiedNameSyntax) syntax;
                        return BindQualifiedType(qualifiedName);
                    }
                default:
                    throw new InvalidOperationException(syntax.Kind.ToString());
            }
        }
Esempio n. 12
0
 internal NamespaceSymbol(NamespaceSyntax syntax, Symbol parent)
     : base(SymbolKind.Namespace, syntax.Name.Text, string.Empty, parent)
 {
     Syntax = syntax;
 }
Esempio n. 13
0
 private BoundType BindTypeDefinition(TypeDefinitionSyntax syntax, Symbol parent)
 {
     switch (syntax.Kind)
     {
         case SyntaxKind.ClassType:
             return BindClassDeclaration((ClassTypeSyntax) syntax, parent);
         case SyntaxKind.StructType:
             return BindStructDeclaration((StructTypeSyntax) syntax, parent);
         case SyntaxKind.InterfaceType:
             return BindInterfaceDeclaration((InterfaceTypeSyntax) syntax, parent);
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Esempio n. 14
0
        private BoundInterfaceType BindInterfaceDeclaration(InterfaceTypeSyntax declaration, Symbol parent)
        {
            var interfaceSymbol = new InterfaceSymbol(declaration, parent);
            AddSymbol(interfaceSymbol, declaration.Name.Span);

            var methods = new List<BoundFunction>();
            var interfaceBinder = new Binder(_sharedBinderState, this);
            foreach (var memberSyntax in declaration.Methods)
                methods.Add(interfaceBinder.Bind(memberSyntax, x => interfaceBinder.BindFunctionDeclaration(x, interfaceSymbol)));

            foreach (var member in interfaceBinder.LocalSymbols.Values.SelectMany(x => x))
                interfaceSymbol.AddMember(member);

            return new BoundInterfaceType(interfaceSymbol, methods.ToImmutableArray());
        }
Esempio n. 15
0
        private BoundClassType BindClassDeclaration(ClassTypeSyntax declaration, Symbol parent)
        {
            ClassOrStructSymbol baseType;
            List<InterfaceSymbol> baseInterfaces;
            BindBaseList(declaration.BaseList, parent, out baseType, out baseInterfaces);

            var classBinder = new Binder(_sharedBinderState, this);

            var classSymbol = new ClassSymbol(declaration, parent, baseType, baseInterfaces.ToImmutableArray(), classBinder);
            AddSymbol(classSymbol, declaration.Name.Span);

            var members = new List<BoundNode>();

            foreach (var memberSyntax in declaration.Members)
            {
                switch (memberSyntax.Kind)
                {
                    case SyntaxKind.VariableDeclarationStatement:
                        members.Add(classBinder.Bind((VariableDeclarationStatementSyntax) memberSyntax, x => classBinder.BindVariableDeclarationStatement(x, classSymbol)));
                        break;
                    case SyntaxKind.FunctionDeclaration:
                        members.Add(classBinder.Bind((FunctionDeclarationSyntax) memberSyntax, x => classBinder.BindFunctionDeclaration(x, classSymbol)));
                        break;
                    case SyntaxKind.FunctionDefinition:
                        members.Add(classBinder.Bind((FunctionDefinitionSyntax) memberSyntax, x => classBinder.BindFunctionDefinition(x, classSymbol)));
                        break;
                }
            }

            foreach (var member in classBinder.LocalSymbols.Values.SelectMany(x => x))
                classSymbol.AddMember(member);

            return new BoundClassType(classSymbol, members.ToImmutableArray());
        }
Esempio n. 16
0
        private BoundFunctionDeclaration BindFunctionDeclaration(FunctionDeclarationSyntax declaration, Symbol parent)
        {
            BindAttributes(declaration.Attributes);

            var boundReturnType = Bind(declaration.ReturnType, x => BindType(x, parent));

            var functionSymbol = LocalSymbols.OfType<SourceFunctionSymbol>()
                .FirstOrDefault(x => SyntaxFacts.HaveMatchingSignatures(
                    x.DefinitionSyntax as FunctionSyntax ?? x.DeclarationSyntaxes[0],
                    declaration));

            if (functionSymbol != null)
            {
                functionSymbol.DeclarationSyntaxes.Add(declaration);
            }
            else
            {
                functionSymbol = new SourceFunctionSymbol(declaration, parent, boundReturnType.TypeSymbol);
                AddSymbol(functionSymbol, declaration.Name.GetTextSpanSafe(), true);
            }

            if (declaration.Semantic != null)
                Bind(declaration.Semantic, BindVariableQualifier);

            var functionBinder = new Binder(_sharedBinderState, this);

            var boundParameters = BindParameters(declaration.ParameterList, functionBinder, functionSymbol);

            return new BoundFunctionDeclaration(functionSymbol, boundReturnType, boundParameters.ToImmutableArray());
        }
Esempio n. 17
0
        private BoundMultipleVariableDeclarations BindVariableDeclaration(VariableDeclarationSyntax syntax, Symbol parent, Func<VariableDeclaratorSyntax, TypeSymbol, VariableSymbol> createSymbol)
        {
            var boundType = Bind(syntax.Type, x => BindType(x, parent));

            var boundDeclarations = new List<BoundVariableDeclaration>();
            foreach (var declarator in syntax.Variables)
            {
                boundDeclarations.Add(Bind(declarator, x => BindVariableDeclarator(x, boundType.TypeSymbol, createSymbol)));
            }

            return new BoundMultipleVariableDeclarations(boundDeclarations.ToImmutableArray());
        }
Esempio n. 18
0
 private BoundMultipleVariableDeclarations BindVariableDeclaration(VariableDeclarationSyntax syntax, Symbol parent)
 {
     return BindVariableDeclaration(syntax, parent, (d, t) => new VariableSymbol(d, parent, t));
 }
Esempio n. 19
0
 public static QuickInfoModel ForSymbol(SemanticModel semanticModel, TextSpan span, Symbol symbol)
 {
     var glyph = symbol.GetGlyph();
     var symbolMarkup = SymbolMarkup.ForSymbol(symbol);
     return new QuickInfoModel(semanticModel, span, glyph, symbolMarkup, symbol.Documentation);
 }
Esempio n. 20
0
 private ImmutableArray<BoundNode> BindTopLevelDeclarations(List<SyntaxNode> declarations, Symbol parent)
 {
     return declarations.Select(x => Bind(x, y => BindGlobalDeclaration(y, parent))).ToImmutableArray();
 }
Esempio n. 21
0
 internal FunctionSymbol(string name, string documentation, Symbol parent, TypeSymbol returnType, Func<InvocableSymbol, IEnumerable<ParameterSymbol>> lazyParameters = null, bool isNumericConstructor = false)
     : base(SymbolKind.Function, name, documentation, parent, returnType, lazyParameters)
 {
     IsNumericConstructor = isNumericConstructor;
 }
Esempio n. 22
0
        private BoundNode BindFunctionDefinition(FunctionDefinitionSyntax declaration, Symbol parent)
        {
            BindAttributes(declaration.Attributes);

            var boundReturnType = Bind(declaration.ReturnType, x => BindType(x, parent));

            var isQualifiedName = false;

            ContainerSymbol containerSymbol;
            Symbol functionOwner;
            switch (declaration.Name.Kind)
            {
                case SyntaxKind.IdentifierDeclarationName:
                    containerSymbol = null;
                    functionOwner = parent;
                    break;
                case SyntaxKind.QualifiedDeclarationName:
                    containerSymbol = LookupContainer(((QualifiedDeclarationNameSyntax) declaration.Name).Left);
                    if (containerSymbol == null)
                        return new BoundErrorNode();
                    isQualifiedName = true;
                    functionOwner = containerSymbol;
                    break;
                default:
                    throw new InvalidOperationException();
            }

            var containerBinder = containerSymbol?.Binder ?? this;

            var symbolTable = containerBinder.LocalSymbols;

            var functionSymbol = symbolTable
                .SelectMany(x => x.Value)
                .OfType<SourceFunctionSymbol>()
                .FirstOrDefault(x => SyntaxFacts.HaveMatchingSignatures(
                    x.DefinitionSyntax as FunctionSyntax ?? x.DeclarationSyntaxes[0],
                    declaration));

            if (functionSymbol != null)
            {
                if (functionSymbol.DefinitionSyntax != null)
                    Diagnostics.ReportSymbolRedefined(declaration.Name.GetTextSpanSafe(), functionSymbol);
                else
                    functionSymbol.DefinitionSyntax = declaration;
            }
            else
            {
                if (isQualifiedName)
                    Diagnostics.ReportUndeclaredFunctionInNamespaceOrClass((QualifiedDeclarationNameSyntax) declaration.Name);
                functionSymbol = new SourceFunctionSymbol(declaration, parent, boundReturnType.TypeSymbol);
                containerBinder.AddSymbol(functionSymbol, declaration.Name.GetTextSpanSafe(), true);
            }

            if (declaration.Semantic != null)
                Bind(declaration.Semantic, BindVariableQualifier);

            var functionBinder = (functionOwner != null && functionOwner.Kind == SymbolKind.Class)
                ? new ClassMethodBinder(_sharedBinderState, this, (ClassSymbol) functionOwner)
                : new Binder(_sharedBinderState, this);

            if (isQualifiedName)
                functionBinder = new ContainedFunctionBinder(_sharedBinderState, functionBinder, containerSymbol.Binder);

            var boundParameters = BindParameters(declaration.ParameterList, functionBinder, functionSymbol);
            var boundBody = functionBinder.Bind(declaration.Body, x => functionBinder.BindBlock(x, functionSymbol));

            return new BoundFunctionDefinition(functionSymbol, boundReturnType, boundParameters.ToImmutableArray(), boundBody);
        }
Esempio n. 23
0
 internal ClassSymbol(ClassTypeSyntax syntax, Symbol parent, ClassOrStructSymbol baseType, ImmutableArray<InterfaceSymbol> baseInterfaces, Binder binder)
     : base(SymbolKind.Class, syntax.Name.Text, parent, baseType, baseInterfaces)
 {
     Syntax = syntax;
     Binder = binder;
 }
Esempio n. 24
0
        private void BindBaseList(BaseListSyntax baseList, Symbol parent, out ClassOrStructSymbol baseType, out List<InterfaceSymbol> baseInterfaces)
        {
            baseType = null;
            baseInterfaces = new List<InterfaceSymbol>();

            if (baseList != null)
            {
                var baseTypeTemp = Bind(baseList.BaseType, x => BindType(x, parent));
                switch (baseTypeTemp.TypeSymbol.Kind)
                {
                    case SymbolKind.Class:
                    case SymbolKind.Struct:
                        baseType = (ClassOrStructSymbol) baseTypeTemp.TypeSymbol;
                        break;
                    case SymbolKind.Interface:
                        baseInterfaces.Add((InterfaceSymbol) baseTypeTemp.TypeSymbol);
                        break;
                }
            }
        }
Esempio n. 25
0
 internal VariableSymbol(SymbolKind kind, string name, string documentation, Symbol parent, TypeSymbol valueType)
     : base(kind, name, documentation, parent)
 {
     ValueType = valueType;
 }
Esempio n. 26
0
        private BoundStructType BindStructDeclaration(StructTypeSyntax declaration, Symbol parent)
        {
            ClassOrStructSymbol baseType;
            List<InterfaceSymbol> baseInterfaces;
            BindBaseList(declaration.BaseList, parent, out baseType, out baseInterfaces);

            var structSymbol = new StructSymbol(declaration, parent, baseType, baseInterfaces.ToImmutableArray());
            AddSymbol(structSymbol, declaration.Name?.Span ?? declaration.GetTextSpanSafe());

            var variables = new List<BoundMultipleVariableDeclarations>();
            var structBinder = new Binder(_sharedBinderState, this);
            foreach (var variableDeclarationStatement in declaration.Fields)
                variables.Add(structBinder.Bind(variableDeclarationStatement, x => structBinder.BindField(x, structSymbol)));

            foreach (var member in structBinder.LocalSymbols.Values.SelectMany(x => x))
                structSymbol.AddMember(member);

            return new BoundStructType(structSymbol, variables.ToImmutableArray());
        }
Esempio n. 27
0
 internal VariableSymbol(VariableDeclaratorSyntax syntax, Symbol parent, TypeSymbol valueType)
     : base(SymbolKind.Variable, syntax.Identifier.Text, string.Empty, parent)
 {
     ValueType = valueType;
 }
Esempio n. 28
0
 private BoundTypeDeclaration BindTypeDeclaration(TypeDeclarationStatementSyntax declaration, Symbol parent)
 {
     return new BoundTypeDeclaration(Bind(declaration.Type, x => BindTypeDefinition(x, parent)));
 }
Esempio n. 29
0
 internal InterfaceSymbol(InterfaceTypeSyntax syntax, Symbol parent)
     : base(SymbolKind.Interface, syntax.Name.Text, string.Empty, parent)
 {
 }
Esempio n. 30
0
 public BoundName(Symbol symbol)
     : base(BoundNodeKind.Name, symbol as TypeSymbol ?? TypeFacts.Missing)
 {
     Symbol = symbol;
 }
Esempio n. 31
0
 internal SourceFunctionSymbol(FunctionDeclarationSyntax syntax, Symbol parent, TypeSymbol returnType, Func<InvocableSymbol, IEnumerable<ParameterSymbol>> lazyParameters = null)
     : base(syntax.Name.GetName(), string.Empty, parent, returnType, lazyParameters)
 {
     DeclarationSyntaxes = new List<FunctionDeclarationSyntax> { syntax };
 }