Ejemplo n.º 1
0
 static public BindingContext CreateInstance(
     CSemanticChecker pSemanticChecker,
     ExprFactory exprFactory,
     OutputContext outputContext,
     NameGenerator nameGenerator,
     bool bflushLocalVariableTypesForEachStatement,
     bool bAllowUnsafeBlocks,
     bool bIsOptimizingSwitchAndArrayInit,
     bool bShowReachability,
     bool bWrapNonExceptionThrows,
     bool bInRefactoring,
     KAID aidLookupContext
     )
 {
     return(new BindingContext(
                pSemanticChecker,
                exprFactory,
                outputContext,
                nameGenerator,
                bflushLocalVariableTypesForEachStatement,
                bAllowUnsafeBlocks,
                bIsOptimizingSwitchAndArrayInit,
                bShowReachability,
                bWrapNonExceptionThrows,
                bInRefactoring,
                aidLookupContext));
 }
Ejemplo n.º 2
0
 static public BindingContext CreateInstance(
         CSemanticChecker pSemanticChecker,
         ExprFactory exprFactory,
         OutputContext outputContext,
         NameGenerator nameGenerator,
         bool bflushLocalVariableTypesForEachStatement,
         bool bAllowUnsafeBlocks,
         bool bIsOptimizingSwitchAndArrayInit,
         bool bShowReachability,
         bool bWrapNonExceptionThrows,
         bool bInRefactoring,
         KAID aidLookupContext
     )
 {
     return new BindingContext(
         pSemanticChecker,
         exprFactory,
         outputContext,
         nameGenerator,
         bflushLocalVariableTypesForEachStatement,
         bAllowUnsafeBlocks,
         bIsOptimizingSwitchAndArrayInit,
         bShowReachability,
         bWrapNonExceptionThrows,
         bInRefactoring,
         aidLookupContext);
 }
        public bool Init(ErrorHandling errorContext, SymbolTable symtable)
        {
            _runtimeBinderSymbolTable = symtable;
            Debug.Assert(_pBSymmgr != null);

#if !CSEE
            Debug.Assert(_predefSyms == null);
#else // CSEE
            Debug.Assert(predefSyms == null || aidMsCorLib != KAID.kaidNil);
#endif // CSEE

            if (_aidMsCorLib == KAID.kaidNil)
            {
                // If we haven't found mscorlib yet, first look for System.Object. Then use its assembly as
                // the location for all other pre-defined types.
                AggregateSymbol aggObj = FindPredefinedType(errorContext, PredefinedTypeFacts.GetName(PredefinedType.PT_OBJECT), KAID.kaidGlobal, AggKindEnum.Class, 0, true);
                if (aggObj == null)
                {
                    return(false);
                }
                _aidMsCorLib = aggObj.GetAssemblyID();
            }

            _predefSyms = new AggregateSymbol[(int)PredefinedType.PT_COUNT];
            Debug.Assert(_predefSyms != null);

            return(true);
        }
