コード例 #1
0
ファイル: SymbolSet.cs プロジェクト: pminiszewski/HlslTools
        public TypeSymbol ResolveIntrinsicType(PredefinedTypeSyntax type, ISymbolTable symbolTable, Symbol contextSymbol)
        {
            switch (type.Kind)
            {
                case SyntaxKind.PredefinedScalarType:
                    return ResolveIntrinsicScalarType((ScalarTypeSyntax) type);

                case SyntaxKind.PredefinedVectorType:
                    return ResolveIntrinsicVectorType((VectorTypeSyntax)type);

                case SyntaxKind.PredefinedGenericVectorType:
                    return ResolveIntrinsicGenericVectorType((GenericVectorTypeSyntax)type);

                case SyntaxKind.PredefinedMatrixType:
                    return ResolveIntrinsicMatrixType((MatrixTypeSyntax)type);

                case SyntaxKind.PredefinedGenericMatrixType:
                    return ResolveIntrinsicGenericMatrixType((GenericMatrixTypeSyntax)type);

                case SyntaxKind.PredefinedObjectType:
                    return ResolveIntrinsicObjectType((PredefinedObjectTypeSyntax) type, symbolTable, contextSymbol);

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), "Unmapped intrinsic type");
            }
        }
コード例 #2
0
ファイル: Symbol.cs プロジェクト: Samana/HlslTools
 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));
 }
コード例 #3
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
 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);
     }
 }
コード例 #4
0
ファイル: Symbol.cs プロジェクト: Samana/HlslTools
 internal Symbol(SymbolKind kind, string name, string documentation, Symbol parent)
 {
     Kind = kind;
     Name = name;
     Documentation = documentation;
     Parent = parent;
 }
コード例 #5
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
        private BoundStatement BindDoStatement(DoStatementSyntax syntax, Symbol parent)
        {
            BindAttributes(syntax.Attributes);

            return new BoundDoStatement(
                Bind(syntax.Condition, BindExpression),
                Bind(syntax.Statement, x => BindStatement(x, parent)));
        }
コード例 #6
0
ファイル: ParameterSymbol.cs プロジェクト: Samana/HlslTools
        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;
        }
コード例 #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;
 }
コード例 #8
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
        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);
        }
コード例 #9
0
ファイル: InvocableSymbol.cs プロジェクト: Samana/HlslTools
        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;
        }
コード例 #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;
        }
コード例 #11
0
ファイル: SymbolScope.cs プロジェクト: pminiszewski/HlslTools
        Symbol ISymbolTable.FindSymbol(string name, Symbol context)
        {
            Symbol symbol = null;

            if (_localTable.ContainsKey(name))
            {
                symbol = _localTable[name];
            }

            if (symbol == null)
            {
                Debug.Assert(_parentSymbolTable != null);
                symbol = _parentSymbolTable.FindSymbol(name, context);
            }

            return symbol;
        }
コード例 #12
0
ファイル: Binder.Types.cs プロジェクト: Samana/HlslTools
        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());
            }
        }
コード例 #13
0
ファイル: TypeSymbol.cs プロジェクト: pminiszewski/HlslTools
        Symbol ISymbolTable.FindSymbol(string name, Symbol context)
        {
            Debug.Assert(string.IsNullOrEmpty(name) == false);
            Debug.Assert(context != null);

            Symbol symbol = GetMember(name);

            if (symbol == null)
            {
                var baseType = GetBaseType();
                if (baseType != null)
                    symbol = ((ISymbolTable)baseType).FindSymbol(name, context);
            }

            if (symbol == null && _parentSymbolTable != null)
                symbol = _parentSymbolTable.FindSymbol(name, context);

            return symbol;
        }
コード例 #14
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.EmptyStatement:
             return BindEmptyStatement((EmptyStatementSyntax) declaration);
         default:
             throw new ArgumentOutOfRangeException(declaration.Kind.ToString());
     }
 }
コード例 #15
0
 internal StructSymbol(StructTypeSyntax syntax, Symbol parent, Func<TypeSymbol, IEnumerable<FieldSymbol>> lazyFields)
     : base(SymbolKind.Struct, syntax.Name.Text, string.Empty, parent, lazyFields)
 {
 }
コード例 #16
0
 public CompletionItem(string displayText, string insertionText, string description, Glyph? glyph, Symbol symbol)
     : this(displayText, insertionText, description, glyph, symbol, false)
 {
 }
