Ejemplo n.º 1
0
Archivo: Type.cs Proyecto: ksg97031/ql
        protected void PopulateType(TextWriter trapFile)
        {
            PopulateMetadataHandle(trapFile);
            PopulateAttributes();

            trapFile.Write("types(");
            trapFile.WriteColumn(this);
            trapFile.Write(',');
            trapFile.WriteColumn((int)GetClassType(Context, symbol));
            trapFile.Write(",\"");
            symbol.BuildDisplayName(Context, trapFile);
            trapFile.WriteLine("\")");

            // Visit base types
            var baseTypes = new List <Type>();

            if (symbol.BaseType != null)
            {
                Type baseKey = Create(Context, symbol.BaseType);
                trapFile.extend(this, baseKey.TypeRef);
                if (symbol.TypeKind != TypeKind.Struct)
                {
                    baseTypes.Add(baseKey);
                }
            }

            if (symbol.TypeKind == TypeKind.Interface)
            {
                trapFile.extend(this, Create(Context, Context.Compilation.ObjectType));
            }

            if (!(base.symbol is IArrayTypeSymbol))
            {
                foreach (var t in base.symbol.Interfaces.Select(i => Create(Context, i)))
                {
                    trapFile.implement(this, t.TypeRef);
                    baseTypes.Add(t);
                }
            }

            var containingType = ContainingType;

            if (containingType != null && symbol.Kind != SymbolKind.TypeParameter)
            {
                Type originalDefinition = symbol.TypeKind == TypeKind.Error ? this : Create(Context, symbol.OriginalDefinition);
                trapFile.nested_types(this, containingType, originalDefinition);
            }
            else if (symbol.ContainingNamespace != null)
            {
                trapFile.parent_namespace(this, Namespace.Create(Context, symbol.ContainingNamespace));
            }

            if (symbol is IArrayTypeSymbol)
            {
                // They are in the namespace of the original object
                ITypeSymbol      elementType = ((IArrayTypeSymbol)symbol).ElementType;
                INamespaceSymbol ns          = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
                if (ns != null)
                {
                    trapFile.parent_namespace(this, Namespace.Create(Context, ns));
                }
            }

            if (symbol is IPointerTypeSymbol)
            {
                ITypeSymbol      elementType = ((IPointerTypeSymbol)symbol).PointedAtType;
                INamespaceSymbol ns          = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;

                if (ns != null)
                {
                    trapFile.parent_namespace(this, Namespace.Create(Context, ns));
                }
            }

            if (symbol.BaseType != null && symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
            {
                // This is a delegate.
                // The method "Invoke" has the return type.
                var invokeMethod = ((INamedTypeSymbol)symbol).DelegateInvokeMethod;

                // Copy the parameters from the "Invoke" method to the delegate type
                for (var i = 0; i < invokeMethod.Parameters.Length; ++i)
                {
                    var param               = invokeMethod.Parameters[i];
                    var originalParam       = invokeMethod.OriginalDefinition.Parameters[i];
                    var originalParamEntity = SymbolEqualityComparer.Default.Equals(param, originalParam) ? null :
                                              DelegateTypeParameter.Create(Context, originalParam, Create(Context, ((INamedTypeSymbol)symbol).OriginalDefinition));
                    DelegateTypeParameter.Create(Context, param, this, originalParamEntity);
                }

                var returnKey = Create(Context, invokeMethod.ReturnType);
                trapFile.delegate_return_type(this, returnKey.TypeRef);
                if (invokeMethod.ReturnsByRef)
                {
                    trapFile.type_annotation(this, Kinds.TypeAnnotation.Ref);
                }
                if (invokeMethod.ReturnsByRefReadonly)
                {
                    trapFile.type_annotation(this, Kinds.TypeAnnotation.ReadonlyRef);
                }
            }

            Modifier.ExtractModifiers(Context, trapFile, this, symbol);

            if (IsSourceDeclaration && symbol.FromSource())
            {
                var declSyntaxReferences = symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).ToArray();

                var baseLists = declSyntaxReferences.OfType <ClassDeclarationSyntax>().Select(c => c.BaseList);
                baseLists = baseLists.Concat(declSyntaxReferences.OfType <InterfaceDeclarationSyntax>().Select(c => c.BaseList));
                baseLists = baseLists.Concat(declSyntaxReferences.OfType <StructDeclarationSyntax>().Select(c => c.BaseList));

                baseLists.
                Where(bl => bl != null).
                SelectMany(bl => bl.Types).
                Zip(baseTypes.Where(bt => bt.symbol.SpecialType != SpecialType.System_Object),
                    (s, t) => TypeMention.Create(Context, s.Type, this, t)).
                Enumerate();
            }
        }