Ejemplo n.º 4
0
        protected BindingContext(
            CSemanticChecker pSemanticChecker,
            ExprFactory exprFactory,
            OutputContext outputContext,
            NameGenerator nameGenerator,
            bool bflushLocalVariableTypesForEachStatement,
            bool bAllowUnsafeBlocks,
            bool bIsOptimizingSwitchAndArrayInit,
            bool bShowReachability,
            bool bWrapNonExceptionThrows,
            bool bInRefactoring,
            KAID aidLookupContext
            )
        {
            m_ExprFactory = exprFactory;
            m_outputContext = outputContext;
            m_pNameGenerator = nameGenerator;
            m_pInputFile = null;
            m_pParentDecl = null;
            m_pContainingAgg = null;
            m_pCurrentSwitchType = null;
            m_pOriginalConstantField = null;
            m_pCurrentFieldSymbol = null;
            m_pImplicitlyTypedLocal = null;
            m_pOuterScope = null;
            m_pFinallyScope = null;
            m_pTryScope = null;
            m_pCatchScope = null;
            m_pCurrentScope = null;
            m_pSwitchScope = null;
            m_pCurrentBlock = null;
            m_UnsafeState = UNSAFESTATES.UNSAFESTATES_Unknown;
            m_FinallyNestingCount = 0;
            m_bInsideTryOfCatch = false;
            m_bInFieldInitializer = false;
            m_bInBaseConstructorCall = false;
            m_bAllowUnsafeBlocks = bAllowUnsafeBlocks;
            m_bIsOptimizingSwitchAndArrayInit = bIsOptimizingSwitchAndArrayInit;
            m_bShowReachability = bShowReachability;
            m_bWrapNonExceptionThrows = bWrapNonExceptionThrows;
            m_bInRefactoring = bInRefactoring;
            m_bInAttribute = false;
            m_bRespectSemanticsAndReportErrors = true;
            m_bflushLocalVariableTypesForEachStatement = bflushLocalVariableTypesForEachStatement;
            m_ppamis = null;
            m_pamiCurrent = null;
            m_pInitType = null;
            m_returnErrorSink = null;

            Debug.Assert(pSemanticChecker != null);
            this.SemanticChecker = pSemanticChecker;
            this.SymbolLoader = SemanticChecker.GetSymbolLoader();
            m_outputContext.m_pThisPointer = null;
            m_outputContext.m_pCurrentMethodSymbol = null;

            m_aidExternAliasLookupContext = aidLookupContext;
            CheckedNormal = false;
            CheckedConstant = false;
        }
Ejemplo n.º 5
0
        protected BindingContext(
            CSemanticChecker pSemanticChecker,
            ExprFactory exprFactory,
            OutputContext outputContext,
            NameGenerator nameGenerator,
            bool bflushLocalVariableTypesForEachStatement,
            bool bAllowUnsafeBlocks,
            bool bIsOptimizingSwitchAndArrayInit,
            bool bShowReachability,
            bool bWrapNonExceptionThrows,
            bool bInRefactoring,
            KAID aidLookupContext
            )
        {
            m_ExprFactory            = exprFactory;
            m_outputContext          = outputContext;
            m_pNameGenerator         = nameGenerator;
            m_pInputFile             = null;
            m_pParentDecl            = null;
            m_pContainingAgg         = null;
            m_pCurrentSwitchType     = null;
            m_pOriginalConstantField = null;
            m_pCurrentFieldSymbol    = null;
            m_pImplicitlyTypedLocal  = null;
            m_pOuterScope            = null;
            m_pFinallyScope          = null;
            m_pTryScope                                = null;
            m_pCatchScope                              = null;
            m_pCurrentScope                            = null;
            m_pSwitchScope                             = null;
            m_pCurrentBlock                            = null;
            m_UnsafeState                              = UNSAFESTATES.UNSAFESTATES_Unknown;
            m_FinallyNestingCount                      = 0;
            m_bInsideTryOfCatch                        = false;
            m_bInFieldInitializer                      = false;
            m_bInBaseConstructorCall                   = false;
            m_bAllowUnsafeBlocks                       = bAllowUnsafeBlocks;
            m_bIsOptimizingSwitchAndArrayInit          = bIsOptimizingSwitchAndArrayInit;
            m_bShowReachability                        = bShowReachability;
            m_bWrapNonExceptionThrows                  = bWrapNonExceptionThrows;
            m_bInRefactoring                           = bInRefactoring;
            m_bInAttribute                             = false;
            m_bRespectSemanticsAndReportErrors         = true;
            m_bflushLocalVariableTypesForEachStatement = bflushLocalVariableTypesForEachStatement;
            m_ppamis          = null;
            m_pamiCurrent     = null;
            m_pInitType       = null;
            m_returnErrorSink = null;

            Debug.Assert(pSemanticChecker != null);
            this.SemanticChecker                   = pSemanticChecker;
            this.SymbolLoader                      = SemanticChecker.GetSymbolLoader();
            m_outputContext.m_pThisPointer         = null;
            m_outputContext.m_pCurrentMethodSymbol = null;

            m_aidExternAliasLookupContext = aidLookupContext;
            CheckedNormal   = false;
            CheckedConstant = false;
        }