コード例 #17
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
        private BoundIfStatement BindIfStatement(IfStatementSyntax syntax, Symbol parent)
        {
            BindAttributes(syntax.Attributes);

            return new BoundIfStatement(
                Bind(syntax.Condition, BindExpression),
                Bind(syntax.Statement, x => BindStatement(x, parent)),
                syntax.Else != null ? Bind(syntax.Else.Statement, x => BindStatement(x, parent)) : null);
        }
コード例 #18
0
ファイル: SymbolSet.cs プロジェクト: pminiszewski/HlslTools
 Symbol ISymbolTable.FindSymbol(string name, Symbol context)
 {
     Symbol symbol;
     _globalMap.TryGetValue(name, out symbol);
     return symbol;
 }
コード例 #19
0
ファイル: SymbolSet.cs プロジェクト: pminiszewski/HlslTools
 public void AddGlobal(Symbol symbol)
 {
     _globals.Add(symbol);
     _globalMap.Add(symbol.Name, symbol);
 }
コード例 #20
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
 private BoundSwitchSection BindSwitchSection(SwitchSectionSyntax syntax, Symbol parent)
 {
     return new BoundSwitchSection(
         syntax.Labels.Select(x => Bind(x, BindSwitchLabel)).ToImmutableArray(),
         syntax.Statements.Select(x => Bind(x, y => BindStatement(y, parent))).ToImmutableArray());
 }
コード例 #21
0
ファイル: SymbolSet.cs プロジェクト: pminiszewski/HlslTools
 private TypeSymbol ResolveIntrinsicObjectType(PredefinedObjectTypeSyntax type, ISymbolTable symbolTable, Symbol contextSymbol)
 {
     var predefinedObjectType = SyntaxFacts.GetPredefinedObjectType(type.ObjectTypeToken.Kind);
     switch (predefinedObjectType)
     {
         case PredefinedObjectType.Buffer:
         case PredefinedObjectType.Texture1D:
         case PredefinedObjectType.Texture1DArray:
         case PredefinedObjectType.Texture2D:
         case PredefinedObjectType.Texture2DArray:
         case PredefinedObjectType.Texture3D:
         case PredefinedObjectType.TextureCube:
         case PredefinedObjectType.TextureCubeArray:
         case PredefinedObjectType.Texture2DMS:
         case PredefinedObjectType.Texture2DMSArray:
         {
             TypeSymbol valueType;
             ScalarType scalarType;
             if (type.TemplateArgumentList != null)
             {
                 var valueTypeSyntax = type.TemplateArgumentList.Arguments[0];
                 valueType = ResolveIntrinsicType((PredefinedTypeSyntax) valueTypeSyntax, symbolTable, contextSymbol);
                 switch (valueTypeSyntax.Kind)
                 {
                     case SyntaxKind.PredefinedScalarType:
                         scalarType = SyntaxFacts.GetScalarType(((ScalarTypeSyntax) valueTypeSyntax).TypeTokens.Select(x => x.Kind).ToArray());
                         break;
                     case SyntaxKind.PredefinedVectorType:
                         scalarType = SyntaxFacts.GetVectorType(((VectorTypeSyntax) valueTypeSyntax).TypeToken.Kind).Item1;
                         break;
                     case SyntaxKind.PredefinedGenericVectorType:
                         scalarType = SyntaxFacts.GetScalarType(((GenericVectorTypeSyntax) valueTypeSyntax).ScalarType.TypeTokens.Select(x => x.Kind).ToArray());
                         break;
                     default:
                         throw new ArgumentOutOfRangeException();
                 }
             }
             else
             {
                 valueType = IntrinsicTypes.Float4;
                 scalarType = ScalarType.Float;
             }
             return IntrinsicTypes.CreateTextureType(predefinedObjectType, valueType, scalarType);
         }
         case PredefinedObjectType.RWBuffer:
         case PredefinedObjectType.RWTexture1D:
         case PredefinedObjectType.RWTexture1DArray:
         case PredefinedObjectType.RWTexture2D:
         case PredefinedObjectType.RWTexture2DArray:
         case PredefinedObjectType.RWTexture3D:
             throw new NotImplementedException();
         case PredefinedObjectType.AppendStructuredBuffer:
         case PredefinedObjectType.ConsumeStructuredBuffer:
         case PredefinedObjectType.StructuredBuffer:
         {
             var valueTypeSyntax = (TypeSyntax) type.TemplateArgumentList.Arguments[0];
             var valueType = ResolveType(valueTypeSyntax, symbolTable, contextSymbol);
             switch (predefinedObjectType)
             {
                 case PredefinedObjectType.AppendStructuredBuffer:
                     return IntrinsicTypes.CreateAppendStructuredBufferType(valueType);
                 case PredefinedObjectType.ConsumeStructuredBuffer:
                     return IntrinsicTypes.CreateConsumeStructuredBufferType(valueType);
                 case PredefinedObjectType.StructuredBuffer:
                     return IntrinsicTypes.CreateStructuredBufferType(valueType);
                 default:
                     throw new ArgumentOutOfRangeException();
             }
         }
         case PredefinedObjectType.ByteAddressBuffer:
             return IntrinsicTypes.CreateByteAddressBufferType();
         case PredefinedObjectType.RWByteAddressBuffer:
         case PredefinedObjectType.RWStructuredBuffer:
         case PredefinedObjectType.InputPatch:
         case PredefinedObjectType.OutputPatch:
         case PredefinedObjectType.PointStream:
         case PredefinedObjectType.LineStream:
         case PredefinedObjectType.TriangleStream:
             throw new NotImplementedException();
         case PredefinedObjectType.Sampler:
         case PredefinedObjectType.SamplerState:
             return IntrinsicTypes.SamplerState;
         case PredefinedObjectType.SamplerComparisonState:
             return IntrinsicTypes.SamplerComparisonState;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
コード例 #22
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 };
 }
