示例#1
0
        // Namespace
        public NamespaceSymbol CreateNamespace(Name name, NamespaceSymbol parent)
        {
            NamespaceSymbol sym = newBasicSym(SYMKIND.SK_NamespaceSymbol, name, parent).AsNamespaceSymbol();
            sym.SetAccess(ACCESS.ACC_PUBLIC);

            return (sym);
        }
示例#2
0
 public CMethodIterator(CSemanticChecker checker, SymbolLoader symLoader, Name name, TypeArray containingTypes, CType @object, CType qualifyingType, Declaration context, bool allowBogusAndInaccessible, bool allowExtensionMethods, int arity, EXPRFLAG flags, symbmask_t mask)
 {
     Debug.Assert(name != null);
     Debug.Assert(symLoader != null);
     Debug.Assert(checker != null);
     Debug.Assert(containingTypes != null);
     _pSemanticChecker = checker;
     _pSymbolLoader = symLoader;
     _pCurrentType = null;
     _pCurrentSym = null;
     _pName = name;
     _pContainingTypes = containingTypes;
     _pQualifyingType = qualifyingType;
     _pContext = context;
     _bAllowBogusAndInaccessible = allowBogusAndInaccessible;
     _bAllowExtensionMethods = allowExtensionMethods;
     _nArity = arity;
     _flags = flags;
     _mask = mask;
     _nCurrentTypeCount = 0;
     _bIsCheckingInstanceMethods = true;
     _bAtEnd = false;
     _bCurrentSymIsBogus = false;
     _bCurrentSymIsInaccessible = false;
     _bcanIncludeExtensionsInResults = _bAllowExtensionMethods;
     _bEndIterationAtCurrentExtensionList = false;
 }
示例#3
0
        /////////////////////////////////////////////////////////////////////////////////
        public AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent, InputFile infile, TypeManager typeManager)
        {
            if (name == null || parent == null || infile == null || typeManager == null)
            {
                throw Error.InternalCompilerError();
            }

            AggregateSymbol sym = null;
            if (infile.GetAssemblyID() == KAID.kaidUnresolved)
            {
                // Unresolved aggs need extra storage.
                sym = CreateUnresolvedAggregate(name, parent, typeManager);
            }
            else
            {
                sym = newBasicSym(SYMKIND.SK_AggregateSymbol, name, parent).AsAggregateSymbol();
                sym.name = name;
                sym.SetTypeManager(typeManager);
                sym.SetSealed(false);
                sym.SetAccess(ACCESS.ACC_UNKNOWN);
                sym.initBogus();
                sym.SetIfaces(null);
                sym.SetIfacesAll(null);
                sym.SetTypeVars(null);
            }

            sym.InitFromInfile(infile);
            return sym;
        }
示例#4
0
        public AssemblyQualifiedNamespaceSymbol CreateNamespaceAid(Name name, ParentSymbol parent, KAID assemblyID)
        {
            Debug.Assert(name != null);

            AssemblyQualifiedNamespaceSymbol sym = newBasicSym(SYMKIND.SK_AssemblyQualifiedNamespaceSymbol, name, parent).AsAssemblyQualifiedNamespaceSymbol();

            Debug.Assert(sym != null);
            return sym;
        }
示例#5
0
        public IndexerSymbol CreateIndexer(Name name, ParentSymbol parent, Name realName, AggregateDeclaration declaration)
        {
            IndexerSymbol sym = (IndexerSymbol)newBasicSym(SYMKIND.SK_IndexerSymbol, name, parent);
            sym.setKind(SYMKIND.SK_PropertySymbol);
            sym.isOperator = true;
            sym.declaration = declaration;

            Debug.Assert(sym != null);
            return sym;
        }
示例#6
0
 public CMemberLookupResults(
         TypeArray containingTypes,
         Name name)
 {
     _pName = name;
     ContainingTypes = containingTypes;
     if (ContainingTypes == null)
     {
         ContainingTypes = BSYMMGR.EmptyTypeArray();
     }
 }
示例#7
0
        public Symbol LookupSym(Name name, ParentSymbol parent, symbmask_t kindmask)
        {
            Key k = new Key(name, parent);
            Symbol sym;

            if (_dictionary.TryGetValue(k, out sym))
            {
                return FindCorrectKind(sym, kindmask);
            }

            return null;
        }