Ejemplo n.º 6
0
 public void AddAid(KAID aid)
 {
     if (aid == KAID.kaidThisAssembly)
     {
         _bsetFilter.Add(KAID.kaidGlobal);
     }
     _bsetFilter.Add(aid);
 }
Ejemplo n.º 7
0
 public void AddAid(KAID aid)
 {
     if (aid == KAID.kaidThisAssembly)
     {
         _bsetFilter.Add(KAID.kaidGlobal);
     }
     _bsetFilter.Add(aid);
 }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        public void SetAssemblyID(KAID aid)
        {
            Debug.Assert(_aid == default(KAID));
            Debug.Assert(KAID.kaidThisAssembly <= aid && aid < KAID.kaidMinModule);

            _aid = aid;
            _bsetFilter.Add(aid);
            if (aid == KAID.kaidThisAssembly)
                _bsetFilter.Add(KAID.kaidGlobal);
        }
Ejemplo n.º 10
0
        public void AddToAlias(KAID aid)
        {
            Debug.Assert(0 <= aid && aid < KAID.kaidMinModule);

            // NOTE: Anything in this assembly should not be added to other aliases!
            Debug.Assert(_aid > KAID.kaidThisAssembly);
            Debug.Assert(_bsetFilter.Contains(_aid));

            _bsetFilter.Add(aid);
        }
Ejemplo n.º 11
0
        public void AddToAlias(KAID aid)
        {
            Debug.Assert(0 <= aid && aid < KAID.kaidMinModule);

            // NOTE: Anything in this assembly should not be added to other aliases!
            Debug.Assert(_aid > KAID.kaidThisAssembly);
            Debug.Assert(_bsetFilter.Contains(_aid));

            _bsetFilter.Add(aid);
        }
 public bool InAlias(KAID aid)
 {
     Debug.Assert(_infile != null);
     //Debug.Assert(DeclFirst() == null || DeclFirst().GetAssemblyID() == infile.GetAssemblyID());
     Debug.Assert(0 <= aid);
     if (aid < KAID.kaidMinModule)
     {
         return(_infile.InAlias(aid));
     }
     return(aid == GetModuleID());
 }
Ejemplo n.º 13
0
        public void SetAssemblyID(KAID aid)
        {
            Debug.Assert(_aid == default(KAID));
            Debug.Assert(KAID.kaidThisAssembly <= aid && aid < KAID.kaidMinModule);

            _aid = aid;
            _bsetFilter.Add(aid);
            if (aid == KAID.kaidThisAssembly)
            {
                _bsetFilter.Add(KAID.kaidGlobal);
            }
        }
Ejemplo n.º 14
0
        private AssemblyQualifiedNamespaceSymbol GetNsAid(NamespaceSymbol ns, KAID aid)
        {
            Name name = GetNameFromPtrs(aid, 0);

            Debug.Assert(name != null);

            AssemblyQualifiedNamespaceSymbol nsa = LookupGlobalSymCore(name, ns, symbmask_t.MASK_AssemblyQualifiedNamespaceSymbol).AsAssemblyQualifiedNamespaceSymbol();

            if (nsa == null)
            {
                // Create a new one.
                nsa = _symFactory.CreateNamespaceAid(name, ns, aid);
            }

            Debug.Assert(nsa.GetNS() == ns);

            return(nsa);
        }
Ejemplo n.º 15
0
        public bool Init(ErrorHandling errorContext, SymbolTable symtable)
        {
            _runtimeBinderSymbolTable = symtable;
            Debug.Assert(_pBSymmgr != null);

#if !CSEE
            Debug.Assert(_predefSyms == null);
#else // CSEE
            Debug.Assert(predefSyms == null || aidMsCorLib != KAID.kaidNil);
#endif // CSEE

            if (_aidMsCorLib == KAID.kaidNil)
            {
                // If we haven't found mscorlib yet, first look for System.Object. Then use its assembly as
                // the location for all other pre-defined types.
                AggregateSymbol aggObj = FindPredefinedType(errorContext, PredefinedTypeFacts.GetName(PredefinedType.PT_OBJECT), KAID.kaidGlobal, AggKindEnum.Class, 0, true);
                if (aggObj == null)
                    return false;
                _aidMsCorLib = aggObj.GetAssemblyID();
            }

            _predefSyms = new AggregateSymbol[(int)PredefinedType.PT_COUNT];
            Debug.Assert(_predefSyms != null);

            return true;
        }