Ejemplo n.º 2
0
 public void ExtractModifiers()
 {
     Modifier.ExtractModifiers(Context, this, symbol);
 }
Ejemplo n.º 3
0
Archivo: Symbol.cs Proyecto: jf205/ql
 public void PopulateModifiers(TextWriter trapFile)
 {
     Modifier.ExtractModifiers(Context, trapFile, this, symbol);
 }
Ejemplo n.º 4
0
        protected void PopulateType(TextWriter trapFile, bool constructUnderlyingTupleType = false)
        {
            PopulateMetadataHandle(trapFile);
            PopulateAttributes();

            trapFile.Write("types(");
            trapFile.WriteColumn(this);
            trapFile.Write(',');
            trapFile.WriteColumn((int)GetClassType(Context, symbol, constructUnderlyingTupleType));
            trapFile.Write(",\"");
            symbol.BuildDisplayName(Context, trapFile, constructUnderlyingTupleType);
            trapFile.WriteLine("\")");

            // Visit base types
            var baseTypes = new List <Type>();

            if (symbol.GetNonObjectBaseType(Context) is INamedTypeSymbol @base)
            {
                var baseKey = Create(Context, @base);
                trapFile.extend(this, baseKey.TypeRef);
                if (symbol.TypeKind != TypeKind.Struct)
                {
                    baseTypes.Add(baseKey);
                }
            }

            if (!(base.symbol is IArrayTypeSymbol))
            {
                foreach (var t in base.symbol.Interfaces.Select(i => Create(Context, i)))
                {
                    trapFile.implement(this, t.TypeRef);
                    baseTypes.Add(t);
                }
            }

            var containingType = ContainingType;

            if (containingType != null && symbol.Kind != SymbolKind.TypeParameter)
            {
                var originalDefinition = symbol.TypeKind == TypeKind.Error ? this : Create(Context, symbol.OriginalDefinition);
                trapFile.nested_types(this, containingType, originalDefinition);
            }
            else if (symbol.ContainingNamespace != null)
            {
                trapFile.parent_namespace(this, Namespace.Create(Context, symbol.ContainingNamespace));
            }

            if (symbol is IArrayTypeSymbol array)
            {
                // They are in the namespace of the original object
                var elementType = array.ElementType;
                var ns          = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;
                if (ns != null)
                {
                    trapFile.parent_namespace(this, Namespace.Create(Context, ns));
                }
            }

            if (symbol is IPointerTypeSymbol pointer)
            {
                var elementType = pointer.PointedAtType;
                var ns          = elementType.TypeKind == TypeKind.TypeParameter ? Context.Compilation.GlobalNamespace : elementType.ContainingNamespace;

                if (ns != null)
                {
                    trapFile.parent_namespace(this, Namespace.Create(Context, ns));
                }
            }

            if (symbol.BaseType != null && symbol.BaseType.SpecialType == SpecialType.System_MulticastDelegate)
            {
                // This is a delegate.
                // The method "Invoke" has the return type.
                var invokeMethod = ((INamedTypeSymbol)symbol).DelegateInvokeMethod;
                ExtractParametersForDelegateLikeType(trapFile, invokeMethod,
                                                     t => trapFile.delegate_return_type(this, t));
            }

            if (symbol is IFunctionPointerTypeSymbol functionPointer)
            {
                ExtractParametersForDelegateLikeType(trapFile, functionPointer.Signature,
                                                     t => trapFile.function_pointer_return_type(this, t));
            }

            Modifier.ExtractModifiers(Context, trapFile, this, symbol);

            if (IsSourceDeclaration && symbol.FromSource())
            {
                var declSyntaxReferences = symbol.DeclaringSyntaxReferences.Select(d => d.GetSyntax()).ToArray();

                var baseLists = declSyntaxReferences.OfType <ClassDeclarationSyntax>().Select(c => c.BaseList);
                baseLists = baseLists.Concat(declSyntaxReferences.OfType <InterfaceDeclarationSyntax>().Select(c => c.BaseList));
                baseLists = baseLists.Concat(declSyntaxReferences.OfType <StructDeclarationSyntax>().Select(c => c.BaseList));

                baseLists
                .Where(bl => bl != null)
                .SelectMany(bl => bl.Types)
                .Zip(
                    baseTypes.Where(bt => bt.symbol.SpecialType != SpecialType.System_Object),
                    (s, t) => TypeMention.Create(Context, s.Type, this, t))
                .Enumerate();
            }
        }