示例#8
0
        // Aggregate
        public AggregateType CreateAggregateType(
            Name name,
            AggregateSymbol parent,
            TypeArray typeArgsThis,
            AggregateType outerType)
        {
            AggregateType type = new AggregateType();

            type.outerType = outerType;
            type.SetOwningAggregate(parent);
            type.SetTypeArgsThis(typeArgsThis);
            type.SetName(name);

            type.SetTypeKind(TypeKind.TK_AggregateType);
            return type;
        }
示例#9
0
        public AggregateSymbol CreateUnresolvedAggregate(Name name, ParentSymbol parent, TypeManager typeManager)
        {
            Debug.Assert(name != null);

            Symbol sym = newBasicSym(SYMKIND.SK_UnresolvedAggregateSymbol, name, parent);
            AggregateSymbol AggregateSymbol = null;

            // Unresolved Aggs need extra storage, but are still considered Aggs.

            sym.setKind(SYMKIND.SK_AggregateSymbol);
            AggregateSymbol = sym.AsAggregateSymbol();
            AggregateSymbol.SetTypeManager(typeManager);

            Debug.Assert(AggregateSymbol != null);
            return (AggregateSymbol);
        }
示例#10
0
            /////////////////////////////////////////////////////////////////////////////////

            private static EXPR FindArgumentWithName(ArgInfos pArguments, Name pName)
            {
                for (int i = 0; i < pArguments.carg; i++)
                {
                    if (pArguments.prgexpr[i].isNamedArgumentSpecification() &&
                            pArguments.prgexpr[i].asNamedArgumentSpecification().Name == pName)
                    {
                        return pArguments.prgexpr[i];
                    }
                }
                return null;
            }
示例#11
0
            /////////////////////////////////////////////////////////////////////////////////

            private bool NamedArgumentNamesAppearInParameterList(
                    MethodOrPropertySymbol methprop)
            {
                // Keep track of the current position in the parameter list so that we can check
                // containment from this point onwards as well as complete containment. This is 
                // for error reporting. The user cannot specify a named argument for a parameter
                // that has a fixed argument value.
                List<Name> currentPosition = methprop.ParameterNames;
                HashSet<Name> names = new HashSet<Name>();
                for (int i = 0; i < _pArguments.carg; i++)
                {
                    if (!_pArguments.prgexpr[i].isNamedArgumentSpecification())
                    {
                        if (!currentPosition.IsEmpty())
                        {
                            currentPosition = currentPosition.Tail();
                        }
                        continue;
                    }

                    Name name = _pArguments.prgexpr[i].asNamedArgumentSpecification().Name;
                    if (!methprop.ParameterNames.Contains(name))
                    {
                        if (_pInvalidSpecifiedName == null)
                        {
                            _pInvalidSpecifiedName = name;
                        }
                        return false;
                    }
                    else if (!currentPosition.Contains(name))
                    {
                        if (_pNameUsedInPositionalArgument == null)
                        {
                            _pNameUsedInPositionalArgument = name;
                        }
                        return false;
                    }
                    if (names.Contains(name))
                    {
                        if (_pDuplicateSpecifiedName == null)
                        {
                            _pDuplicateSpecifiedName = name;
                        }
                        return false;
                    }
                    names.Add(name);
                }
                return true;
            }
示例#12
0
        public TypeParameterSymbol CreateClassTypeParameter(Name pName, AggregateSymbol pParent, int index, int indexTotal)
        {
            TypeParameterSymbol pResult = newBasicSym(SYMKIND.SK_TypeParameterSymbol, pName, pParent).AsTypeParameterSymbol();
            pResult.SetIndexInOwnParameters(index);
            pResult.SetIndexInTotalParameters(indexTotal);

            pResult.SetIsMethodTypeParameter(false);
            pResult.SetAccess(ACCESS.ACC_PRIVATE); // Always private - not accessible anywhere except their own type.

            return pResult;
        }
示例#13
0
        public EventSymbol CreateEvent(Name name, ParentSymbol parent, AggregateDeclaration declaration)
        {
            EventSymbol sym = newBasicSym(SYMKIND.SK_EventSymbol, name, parent).AsEventSymbol();
            sym.declaration = declaration;

            Debug.Assert(sym != null);
            return (sym);
        }
