public EXPRTHISPOINTER CreateThis(LocalVariableSymbol pLocal, bool fImplicit) { Debug.Assert(pLocal == null || pLocal.isThis); CType type = null; if (pLocal != null) { type = pLocal.GetType(); } EXPRFLAG flags = EXPRFLAG.EXF_CANTBENULL; if (fImplicit) { flags |= EXPRFLAG.EXF_IMPLICITTHIS; } if (type != null && type.isStructType()) { flags |= EXPRFLAG.EXF_LVALUE; } EXPRTHISPOINTER rval = new EXPRTHISPOINTER(); rval.kind = ExpressionKind.EK_THISPOINTER; rval.type = type; rval.flags = flags; rval.local = pLocal; Debug.Assert(rval != null); return(rval); }
public ExprLocal(LocalVariableSymbol local) : base(ExpressionKind.Local) { Flags = EXPRFLAG.EXF_LVALUE; Local = local; Type = local?.GetType(); }
public ExprLocal CreateLocal(EXPRFLAG nFlags, LocalVariableSymbol pLocal) { Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MASK_ANY))); ExprLocal rval = new ExprLocal(); rval.Flags = nFlags; rval.Local = pLocal; return(rval); }
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); }
protected void ReportLocalError(LocalVariableSymbol local, CheckLvalueKind kind, bool isNested) { Debug.Assert(local != null); int index = kind == CheckLvalueKind.OutParameter ? 0 : 1; Debug.Assert(index != 2 && index != 3); // There is no way that we can have no cause AND a read-only local nested in a struct with a // writable field. What would make the local read-only if not one of the causes above? (Const // locals may not be structs, so we would already have errored out in that scenario.) ErrorCode err = s_ReadOnlyLocalErrors[index]; ErrorContext.Error(err, local.name); }
private RuntimeBinderException ReportLocalError(LocalVariableSymbol local, CheckLvalueKind kind, bool isNested) { Debug.Assert(local != null); int index = kind == CheckLvalueKind.OutParameter ? 0 : 1; Debug.Assert(index != 2 && index != 3); // There is no way that we can have no cause AND a read-only local nested in a struct with a // writable field. What would make the local read-only if not one of the causes above? (Const // locals may not be structs, so we would already have errored out in that scenario.) ErrorCode err = s_ReadOnlyLocalErrors[index]; return(ErrorContext.Error(err, local.name)); }
public EXPRLOCAL CreateLocal(EXPRFLAG nFlags, LocalVariableSymbol pLocal) { Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MASK_ANY))); CType type = null; if (pLocal != null) { type = pLocal.GetType(); } EXPRLOCAL rval = new EXPRLOCAL(); rval.kind = ExpressionKind.EK_LOCAL; rval.type = type; rval.flags = nFlags; rval.local = pLocal; Debug.Assert(rval != null); return(rval); }
public ExprThisPointer CreateThis(LocalVariableSymbol pLocal, bool fImplicit) { Debug.Assert(pLocal == null || pLocal.isThis); EXPRFLAG flags = EXPRFLAG.EXF_CANTBENULL; if (fImplicit) { flags |= EXPRFLAG.EXF_IMPLICITTHIS; } if (pLocal != null && pLocal.GetType().isStructType()) { flags |= EXPRFLAG.EXF_LVALUE; } ExprThisPointer rval = new ExprThisPointer(); rval.Flags = flags; rval.Local = pLocal; return(rval); }
protected Symbol newBasicSym( SYMKIND kind, Name name, ParentSymbol parent) { // The parser creates names with PN_MISSING when attempting to recover from errors // To prevent spurious errors, we create SYMs with a different name (PN_MISSINGSYM) // so that they are never found when doing lookup. if (name == m_pMissingNameNode) { name = m_pMissingNameSym; } Symbol sym; switch (kind) { case SYMKIND.SK_NamespaceSymbol: sym = new NamespaceSymbol(); sym.name = name; break; case SYMKIND.SK_NamespaceDeclaration: sym = new NamespaceDeclaration(); sym.name = name; break; case SYMKIND.SK_AssemblyQualifiedNamespaceSymbol: sym = new AssemblyQualifiedNamespaceSymbol(); sym.name = name; break; case SYMKIND.SK_AggregateSymbol: sym = new AggregateSymbol(); sym.name = name; break; case SYMKIND.SK_AggregateDeclaration: sym = new AggregateDeclaration(); sym.name = name; break; case SYMKIND.SK_TypeParameterSymbol: sym = new TypeParameterSymbol(); sym.name = name; break; case SYMKIND.SK_FieldSymbol: sym = new FieldSymbol(); sym.name = name; break; case SYMKIND.SK_LocalVariableSymbol: sym = new LocalVariableSymbol(); sym.name = name; break; case SYMKIND.SK_MethodSymbol: sym = new MethodSymbol(); sym.name = name; break; case SYMKIND.SK_PropertySymbol: sym = new PropertySymbol(); sym.name = name; break; case SYMKIND.SK_EventSymbol: sym = new EventSymbol(); sym.name = name; break; case SYMKIND.SK_TransparentIdentifierMemberSymbol: sym = new TransparentIdentifierMemberSymbol(); sym.name = name; break; case SYMKIND.SK_Scope: sym = new Scope(); sym.name = name; break; case SYMKIND.SK_LabelSymbol: sym = new LabelSymbol(); sym.name = name; break; case SYMKIND.SK_GlobalAttributeDeclaration: sym = new GlobalAttributeDeclaration(); sym.name = name; break; case SYMKIND.SK_UnresolvedAggregateSymbol: sym = new UnresolvedAggregateSymbol(); sym.name = name; break; case SYMKIND.SK_InterfaceImplementationMethodSymbol: sym = new InterfaceImplementationMethodSymbol(); sym.name = name; break; case SYMKIND.SK_IndexerSymbol: sym = new IndexerSymbol(); sym.name = name; break; case SYMKIND.SK_ParentSymbol: sym = new ParentSymbol(); sym.name = name; break; case SYMKIND.SK_IteratorFinallyMethodSymbol: sym = new IteratorFinallyMethodSymbol(); sym.name = name; break; default: throw Error.InternalCompilerError(); } sym.setKind(kind); if (parent != null) { // Set the parent element of the child symbol. parent.AddToChildList(sym); m_pSymTable.InsertChild(parent, sym); } return(sym); }
public EXPRTHISPOINTER CreateThis(LocalVariableSymbol pLocal, bool fImplicit) { Debug.Assert(pLocal == null || pLocal.isThis); CType type = null; if (pLocal != null) { type = pLocal.GetType(); } EXPRFLAG flags = EXPRFLAG.EXF_CANTBENULL; if (fImplicit) { flags |= EXPRFLAG.EXF_IMPLICITTHIS; } if (type != null && type.isStructType()) { flags |= EXPRFLAG.EXF_LVALUE; } EXPRTHISPOINTER rval = new EXPRTHISPOINTER(); rval.kind = ExpressionKind.EK_THISPOINTER; rval.type = type; rval.flags = flags; rval.local = pLocal; Debug.Assert(rval != null); return (rval); }
public static ExprLocal CreateLocal(LocalVariableSymbol local) => new ExprLocal(local);
protected Symbol newBasicSym( SYMKIND kind, Name name, ParentSymbol parent) { // The parser creates names with PN_MISSING when attempting to recover from errors // To prevent spurious errors, we create SYMs with a different name (PN_MISSINGSYM) // so that they are never found when doing lookup. if (name == m_pMissingNameNode) { name = m_pMissingNameSym; } Symbol sym; switch (kind) { case SYMKIND.SK_NamespaceSymbol: sym = new NamespaceSymbol(); sym.name = name; break; case SYMKIND.SK_NamespaceDeclaration: sym = new NamespaceDeclaration(); sym.name = name; break; case SYMKIND.SK_AssemblyQualifiedNamespaceSymbol: sym = new AssemblyQualifiedNamespaceSymbol(); sym.name = name; break; case SYMKIND.SK_AggregateSymbol: sym = new AggregateSymbol(); sym.name = name; break; case SYMKIND.SK_AggregateDeclaration: sym = new AggregateDeclaration(); sym.name = name; break; case SYMKIND.SK_TypeParameterSymbol: sym = new TypeParameterSymbol(); sym.name = name; break; case SYMKIND.SK_FieldSymbol: sym = new FieldSymbol(); sym.name = name; break; case SYMKIND.SK_LocalVariableSymbol: sym = new LocalVariableSymbol(); sym.name = name; break; case SYMKIND.SK_MethodSymbol: sym = new MethodSymbol(); sym.name = name; break; case SYMKIND.SK_PropertySymbol: sym = new PropertySymbol(); sym.name = name; break; case SYMKIND.SK_EventSymbol: sym = new EventSymbol(); sym.name = name; break; case SYMKIND.SK_TransparentIdentifierMemberSymbol: sym = new TransparentIdentifierMemberSymbol(); sym.name = name; break; case SYMKIND.SK_Scope: sym = new Scope(); sym.name = name; break; case SYMKIND.SK_LabelSymbol: sym = new LabelSymbol(); sym.name = name; break; case SYMKIND.SK_GlobalAttributeDeclaration: sym = new GlobalAttributeDeclaration(); sym.name = name; break; case SYMKIND.SK_UnresolvedAggregateSymbol: sym = new UnresolvedAggregateSymbol(); sym.name = name; break; case SYMKIND.SK_InterfaceImplementationMethodSymbol: sym = new InterfaceImplementationMethodSymbol(); sym.name = name; break; case SYMKIND.SK_IndexerSymbol: sym = new IndexerSymbol(); sym.name = name; break; case SYMKIND.SK_ParentSymbol: sym = new ParentSymbol(); sym.name = name; break; case SYMKIND.SK_IteratorFinallyMethodSymbol: sym = new IteratorFinallyMethodSymbol(); sym.name = name; break; default: throw Error.InternalCompilerError(); } sym.setKind(kind); if (parent != null) { // Set the parent element of the child symbol. parent.AddToChildList(sym); m_pSymTable.InsertChild(parent, sym); } return (sym); }
///////////////////////////////////////////////////////////////////////////////// private EXPR CreateArgumentEXPR(ArgumentObject argument, LocalVariableSymbol local) { EXPR arg; if (argument.Info.LiteralConstant) { if (argument.Value == null) { if (argument.Info.UseCompileTimeType) { arg = _exprFactory.CreateConstant(_symbolTable.GetCTypeFromType(argument.Type), new CONSTVAL()); } else { arg = _exprFactory.CreateNull(); } } else { arg = _exprFactory.CreateConstant(_symbolTable.GetCTypeFromType(argument.Type), new CONSTVAL(argument.Value)); } } else { // If we have a dynamic argument and it was null, the type is going to be Object. // But we want it to be typed NullType so we can have null conversions. if (!argument.Info.UseCompileTimeType && argument.Value == null) { arg = _exprFactory.CreateNull(); } else { arg = CreateLocal(argument.Type, argument.Info.IsOut, local); } } // Now check if we have a named thing. If so, wrap this thing in a named argument. if (argument.Info.NamedArgument) { Debug.Assert(argument.Info.Name != null); arg = _exprFactory.CreateNamedArgumentSpecification(SymbolTable.GetName(argument.Info.Name, _semanticChecker.GetNameManager()), arg); } // If we have an object that was "dynamic" at compile time, we need // to be able to convert it to every interface that the actual value // implements. This allows conversion binders and overload resolution // to behave as though type information is available for these EXPRs, // even though it may be the case that the actual runtime type is // inaccessible and therefore unused. // This comes in handy for, e.g., iterators (they are nested private // classes), and COM RCWs without type information (they do not expose // their interfaces in a usual way). // It is critical that arg.RuntimeObject is non-null only when the // compile time type of the argument is dynamic, otherwise normal C# // semantics on typed arguments will be broken. if (!argument.Info.UseCompileTimeType && argument.Value != null) { arg.RuntimeObject = argument.Value; arg.RuntimeObjectActualType = _symbolTable.GetCTypeFromType(argument.Value.GetType()); } return arg; }
///////////////////////////////////////////////////////////////////////////////// private EXPR CreateLocal(Type type, bool bIsOut, LocalVariableSymbol local) { CType ctype = _symbolTable.GetCTypeFromType(type); if (bIsOut) { Debug.Assert(ctype.IsParameterModifierType()); ctype = _semanticChecker.GetTypeManager().GetParameterModifier( ctype.AsParameterModifierType().GetParameterType(), true); } // If we can convert, do that. If not, cast it. EXPRLOCAL exprLocal = _exprFactory.CreateLocal(EXPRFLAG.EXF_LVALUE, local); EXPR result = _binder.tryConvert(exprLocal, ctype); if (result == null) { result = _binder.mustCast(exprLocal, ctype); } result.flags |= EXPRFLAG.EXF_LVALUE; return result; }
///////////////////////////////////////////////////////////////////////////////// private EXPR BindProperty( DynamicMetaObjectBinder payload, ArgumentObject argument, LocalVariableSymbol local, EXPR optionalIndexerArguments, bool fEventsPermitted) { // If our argument is a static type, then we're calling a static property. EXPR callingObject = argument.Info.IsStaticType ? _exprFactory.CreateClass(_symbolTable.GetCTypeFromType(argument.Value as Type), null, null) : CreateLocal(argument.Type, argument.Info.IsOut, local); if (!argument.Info.UseCompileTimeType && argument.Value == null) { throw Error.NullReferenceOnMemberException(); } // If our argument is a struct type, unbox it. if (argument.Type.GetTypeInfo().IsValueType && callingObject.isCAST()) { // If we have a struct type, unbox it. callingObject.flags |= EXPRFLAG.EXF_UNBOXRUNTIME; } string name = GetName(payload); BindingFlag bindFlags = GetBindingFlags(payload); MemberLookup mem = new MemberLookup(); SymWithType swt = _symbolTable.LookupMember(name, callingObject, _bindingContext.ContextForMemberLookup(), 0, mem, false, false); if (swt == null) { if (optionalIndexerArguments != null) { int numIndexArguments = ExpressionIterator.Count(optionalIndexerArguments); // We could have an array access here. See if its just an array. if ((argument.Type.IsArray && argument.Type.GetArrayRank() == numIndexArguments) || argument.Type == typeof(string)) { return CreateArray(callingObject, optionalIndexerArguments); } } mem.ReportErrors(); Debug.Assert(false, "Why didn't member lookup report an error?"); } switch (swt.Sym.getKind()) { case SYMKIND.SK_MethodSymbol: throw Error.BindPropertyFailedMethodGroup(name); case SYMKIND.SK_PropertySymbol: if (swt.Sym is IndexerSymbol) { return CreateIndexer(swt, callingObject, optionalIndexerArguments, bindFlags); } else { BindingFlag flags = 0; if (payload is CSharpGetMemberBinder || payload is CSharpGetIndexBinder) { flags = BindingFlag.BIND_RVALUEREQUIRED; } // Properties can be LValues. callingObject.flags |= EXPRFLAG.EXF_LVALUE; return CreateProperty(swt, callingObject, flags); } case SYMKIND.SK_FieldSymbol: return CreateField(swt, callingObject); case SYMKIND.SK_EventSymbol: if (fEventsPermitted) { return CreateEvent(swt, callingObject); } else { throw Error.BindPropertyFailedEvent(name); } default: Debug.Assert(false, "Unexpected type returned from lookup"); throw Error.InternalCompilerError(); } }
public EXPRLOCAL CreateLocal(EXPRFLAG nFlags, LocalVariableSymbol pLocal) { Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MASK_ANY))); CType type = null; if (pLocal != null) { type = pLocal.GetType(); } EXPRLOCAL rval = new EXPRLOCAL(); rval.kind = ExpressionKind.EK_LOCAL; rval.type = type; rval.flags = nFlags; rval.local = pLocal; Debug.Assert(rval != null); return (rval); }
private Symbol NewBasicSymbol( SYMKIND kind, Name name, ParentSymbol parent) { Symbol sym; switch (kind) { case SYMKIND.SK_NamespaceSymbol: sym = new NamespaceSymbol(); sym.name = name; break; case SYMKIND.SK_AggregateSymbol: sym = new AggregateSymbol(); sym.name = name; break; case SYMKIND.SK_AggregateDeclaration: sym = new AggregateDeclaration(); sym.name = name; break; case SYMKIND.SK_TypeParameterSymbol: sym = new TypeParameterSymbol(); sym.name = name; break; case SYMKIND.SK_FieldSymbol: sym = new FieldSymbol(); sym.name = name; break; case SYMKIND.SK_LocalVariableSymbol: sym = new LocalVariableSymbol(); sym.name = name; break; case SYMKIND.SK_MethodSymbol: sym = new MethodSymbol(); sym.name = name; break; case SYMKIND.SK_PropertySymbol: sym = new PropertySymbol(); sym.name = name; break; case SYMKIND.SK_EventSymbol: sym = new EventSymbol(); sym.name = name; break; case SYMKIND.SK_Scope: sym = new Scope(); sym.name = name; break; case SYMKIND.SK_IndexerSymbol: sym = new IndexerSymbol(); sym.name = name; break; default: throw Error.InternalCompilerError(); } sym.setKind(kind); if (parent != null) { // Set the parent element of the child symbol. parent.AddToChildList(sym); _symbolTable.InsertChild(parent, sym); } return(sym); }