コード例 #1
0
ファイル: ClassSymbol.cs プロジェクト: Samana/HlslTools
 internal ClassSymbol(ClassTypeSyntax syntax, Symbol parent, ClassSymbol baseClass, ImmutableArray <InterfaceSymbol> baseInterfaces, Binder binder)
     : base(SymbolKind.Class, syntax.Name.Text, string.Empty, parent)
 {
     Syntax         = syntax;
     BaseClass      = baseClass;
     BaseInterfaces = baseInterfaces;
     Binder         = binder;
 }
コード例 #2
0
ファイル: ClassMethodBinder.cs プロジェクト: Samana/HlslTools
 public ClassMethodBinder(SharedBinderState sharedBinderState, Binder parent, ClassSymbol classSymbol)
     : base(sharedBinderState, parent)
 {
     _classSymbol = classSymbol;
 }
コード例 #3
0
ファイル: BoundClassType.cs プロジェクト: Samana/HlslTools
 public BoundClassType(ClassSymbol classSymbol, ImmutableArray<BoundNode> members)
     : base(BoundNodeKind.ClassType, classSymbol)
 {
     ClassSymbol = classSymbol;
     Members = members;
 }
コード例 #4
0
        private void BindClassDeclaration(ClassTypeSyntax declaration)
        {
            Func<TypeSymbol, IEnumerable<MemberSymbol>> lazyMemberSymbols = cd =>
            {
                var memberSymbols = new List<MemberSymbol>();
                foreach (var memberSyntax in declaration.Members)
                {
                    switch (memberSyntax.Kind)
                    {
                        case SyntaxKind.VariableDeclarationStatement:
                            memberSymbols.AddRange(BindFields((VariableDeclarationStatementSyntax)memberSyntax, cd));
                            break;
                        case SyntaxKind.FunctionDeclaration:
                            memberSymbols.Add(BindMethodDeclaration((FunctionDeclarationSyntax)memberSyntax, cd));
                            break;
                        case SyntaxKind.FunctionDefinition:
                            memberSymbols.Add(BindMethodDefinition((FunctionDefinitionSyntax)memberSyntax, cd));
                            break;
                    }
                }
                return memberSymbols;
            };

            var symbol = new ClassSymbol(declaration, null, lazyMemberSymbols);
            _bindingResult.AddSymbol(declaration, symbol);

            _symbolSet.AddGlobal(symbol);
        }
コード例 #5
0
        private BoundClassType BindClassDeclaration(ClassTypeSyntax declaration, Symbol parent)
        {
            ClassSymbol baseClass = null;
            var baseInterfaces = new List<InterfaceSymbol>();

            if (declaration.BaseList != null)
            {
                var baseType = Bind(declaration.BaseList.BaseType, x => BindType(x, parent));
                switch (baseType.TypeSymbol.Kind)
                {
                    case SymbolKind.Class:
                        baseClass = (ClassSymbol) baseType.TypeSymbol;
                        break;
                    case SymbolKind.Interface:
                        baseInterfaces.Add((InterfaceSymbol) baseType.TypeSymbol);
                        break;
                }
            }

            var classBinder = new Binder(_sharedBinderState, this);

            var classSymbol = new ClassSymbol(declaration, parent, baseClass, 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());
        }