示例#14
0
        // Derived types - parent is base type
        public ArrayType CreateArray(Name name, CType pElementType, int rank)
        {
            ArrayType type = new ArrayType();

            type.SetName(name);
            type.rank = rank;
            type.SetElementType(pElementType);

            type.SetTypeKind(TypeKind.TK_ArrayType);
            return type;
        }
示例#15
0
        private AggregateSymbol FindPredefinedTypeCore(Name name, NamespaceOrAggregateSymbol bag, KAID aid, AggKindEnum aggKind, int arity,
                out AggregateSymbol paggAmbig, out AggregateSymbol paggBad)
        {
            AggregateSymbol aggFound = null;
            paggAmbig = null;
            paggBad = null;

            for (AggregateSymbol aggCur = _pBSymmgr.LookupGlobalSymCore(name, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol();
                 aggCur != null;
                 aggCur = BSYMMGR.LookupNextSym(aggCur, bag, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol())
            {
                if (!aggCur.InAlias(aid) || aggCur.GetTypeVarsAll().size != arity)
                {
                    continue;
                }
                if (aggCur.AggKind() != aggKind)
                {
                    if (paggBad == null)
                    {
                        paggBad = aggCur;
                    }
                    continue;
                }
                if (aggFound != null)
                {
                    Debug.Assert(paggAmbig == null);
                    paggAmbig = aggCur;
                    break;
                }
                aggFound = aggCur;
                if (paggAmbig == null)
                {
                    break;
                }
            }

            return aggFound;
        }
示例#16
0
        /////////////////////////////////////////////////////////////////////////////////

        internal void AddPredefinedPropertyToSymbolTable(AggregateSymbol type, Name property)
        {
            AggregateType aggtype = type.getThisType();
            Type t = aggtype.AssociatedSystemType;

            var props = Enumerable.Where(t.GetRuntimeProperties(), x => x.Name == property.Text);

            foreach (PropertyInfo pi in props)
            {
                AddPropertyToSymbolTable(pi, type);
            }
        }
示例#17
0
        private MethodSymbol LoadMethod(
                        AggregateSymbol type,
                        int[] signature,
                        int cMethodTyVars,
                        Name methodName,
                        ACCESS methodAccess,
                        bool isStatic,
                        bool isVirtual
                        )
        {
            Debug.Assert(signature != null);
            Debug.Assert(cMethodTyVars >= 0);
            Debug.Assert(methodName != null);

            if (type == null)
            {
                return null;
            }
            TypeArray classTyVars = type.GetTypeVarsAll();

            int index = 0;
            CType returnType = LoadTypeFromSignature(signature, ref index, classTyVars);
            if (returnType == null)
            {
                return null;
            }
            TypeArray argumentTypes = LoadTypeArrayFromSignature(signature, ref index, classTyVars);
            if (argumentTypes == null)
            {
                return null;
            }
            TypeArray standardMethodTyVars = GetTypeManager().GetStdMethTyVarArray(cMethodTyVars);

            MethodSymbol ret = LookupMethodWhileLoading(type, cMethodTyVars, methodName, methodAccess, isStatic, isVirtual, returnType, argumentTypes);

            if (ret == null)
            {
                RuntimeBinderSymbolTable.AddPredefinedMethodToSymbolTable(type, methodName);
                ret = LookupMethodWhileLoading(type, cMethodTyVars, methodName, methodAccess, isStatic, isVirtual, returnType, argumentTypes);
            }
            return ret;
        }
示例#18
0
        private readonly Name _pName; // The name that we're looking for.

        public CMemberLookupResults()
        {
            _pName = null;
            ContainingTypes = null;
        }
示例#19
0
        public NullableType CreateNullable(Name name, CType pUnderlyingType, BSYMMGR symmgr, TypeManager typeManager)
        {
            NullableType type = new NullableType();
            type.SetName(name);
            type.SetUnderlyingType(pUnderlyingType);
            type.symmgr = symmgr;
            type.typeManager = typeManager;

            type.SetTypeKind(TypeKind.TK_NullableType);
            return type;
        }
示例#20
0
        public ParameterModifierType CreateParameterModifier(Name name, CType pParameterType)
        {
            ParameterModifierType type = new ParameterModifierType();
            type.SetName(name);
            type.SetParameterType(pParameterType);

            type.SetTypeKind(TypeKind.TK_ParameterModifierType);
            return type;
        }
示例#21
0
        public PointerType CreatePointer(Name name, CType pReferentType)
        {
            PointerType type = new PointerType();
            type.SetName(name);
            type.SetReferentType(pReferentType);

            type.SetTypeKind(TypeKind.TK_PointerType);
            return type;
        }
示例#22
0
        public ErrorType GetErrorType(
                CType pParentType,
                AssemblyQualifiedNamespaceSymbol pParentNS,
                Name nameText,
                TypeArray typeArgs)
        {
            Debug.Assert(nameText != null);
            Debug.Assert(pParentType == null || pParentNS == null);
            if (pParentType == null && pParentNS == null)
            {
                // Use the root namespace as the parent.
                pParentNS = _BSymmgr.GetRootNsAid(KAID.kaidGlobal);
            }
            if (typeArgs == null)
            {
                typeArgs = BSYMMGR.EmptyTypeArray();
            }

            Name name = _BSymmgr.GetNameFromPtrs(nameText, typeArgs);
            Debug.Assert(name != null);

            ErrorType pError = null;
            if (pParentType != null)
            {
                pError = _typeTable.LookupError(name, pParentType);
            }
            else
            {
                Debug.Assert(pParentNS != null);
                pError = _typeTable.LookupError(name, pParentNS);
            }

            if (pError == null)
            {
                // No existing error symbol. Create a new one.
                pError = _typeFactory.CreateError(name, pParentType, pParentNS, nameText, typeArgs);
                pError.SetErrors(true);
                if (pParentType != null)
                {
                    _typeTable.InsertError(name, pParentType, pError);
                }
                else
                {
                    _typeTable.InsertError(name, pParentNS, pError);
                }
            }
            else
            {
                Debug.Assert(pError.HasErrors());
                Debug.Assert(pError.nameText == nameText);
                Debug.Assert(pError.typeArgs == typeArgs);
            }
            Debug.Assert(!pError.IsUnresolved());

            return pError;
        }
示例#23
0
文件: Type.cs 项目: dotnet/corefx
 public void SetName(Name pName) { _pName = pName; }
示例#24
0
        public MethodSymbol CreateMethod(Name name, ParentSymbol parent, AggregateDeclaration declaration)
        {
            MethodSymbol sym = newBasicSym(SYMKIND.SK_MethodSymbol, name, parent).AsMethodSymbol();
            sym.declaration = declaration;

            return sym;
        }
示例#25
0
        private PropertySymbol LoadProperty(
            PREDEFPROP predefProp,
            Name propertyName,
            PREDEFMETH propertyGetter,
            PREDEFMETH propertySetter)
        {
            Debug.Assert(propertyName != null);
            Debug.Assert(propertyGetter > PREDEFMETH.PM_FIRST && propertyGetter < PREDEFMETH.PM_COUNT);
            Debug.Assert(propertySetter > PREDEFMETH.PM_FIRST && propertySetter <= PREDEFMETH.PM_COUNT);

            MethodSymbol getter = GetOptionalMethod(propertyGetter);
            MethodSymbol setter = null;
            if (propertySetter != PREDEFMETH.PM_COUNT)
            {
                setter = GetOptionalMethod(propertySetter);
            }

            if (getter == null && setter == null)
            {
                RuntimeBinderSymbolTable.AddPredefinedPropertyToSymbolTable(GetOptPredefAgg(GetPropPredefType(predefProp)), propertyName);
                getter = GetOptionalMethod(propertyGetter);
                if (propertySetter != PREDEFMETH.PM_COUNT)
                {
                    setter = GetOptionalMethod(propertySetter);
                }
            }

            if (setter != null)
            {
                setter.SetMethKind(MethodKindEnum.PropAccessor);
            }

            PropertySymbol property = null;
            if (getter != null)
            {
                getter.SetMethKind(MethodKindEnum.PropAccessor);
                property = getter.getProperty();

                // Didn't find it, so load it.
                if (property == null)
                {
                    RuntimeBinderSymbolTable.AddPredefinedPropertyToSymbolTable(GetOptPredefAgg(GetPropPredefType(predefProp)), propertyName);
                }
                property = getter.getProperty();
                Debug.Assert(property != null);

                if (property.name != propertyName ||
                    (propertySetter != PREDEFMETH.PM_COUNT &&
                        (setter == null ||
                         !setter.isPropertyAccessor() ||
                         setter.getProperty() != property)) ||
                    property.getBogus())
                {
                    property = null;
                }
            }

            return property;
        }
示例#26
0
        public ErrorType CreateError(
            Name name,
            CType parent,
            AssemblyQualifiedNamespaceSymbol pParentNS,
            Name nameText,
            TypeArray typeArgs)
        {
            ErrorType e = new ErrorType();
            e.SetName(name);
            e.nameText = nameText;
            e.typeArgs = typeArgs;
            e.SetTypeParent(parent);
            e.SetNSParent(pParentNS);

            e.SetTypeKind(TypeKind.TK_ErrorType);
            return e;
        }
示例#27
0
 private MethodSymbol LookupMethodWhileLoading(AggregateSymbol type, int cMethodTyVars, Name methodName, ACCESS methodAccess, bool isStatic, bool isVirtual, CType returnType, TypeArray argumentTypes)
 {
     for (Symbol sym = GetSymbolLoader().LookupAggMember(methodName, type, symbmask_t.MASK_ALL);
          sym != null;
          sym = GetSymbolLoader().LookupNextSym(sym, type, symbmask_t.MASK_ALL))
     {
         if (sym.IsMethodSymbol())
         {
             MethodSymbol methsym = sym.AsMethodSymbol();
             if ((methsym.GetAccess() == methodAccess || methodAccess == ACCESS.ACC_UNKNOWN) &&
                 methsym.isStatic == isStatic &&
                 methsym.isVirtual == isVirtual &&
                 methsym.typeVars.size == cMethodTyVars &&
                 GetTypeManager().SubstEqualTypes(methsym.RetType, returnType, null, methsym.typeVars, SubstTypeFlags.DenormMeth) &&
                 GetTypeManager().SubstEqualTypeArrays(methsym.Params, argumentTypes, (TypeArray)null,
                     methsym.typeVars, SubstTypeFlags.DenormMeth) &&
                 !methsym.getBogus())
             {
                 return methsym;
             }
         }
     }
     return null;
 }
示例#28
0
        // Members of aggs
        public FieldSymbol CreateMemberVar(Name name, ParentSymbol parent, AggregateDeclaration declaration, int iIteratorLocal)
        {
            Debug.Assert(name != null);

            FieldSymbol sym = newBasicSym(SYMKIND.SK_FieldSymbol, name, parent).AsFieldSymbol();
            sym.declaration = declaration;

            Debug.Assert(sym != null);
            return (sym);
        }
示例#29
0
        /////////////////////////////////////////////////////////////////////////////////

        internal void AddPredefinedMethodToSymbolTable(AggregateSymbol type, Name methodName)
        {
            Type t = type.getThisType().AssociatedSystemType;

            // If we got here, it means we couldn't find it in our initial lookup. Means we haven't loaded it from reflection yet.
            // Lets go and do that now.
            // Check if we have constructors or not.
            if (methodName == _nameManager.GetPredefinedName(PredefinedName.PN_CTOR))
            {
                var ctors = Enumerable.Where(t.GetConstructors(), m => m.Name == methodName.Text);

                foreach (ConstructorInfo c in ctors)
                {
                    AddMethodToSymbolTable(
                        c,
                        type,
                        MethodKindEnum.Constructor);
                }
            }
            else
            {
                var methods = Enumerable.Where(t.GetRuntimeMethods(), m => m.Name == methodName.Text && m.DeclaringType == t);

                foreach (MethodInfo m in methods)
                {
                    AddMethodToSymbolTable(
                        m,
                        type,
                        m.Name == SpecialNames.Invoke ? MethodKindEnum.Invoke : MethodKindEnum.Actual);
                }
            }
        }
示例#30
0
        public LocalVariableSymbol CreateLocalVar(Name name, ParentSymbol parent, CType type)
        {
            LocalVariableSymbol sym = newBasicSym(SYMKIND.SK_LocalVariableSymbol, name, parent).AsLocalVariableSymbol();
            sym.SetType(type);
            sym.SetAccess(ACCESS.ACC_UNKNOWN);    // required for Symbol::hasExternalAccess which is used by refactoring
            sym.wrap = null;

            return sym;
        }