コード例 #23
0
 public SourceParameterSymbol(ParameterSyntax syntax, Symbol parent, TypeSymbol valueType, ParameterDirection direction = ParameterDirection.In)
     : base(syntax.Declarator.Identifier.Text, string.Empty, parent, valueType, direction)
 {
     Syntax = syntax;
 }
コード例 #24
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
 private BoundMultipleVariableDeclarations BindVariableDeclarationStatement(VariableDeclarationStatementSyntax syntax, Symbol parent)
 {
     BindAttributes(syntax.Attributes);
     return BindVariableDeclaration(syntax.Declaration, parent);
 }
コード例 #25
0
 internal ConstantBufferSymbol(ConstantBufferSyntax syntax, Symbol parent)
     : base(SymbolKind.ConstantBuffer, syntax.Name.Text, string.Empty, parent)
 {
     Syntax = syntax;
 }
コード例 #26
0
ファイル: Binder.Statements.cs プロジェクト: Samana/HlslTools
 private BoundStatement BindWhileStatement(WhileStatementSyntax syntax, Symbol parent)
 {
     return new BoundWhileStatement(
         Bind(syntax.Condition, BindExpression),
         Bind(syntax.Statement, x => BindStatement(x, parent)));
 }
コード例 #27
0
 public static void ReportSymbolRedefined(this ICollection<Diagnostic> diagnostics, TextSpan span, Symbol symbol)
 {
     diagnostics.Report(span, DiagnosticId.SymbolRedefined, symbol.Name);
 }
コード例 #28
0
ファイル: SymbolSet.cs プロジェクト: pminiszewski/HlslTools
        public TypeSymbol ResolveType(TypeSyntax node, ISymbolTable symbolTable, Symbol contextSymbol)
        {
            if (node is PredefinedTypeSyntax)
            {
                return ResolveIntrinsicType((PredefinedTypeSyntax) node, symbolTable, contextSymbol);
            }
            //else if (node is ArrayTypeNode)
            //{
            //    ArrayTypeNode arrayTypeNode = (ArrayTypeNode)node;

            //    TypeSymbol itemTypeSymbol = ResolveType(arrayTypeNode.BaseType, symbolTable, contextSymbol);
            //    Debug.Assert(itemTypeSymbol != null);

            //    return CreateArrayTypeSymbol(itemTypeSymbol);
            //}
            else
            {
                Debug.Assert(node is IdentifierNameSyntax);
                var nameNode = (IdentifierNameSyntax) node;

                return (TypeSymbol)symbolTable.FindSymbol(nameNode.Name.Text, contextSymbol);
            }
        }
コード例 #29
0
ファイル: ClassSymbol.cs プロジェクト: pminiszewski/HlslTools
 public ClassSymbol(ClassTypeSyntax syntax, Symbol parent, Func<TypeSymbol, IEnumerable<MemberSymbol>> lazyMembers)
     : base(SymbolKind.Class, syntax.Name.Text, string.Empty, parent, lazyMembers)
 {
 }
コード例 #30
0
 public void AddSymbol(SyntaxNode syntaxNode, Symbol symbol)
 {
     _symbolFromSyntaxNode[syntaxNode] = symbol;
 }