///////////////////////////////////////////////////////////////////////////////// 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; }
public GlobalSymbolContext(NameManager namemgr) { TypeManager = new TypeManager(); GlobalSymbols = new BSYMMGR(namemgr, TypeManager); _predefTypes = new PredefinedTypes(GlobalSymbols); TypeManager.Init(GlobalSymbols, _predefTypes); GlobalSymbols.Init(); _nameManager = namemgr; }
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); }
///////////////////////////////////////////////////////////////////////////////// internal SymbolTable( SYMTBL symTable, SymFactory symFactory, NameManager nameManager, TypeManager typeManager, BSYMMGR bsymmgr, CSemanticChecker semanticChecker, InputFile infile) { _symbolTable = symTable; _symFactory = symFactory; _nameManager = nameManager; _typeManager = typeManager; _bsymmgr = bsymmgr; _semanticChecker = semanticChecker; _infile = infile; ClearCache(); }
///////////////////////////////////////////////////////////////////////////////// public static Expression Rewrite(TypeManager typeManager, EXPR pExpr, IEnumerable<Expression> listOfParameters) { ExpressionTreeCallRewriter rewriter = new ExpressionTreeCallRewriter(typeManager, listOfParameters); // We should have a EXPRBINOP thats an EK_SEQUENCE. The RHS of our sequence // should be a call to PM_EXPRESSION_LAMBDA. The LHS of our sequence is the // set of declarations for the parameters that we'll need. // Assert all of these first, and then unwrap them. Debug.Assert(pExpr != null); Debug.Assert(pExpr.isBIN()); Debug.Assert(pExpr.kind == ExpressionKind.EK_SEQUENCE); Debug.Assert(pExpr.asBIN().GetOptionalRightChild() != null); Debug.Assert(pExpr.asBIN().GetOptionalRightChild().isCALL()); Debug.Assert(pExpr.asBIN().GetOptionalRightChild().asCALL().PredefinedMethod == PREDEFMETH.PM_EXPRESSION_LAMBDA); Debug.Assert(pExpr.asBIN().GetOptionalLeftChild() != null); // Visit the left to generate the parameter construction. rewriter.Visit(pExpr.asBIN().GetOptionalLeftChild()); EXPRCALL call = pExpr.asBIN().GetOptionalRightChild().asCALL(); ExpressionEXPR e = rewriter.Visit(call) as ExpressionEXPR; return e.Expression; }
///////////////////////////////////////////////////////////////////////////////// public AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent, TypeManager typeManager) { if (name == null || parent == null || typeManager == null) { throw Error.InternalCompilerError(); } AggregateSymbol sym = (AggregateSymbol)NewBasicSymbol(SYMKIND.SK_AggregateSymbol, name, parent); sym.name = name; sym.SetTypeManager(typeManager); sym.SetSealed(false); sym.SetAccess(ACCESS.ACC_UNKNOWN); sym.SetIfaces(null); sym.SetIfacesAll(null); sym.SetTypeVars(null); return(sym); }
public override AggregateType GetAts() => _ats ?? (_ats = TypeManager.GetAggregate(TypeManager.GetNullable(), TypeArray.Allocate(UnderlyingType)));
private static bool CheckSingleConstraint(Symbol symErr, TypeParameterType var, CType arg, TypeArray typeArgsCls, TypeArray typeArgsMeth, CheckConstraintsFlags flags) { Debug.Assert(!(arg is PointerType)); Debug.Assert(!arg.IsStaticClass); bool fReportErrors = 0 == (flags & CheckConstraintsFlags.NoErrors); if (var.HasRefConstraint && !arg.IsReferenceType) { if (fReportErrors) { throw ErrorHandling.Error(ErrorCode.ERR_RefConstraintNotSatisfied, symErr, new ErrArgNoRef(var), arg); } return(false); } TypeArray bnds = TypeManager.SubstTypeArray(var.Bounds, typeArgsCls, typeArgsMeth); int itypeMin = 0; if (var.HasValConstraint) { // If we have a type variable that is constrained to a value type, then we // want to check if its a nullable type, so that we can report the // constraint error below. In order to do this however, we need to check // that either the type arg is not a value type, or it is a nullable type. // // To check whether or not its a nullable type, we need to get the resolved // bound from the type argument and check against that. if (!arg.IsNonNullableValueType) { if (fReportErrors) { throw ErrorHandling.Error(ErrorCode.ERR_ValConstraintNotSatisfied, symErr, new ErrArgNoRef(var), arg); } return(false); } // Since FValCon() is set it is redundant to check System.ValueType as well. if (bnds.Count != 0 && bnds[0].IsPredefType(PredefinedType.PT_VALUE)) { itypeMin = 1; } } for (int j = itypeMin; j < bnds.Count; j++) { CType typeBnd = bnds[j]; if (!SatisfiesBound(arg, typeBnd)) { if (fReportErrors) { // The bound isn't satisfied because of a constraint type. Explain to the user why not. // There are 4 main cases, based on the type of the supplied type argument: // - reference type, or type parameter known to be a reference type // - nullable type, from which there is a boxing conversion to the constraint type(see below for details) // - type variable // - value type // These cases are broken out because: a) The sets of conversions which can be used // for constraint satisfaction is different based on the type argument supplied, // and b) Nullable is one funky type, and user's can use all the help they can get // when using it. ErrorCode error; if (arg.IsReferenceType) { // A reference type can only satisfy bounds to types // to which they have an implicit reference conversion error = ErrorCode.ERR_GenericConstraintNotSatisfiedRefType; } else if (arg is NullableType nubArg && SymbolLoader.HasBaseConversion(nubArg.UnderlyingType, typeBnd)) // This is inlining FBoxingConv { // nullable types do not satisfy bounds to every type that they are boxable to // They only satisfy bounds of object and ValueType if (typeBnd.IsPredefType(PredefinedType.PT_ENUM) || nubArg.UnderlyingType == typeBnd) { // Nullable types don't satisfy bounds of EnumType, or the underlying type of the enum // even though the conversion from Nullable to these types is a boxing conversion // This is a rare case, because these bounds can never be directly stated ... // These bounds can only occur when one type parameter is constrained to a second type parameter // and the second type parameter is instantiated with Enum or the underlying type of the first type // parameter error = ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum; } else { // Nullable types don't satisfy the bounds of any interface type // even when there is a boxing conversion from the Nullable type to // the interface type. This will be a relatively common scenario // so we cal it out separately from the previous case. Debug.Assert(typeBnd.IsInterfaceType); error = ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface; } } else { // Value types can only satisfy bounds through boxing conversions. // Note that the exceptional case of Nullable types and boxing is handled above. error = ErrorCode.ERR_GenericConstraintNotSatisfiedValType; } throw ErrorHandling.Error(error, new ErrArg(symErr), new ErrArg(typeBnd, ErrArgFlags.Unique), var, new ErrArg(arg, ErrArgFlags.Unique)); } return(false); } }
public static ExprConstant CreateBoolConstant(bool b) => CreateConstant(TypeManager.GetPredefAgg(PredefinedType.PT_BOOL).getThisType(), ConstVal.Get(b));
///////////////////////////////////////////////////////////////////////////////// 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); }
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; }
internal static bool ReOrderArgsForNamedArguments( MethodOrPropertySymbol methprop, TypeArray pCurrentParameters, AggregateType pCurrentType, EXPRMEMGRP pGroup, ArgInfos pArguments, TypeManager typeManager, ExprFactory exprFactory, SymbolLoader symbolLoader) { // We use the param count from pCurrentParameters because they may have been resized // for param arrays. int numParameters = pCurrentParameters.size; EXPR[] pExprArguments = new EXPR[numParameters]; // Now go through the parameters. First set all positional arguments in the new argument // set, then for the remainder, look for a named argument with a matching name. int index = 0; EXPR paramArrayArgument = null; TypeArray @params = typeManager.SubstTypeArray( pCurrentParameters, pCurrentType, pGroup.typeArgs); foreach (Name name in methprop.ParameterNames) { // This can happen if we had expanded our param array to size 0. if (index >= pCurrentParameters.size) { break; } // If: // (1) we have a param array method // (2) we're on the last arg // (3) the thing we have is an array init thats generated for param array // then let us through. if (methprop.isParamArray && index < pArguments.carg && pArguments.prgexpr[index].isARRINIT() && pArguments.prgexpr[index].asARRINIT().GeneratedForParamArray) { paramArrayArgument = pArguments.prgexpr[index]; } // Positional. if (index < pArguments.carg && !pArguments.prgexpr[index].isNamedArgumentSpecification() && !(pArguments.prgexpr[index].isARRINIT() && pArguments.prgexpr[index].asARRINIT().GeneratedForParamArray)) { pExprArguments[index] = pArguments.prgexpr[index++]; continue; } // Look for names. EXPR pNewArg = FindArgumentWithName(pArguments, name); if (pNewArg == null) { if (methprop.IsParameterOptional(index)) { pNewArg = GenerateOptionalArgument(symbolLoader, exprFactory, methprop, @params.Item(index), index); } else if (paramArrayArgument != null && index == methprop.Params.Count - 1) { // If we have a param array argument and we're on the last one, then use it. pNewArg = paramArrayArgument; } else { // No name and no default value. return false; } } pExprArguments[index++] = pNewArg; } // Here we've found all the arguments, or have default values for them. CType[] prgTypes = new CType[pCurrentParameters.size]; for (int i = 0; i < numParameters; i++) { if (i < pArguments.prgexpr.Count) { pArguments.prgexpr[i] = pExprArguments[i]; } else { pArguments.prgexpr.Add(pExprArguments[i]); } prgTypes[i] = pArguments.prgexpr[i].type; } pArguments.carg = pCurrentParameters.size; pArguments.types = symbolLoader.getBSymmgr().AllocParams(pCurrentParameters.size, prgTypes); return true; }
public bool InternalsVisibleTo(Assembly assembly) => TypeManager.InternalsVisibleTo(AssociatedAssembly, assembly);
public static ExprConstant CreateStringConstant(string str) => CreateConstant(TypeManager.GetPredefAgg(PredefinedType.PT_STRING).getThisType(), ConstVal.Get(str));
public static ExprTypeOf CreateTypeOf(CType sourceType) => new ExprTypeOf(TypeManager.GetPredefAgg(PredefinedType.PT_TYPE).getThisType(), sourceType);
public static ExprFieldInfo CreateFieldInfo(FieldSymbol field, AggregateType fieldType) => new ExprFieldInfo(field, fieldType, TypeManager.GetPredefAgg(PredefinedType.PT_FIELDINFO).getThisType());
public static ExprPropertyInfo CreatePropertyInfo(PropertySymbol prop, AggregateType propertyType) => new ExprPropertyInfo(TypeManager.GetPredefAgg(PredefinedType.PT_PROPERTYINFO).getThisType(), prop, propertyType);
public static ExprMethodInfo CreateMethodInfo(MethodSymbol method, AggregateType methodType, TypeArray methodParameters) => new ExprMethodInfo( TypeManager.GetPredefAgg(method.IsConstructor() ? PredefinedType.PT_CONSTRUCTORINFO : PredefinedType.PT_METHODINFO).getThisType(), method, methodType, methodParameters);
///////////////////////////////////////////////////////////////////////////////// protected ExpressionTreeCallRewriter(TypeManager typeManager, IEnumerable<Expression> listOfParameters) { _typeManager = typeManager; _DictionaryOfParameters = new Dictionary<EXPRCALL, Expression>(); _ListOfParameters = listOfParameters; }
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); }
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); }
//////////////////////////////////////////////////////////////////////////////// // Get the standard type variable (eg, !0, !1, or !!0, !!1). // // iv is the index. // pbsm is the containing symbol manager // fMeth designates whether this is a method type var or class type var // // The standard class type variables are useful during emit, but not for type // comparison when binding. The standard method type variables are useful during // binding for signature comparison. public TypeParameterType GetTypeVarSym(int iv, TypeManager pTypeManager, bool fMeth) { Debug.Assert(iv >= 0); TypeParameterType tpt = null; if (iv >= this.prgptvs.Count) { TypeParameterSymbol pTypeParameter = new TypeParameterSymbol(); pTypeParameter.SetIsMethodTypeParameter(fMeth); pTypeParameter.SetIndexInOwnParameters(iv); pTypeParameter.SetIndexInTotalParameters(iv); pTypeParameter.SetAccess(ACCESS.ACC_PRIVATE); tpt = pTypeManager.GetTypeParameter(pTypeParameter); this.prgptvs.Add(tpt); } else { tpt = this.prgptvs[iv]; } Debug.Assert(tpt != null); return tpt; }
public static AggregateSymbol GetPredefAgg(PredefinedType pt) => TypeManager.GetPredefAgg(pt);
public void SetTypeManager(TypeManager typeManager) { _pTypeManager = typeManager; }
public void SetTypeManager(TypeManager typeManager) { _pTypeManager = typeManager; }
private static bool IsDelegateType(CType pSrcType, AggregateType pAggType) => TypeManager.SubstType(pSrcType, pAggType, pAggType.TypeArgsAll).IsDelegateType;
public static ExprConstant CreateIntegerConstant(int x) => CreateConstant(TypeManager.GetPredefAgg(PredefinedType.PT_INT).getThisType(), ConstVal.Get(x));
private Expr GenerateBuiltInBinaryOperator(ExprBinOp expr) { Debug.Assert(expr != null); PREDEFMETH pdm = expr.Kind switch { ExpressionKind.LeftShirt => PREDEFMETH.PM_EXPRESSION_LEFTSHIFT, ExpressionKind.RightShift => PREDEFMETH.PM_EXPRESSION_RIGHTSHIFT, ExpressionKind.BitwiseExclusiveOr => PREDEFMETH.PM_EXPRESSION_EXCLUSIVEOR, ExpressionKind.BitwiseOr => PREDEFMETH.PM_EXPRESSION_OR, ExpressionKind.BitwiseAnd => PREDEFMETH.PM_EXPRESSION_AND, ExpressionKind.LogicalAnd => PREDEFMETH.PM_EXPRESSION_ANDALSO, ExpressionKind.LogicalOr => PREDEFMETH.PM_EXPRESSION_ORELSE, ExpressionKind.StringEq => PREDEFMETH.PM_EXPRESSION_EQUAL, ExpressionKind.Eq => PREDEFMETH.PM_EXPRESSION_EQUAL, ExpressionKind.StringNotEq => PREDEFMETH.PM_EXPRESSION_NOTEQUAL, ExpressionKind.NotEq => PREDEFMETH.PM_EXPRESSION_NOTEQUAL, ExpressionKind.GreaterThanOrEqual => PREDEFMETH.PM_EXPRESSION_GREATERTHANOREQUAL, ExpressionKind.LessThanOrEqual => PREDEFMETH.PM_EXPRESSION_LESSTHANOREQUAL, ExpressionKind.LessThan => PREDEFMETH.PM_EXPRESSION_LESSTHAN, ExpressionKind.GreaterThan => PREDEFMETH.PM_EXPRESSION_GREATERTHAN, ExpressionKind.Modulo => PREDEFMETH.PM_EXPRESSION_MODULO, ExpressionKind.Divide => PREDEFMETH.PM_EXPRESSION_DIVIDE, ExpressionKind.Multiply => expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_MULTIPLYCHECKED : PREDEFMETH.PM_EXPRESSION_MULTIPLY, ExpressionKind.Subtract => expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_SUBTRACTCHECKED : PREDEFMETH.PM_EXPRESSION_SUBTRACT, ExpressionKind.Add => expr.isChecked() ? PREDEFMETH.PM_EXPRESSION_ADDCHECKED : PREDEFMETH.PM_EXPRESSION_ADD, _ => throw Error.InternalCompilerError(), }; Expr origL = expr.OptionalLeftChild; Expr origR = expr.OptionalRightChild; Debug.Assert(origL != null); Debug.Assert(origR != null); CType typeL = origL.Type; CType typeR = origR.Type; Expr newL = Visit(origL); Expr newR = Visit(origR); bool didEnumConversion = false; CType convertL = null; CType convertR = null; if (typeL.IsEnumType) { // We have already inserted casts if not lifted, so we should never see an enum. Debug.Assert(expr.IsLifted); convertL = TypeManager.GetNullable(typeL.UnderlyingEnumType); typeL = convertL; didEnumConversion = true; } else if (typeL is NullableType nubL && nubL.UnderlyingType.IsEnumType) { Debug.Assert(expr.IsLifted); convertL = TypeManager.GetNullable(nubL.UnderlyingType.UnderlyingEnumType); typeL = convertL; didEnumConversion = true; } if (typeR.IsEnumType) { Debug.Assert(expr.IsLifted); convertR = TypeManager.GetNullable(typeR.UnderlyingEnumType); typeR = convertR; didEnumConversion = true; } else if (typeR is NullableType nubR && nubR.UnderlyingType.IsEnumType) { Debug.Assert(expr.IsLifted); convertR = TypeManager.GetNullable(nubR.UnderlyingType.UnderlyingEnumType); typeR = convertR; didEnumConversion = true; } if (typeL is NullableType nubL2 && nubL2.UnderlyingType == typeR) { convertR = typeL; } if (typeR is NullableType nubR2 && nubR2.UnderlyingType == typeL) { convertL = typeR; } if (convertL != null) { newL = GenerateCall(PREDEFMETH.PM_EXPRESSION_CONVERT, newL, CreateTypeOf(convertL)); } if (convertR != null) { newR = GenerateCall(PREDEFMETH.PM_EXPRESSION_CONVERT, newR, CreateTypeOf(convertR)); } Expr call = GenerateCall(pdm, newL, newR); if (didEnumConversion && expr.Type.StripNubs().IsEnumType) { call = GenerateCall(PREDEFMETH.PM_EXPRESSION_CONVERT, call, CreateTypeOf(expr.Type)); } return(call); }
public GlobalSymbolContext() { GlobalSymbols = new BSYMMGR(); _predefTypes = new PredefinedTypes(GlobalSymbols); TypeManager = new TypeManager(GlobalSymbols, _predefTypes); }