Ejemplo n.º 16
0
        private KAID _aidMsCorLib;        // The assembly ID for all predefined types.

        public PredefinedTypes(BSYMMGR pBSymmgr)
        {
            _pBSymmgr = pBSymmgr;
            _aidMsCorLib = KAID.kaidNil;
            _runtimeBinderSymbolTable = null;
        }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
0
        private AggregateSymbol FindPredefinedType(ErrorHandling errorContext, string pszType, KAID aid, AggKindEnum aggKind, int arity, bool isRequired)
        {
            Debug.Assert(!string.IsNullOrEmpty(pszType)); // Shouldn't be the empty string!

            NamespaceOrAggregateSymbol bagCur = _pBSymmgr.GetRootNS();
            Name name = null;

            string[] nameParts = pszType.Split(s_nameSeparators);
            for (int i = 0, n = nameParts.Length; i < n; i++)
            {
                name = _pBSymmgr.GetNameManager().Add(nameParts[i]);

                if (i == n - 1)
                {
                    // This is the last component. Handle it special below.
                    break;
                }

                // first search for an outer type which is also predefined
                // this must be first because we always create a namespace for
                // outer names, even for nested types
                AggregateSymbol aggNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol();
                if (aggNext != null && aggNext.InAlias(aid) && aggNext.IsPredefined())
                {
                    bagCur = aggNext;
                }
                else
                {
                    // ... if no outer type, then search for namespaces
                    NamespaceSymbol nsNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_NamespaceSymbol).AsNamespaceSymbol();
                    bool bIsInAlias = true;
                    if (nsNext == null)
                    {
                        bIsInAlias = false;
                    }
                    else
                    {
                        bIsInAlias = nsNext.InAlias(aid);
                    }
                    if (!bIsInAlias)
                    {
                        // Didn't find the namespace in this aid.
                        if (isRequired)
                        {
                            errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType);
                        }
                        return null;
                    }
                    bagCur = nsNext;
                }
            }

            AggregateSymbol aggAmbig;
            AggregateSymbol aggBad;
            AggregateSymbol aggFound = FindPredefinedTypeCore(name, bagCur, aid, aggKind, arity, out aggAmbig, out aggBad);

            if (aggFound == null)
            {
                // Didn't find the AggregateSymbol.
                if (aggBad != null && (isRequired || aid == KAID.kaidGlobal && aggBad.IsSource()))
                    errorContext.ErrorRef(ErrorCode.ERR_PredefinedTypeBadType, aggBad);
                else if (isRequired)
                    errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType);
                return null;
            }

            if (aggAmbig == null && aid != KAID.kaidGlobal)
            {
                // Look in kaidGlobal to make sure there isn't a conflicting one.
                AggregateSymbol tmp;
                AggregateSymbol agg2 = FindPredefinedTypeCore(name, bagCur, KAID.kaidGlobal, aggKind, arity, out aggAmbig, out tmp);
                Debug.Assert(agg2 != null);
                if (agg2 != aggFound)
                    aggAmbig = agg2;
            }

            return aggFound;
        }
Ejemplo n.º 19
0
 public bool InAlias(KAID aid)
 {
     Debug.Assert(0 <= aid);
     return _bsetFilter.Contains(aid);
 }
Ejemplo n.º 20
0
 public bool InAlias(KAID aid)
 {
     Debug.Assert(_infile != null);
     //Debug.Assert(DeclFirst() == null || DeclFirst().GetAssemblyID() == infile.GetAssemblyID());
     Debug.Assert(0 <= aid);
     if (aid < KAID.kaidMinModule)
         return _infile.InAlias(aid);
     return (aid == GetModuleID());
 }
        private AggregateSymbol FindPredefinedType(ErrorHandling errorContext, string pszType, KAID aid, AggKindEnum aggKind, int arity, bool isRequired)
        {
            Debug.Assert(!string.IsNullOrEmpty(pszType)); // Shouldn't be the empty string!

            NamespaceOrAggregateSymbol bagCur = _pBSymmgr.GetRootNS();
            Name name = null;

            string[] nameParts = pszType.Split(s_nameSeparators);
            for (int i = 0, n = nameParts.Length; i < n; i++)
            {
                name = _pBSymmgr.GetNameManager().Add(nameParts[i]);

                if (i == n - 1)
                {
                    // This is the last component. Handle it special below.
                    break;
                }

                // first search for an outer type which is also predefined
                // this must be first because we always create a namespace for
                // outer names, even for nested types
                AggregateSymbol aggNext = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_AggregateSymbol).AsAggregateSymbol();
                if (aggNext != null && aggNext.InAlias(aid) && aggNext.IsPredefined())
                {
                    bagCur = aggNext;
                }
                else
                {
                    // ... if no outer type, then search for namespaces
                    NamespaceSymbol nsNext     = _pBSymmgr.LookupGlobalSymCore(name, bagCur, symbmask_t.MASK_NamespaceSymbol).AsNamespaceSymbol();
                    bool            bIsInAlias = true;
                    if (nsNext == null)
                    {
                        bIsInAlias = false;
                    }
                    else
                    {
                        bIsInAlias = nsNext.InAlias(aid);
                    }
                    if (!bIsInAlias)
                    {
                        // Didn't find the namespace in this aid.
                        if (isRequired)
                        {
                            errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType);
                        }
                        return(null);
                    }
                    bagCur = nsNext;
                }
            }

            AggregateSymbol aggAmbig;
            AggregateSymbol aggBad;
            AggregateSymbol aggFound = FindPredefinedTypeCore(name, bagCur, aid, aggKind, arity, out aggAmbig, out aggBad);

            if (aggFound == null)
            {
                // Didn't find the AggregateSymbol.
                if (aggBad != null && (isRequired || aid == KAID.kaidGlobal && aggBad.IsSource()))
                {
                    errorContext.ErrorRef(ErrorCode.ERR_PredefinedTypeBadType, aggBad);
                }
                else if (isRequired)
                {
                    errorContext.Error(ErrorCode.ERR_PredefinedTypeNotFound, pszType);
                }
                return(null);
            }

            if (aggAmbig == null && aid != KAID.kaidGlobal)
            {
                // Look in kaidGlobal to make sure there isn't a conflicting one.
                AggregateSymbol tmp;
                AggregateSymbol agg2 = FindPredefinedTypeCore(name, bagCur, KAID.kaidGlobal, aggKind, arity, out aggAmbig, out tmp);
                Debug.Assert(agg2 != null);
                if (agg2 != aggFound)
                {
                    aggAmbig = agg2;
                }
            }

            return(aggFound);
        }
        KAID aidMsCorLib;             // The assembly ID for all predefined types.

        public PredefinedTypes(BSYMMGR pBSymmgr)
        {
            this.pBSymmgr    = pBSymmgr;
            this.aidMsCorLib = KAID.kaidNil;
            this.runtimeBinderSymbolTable = null;
        }
Ejemplo n.º 23
0
 public AssemblyQualifiedNamespaceSymbol GetRootNsAid(KAID aid)
 {
     return(GetNsAid(_rootNS, aid));
 }
Ejemplo n.º 24
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);
        }
        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);
        }
Ejemplo n.º 26
0
 public bool InAlias(KAID aid)
 {
     Debug.Assert(0 <= aid);
     return(_bsetFilter.Contains(aid));
 }
        private KAID _aidMsCorLib;             // The assembly ID for all predefined types.

        public PredefinedTypes(BSYMMGR pBSymmgr)
        {
            _pBSymmgr    = pBSymmgr;
            _aidMsCorLib = KAID.kaidNil;
            _runtimeBinderSymbolTable = null;
        }