// Delegates are really just blessed Types. void CreateProxyType(ISemanticResolver s) { Debug.Assert(m_nodeProxy == null, "only create proxy once"); // The delegate R F(A) (where R is a return type, and A is a parameter list) // Can be converted into the type: // sealed class F : System.MulticastDelegate { // F(object, native int) { } // BeginInvoke() { } // EndInvoke() { } // R Invoke(A) { } // } BlockStatement stmtEmpty = new BlockStatement(null, new Statement[0]); Modifiers modsPublic = new Modifiers(); modsPublic.SetPublic(); Modifiers modsVirtual = modsPublic; modsVirtual.SetVirtual(); //System.Type tNativeInt = typeof(int); System.Type tNativeInt = Type.GetType("System.IntPtr"); TypeEntry t_IAsyncResult = s.ResolveCLRTypeToBlueType(typeof(System.IAsyncResult)); // Create the parameters for the BeginInvoke() ParamVarDecl [] paramBeginInvoke = new ParamVarDecl[m_arParams.Length + 2]; m_arParams.CopyTo(paramBeginInvoke, 0); paramBeginInvoke[m_arParams.Length]= new ParamVarDecl( new Identifier("cb"), new ResolvedTypeSig(typeof(System.AsyncCallback), s), EArgFlow.cIn ); paramBeginInvoke[m_arParams.Length + 1] = new ParamVarDecl( new Identifier("state"), new ResolvedTypeSig(typeof(System.Object), s), EArgFlow.cIn ); m_nodeProxy = new ClassDecl( m_idName, new TypeSig[] { new ResolvedTypeSig(typeof(System.MulticastDelegate), s) }, new MethodDecl[] { // Ctor new MethodDecl( m_idName, null, new ParamVarDecl[] { new ParamVarDecl(new Identifier("instance"), new ResolvedTypeSig(typeof(object), s), EArgFlow.cIn), new ParamVarDecl(new Identifier("func"), new ResolvedTypeSig(tNativeInt, s), EArgFlow.cIn) }, stmtEmpty, modsPublic ), // Invoke, new MethodDecl( new Identifier("Invoke"), this.m_tRetType, this.m_arParams, stmtEmpty, modsVirtual), // Begin Invoke new MethodDecl( new Identifier("BeginInvoke"), new ResolvedTypeSig(t_IAsyncResult), paramBeginInvoke, stmtEmpty, modsVirtual), // End Invoke new MethodDecl( new Identifier("EndInvoke"), this.m_tRetType, new ParamVarDecl[] { new ParamVarDecl(new Identifier("result"), new ResolvedTypeSig(t_IAsyncResult), EArgFlow.cIn) }, stmtEmpty, modsVirtual) }, new PropertyDecl[0], new FieldDecl[0], new EventDecl[0], new TypeDeclBase[0], m_mods, true); // isClass }
public EventDecl( Identifier idName, NonRefTypeSig tType, Modifiers mods ) { Debug.Assert(idName != null); Debug.Assert(tType != null); m_idName = idName; m_tType = tType; m_mods = mods; }
public DelegateDecl( Identifier idName, TypeSig tRetType, ParamVarDecl[] arParams, Modifiers mods ) { Debug.Assert(idName != null); Debug.Assert(tRetType != null); Debug.Assert(arParams != null); m_idName = idName; m_tRetType = tRetType; m_arParams = arParams; m_mods = mods; // Implied sealed m_mods.SetSealed(); }
void FixCtors( ISemanticResolver s, ICLRtypeProvider provider ) { // Add default ctor bool fFoundCtor = m_symbol.HasMethodHeader(Name); // Note that structs don't have a default ctor, but can have other ctors // But add a default ctor for classes if we don't have one. if (!fFoundCtor && IsClass) { CtorChainStatement stmtChain = new CtorChainStatement(); Modifiers mods = new Modifiers(); mods.SetPublic(); MethodDecl mdecl = new MethodDecl( new Identifier(Name, this.Location), null, null, new BlockStatement(new LocalVarDecl[0], new Statement[] { stmtChain }), //new AST.Modifiers(AST.Modifiers.EFlags.Public) mods ); stmtChain.FinishInit(mdecl); mdecl.ResolveMember(m_symbol,s, null); mdecl.Symbol.SetInfo(provider); // Add to the end of the m_alMethods array so that we get codegen'ed! AddMethodToList(mdecl); Debug.Assert(m_symbol.HasMethodHeader(Name)); } // @todo - perhaps we could just make the static initializer a static-ctor.. // If we don't have a static ctor, but we do have static data, then add // a static ctor if (m_nodeStaticInit != null) { bool fFoundStaticCtor = false; foreach(MethodDecl m in m_alMethods) { if (m.Mods.IsStatic && m.IsCtor) { fFoundStaticCtor = true; break; } } if (!fFoundStaticCtor) { Modifiers mods = new Modifiers(); mods.SetStatic(); mods.SetPublic(); MethodDecl mdecl2 = new MethodDecl( new Identifier(Name, this.Location), null, null, new BlockStatement(null, new Statement[]{}), //new Modifiers(AST.Modifiers.EFlags.Static | Modifiers.EFlags.Public) mods ); mdecl2.ResolveMember(m_symbol, s, null); mdecl2.Symbol.SetInfo(provider); AddMethodToList(mdecl2); } } // end check static ctor } // fix ctors
// Resolve all the fields in this type. Only class/struct should call // this. void FixFields(ISemanticResolver s, ICLRtypeProvider provider) { Debug.Assert(!IsInterface); int cInstance = 0; int cStatic = 0; foreach(FieldDecl f in m_alFields) { f.ResolveMember(m_symbol, s, provider); //f.Symbol.SetInfo(provider); if (f.InitialExp != null) if (f.Mods.IsStatic) cStatic++; else cInstance++; } Statement [] stmtStatic = new Statement[cStatic]; Statement [] stmtInstance = new Statement[cInstance]; cStatic = 0; cInstance = 0; // Fields can have assignments. Make 2 helper functions to do // assignment for static & instance fields foreach(FieldDecl f in m_alFields) { if (f.InitialExp != null) { Statement stmt = new ExpStatement(new AssignStmtExp( new SimpleObjExp(new Identifier(f.Name, f.Location)), f.InitialExp)); if (f.Mods.IsStatic) { stmtStatic[cStatic] = stmt; cStatic++; } else { if (IsStruct) { //ThrowError_NoFieldInitForStructs(s, f); ThrowError(SymbolError.NoFieldInitForStructs(f)); } stmtInstance[cInstance] = stmt; cInstance ++; } } // end has initializer expression } Debug.Assert(cStatic == stmtStatic.Length); Debug.Assert(cInstance == stmtInstance.Length); // Create methods to initialize the static & instance fields. // Then the ctors can call these methods if (cStatic != 0) { Modifiers mods = new Modifiers(); mods.SetStatic(); mods.SetPrivate(); m_nodeStaticInit = new MethodDecl( new Identifier(".StaticInit", this.Location), new ResolvedTypeSig(typeof(void), s), new ParamVarDecl[0], new BlockStatement(null, stmtStatic), mods ); //AddMethodToList(m_nodeStaticInit); } if (cInstance != 0) { Modifiers mods = new Modifiers(); mods.SetPrivate(); m_nodeInstanceInit = new MethodDecl( new Identifier(".InstanceInit", this.Location), new ResolvedTypeSig(typeof(void), s), new ParamVarDecl[0], new BlockStatement(null, stmtInstance), mods ); AddMethodToList(m_nodeInstanceInit); } } // end fields
// For non-interface types public ClassDecl( Identifier idName, TypeSig [] arSuper, // super class & implemented interfaces MethodDecl [] alMethods, PropertyDecl[] alProperties, FieldDecl[] alFields, EventDecl [] alEvents, TypeDeclBase[] alNestedTypes, Modifiers mods, bool fIsClass // true for class, false for struct ) { Debug.Assert(idName != null); Debug.Assert(alMethods != null); Debug.Assert(alFields != null); Debug.Assert(alProperties != null); Debug.Assert(alEvents != null); m_strName = idName.Text; m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper; m_alNestedTypes = (alNestedTypes == null) ? m_sEmptyTypeList : alNestedTypes; m_alMethods = alMethods; m_alProperties = alProperties; m_alFields = alFields; m_alEvents = alEvents; // @todo - this is wrong m_filerange = idName.Location; if (!fIsClass) // structs are implicitly sealed. mods.SetSealed(); m_mods = mods; m_genre = fIsClass ? TypeEntry.Genre.cClass : TypeEntry.Genre.cStruct; }
// For interface types public ClassDecl( Identifier idName, TypeSig [] arSuper, // super class & implemented interfaces MethodDecl [] alMethods, PropertyDecl[] alProperties, Modifiers mods ) { Debug.Assert(idName != null); Debug.Assert(alMethods != null); m_strName = idName.Text; m_arSuper = (arSuper == null) ? new TypeSig[0] : arSuper; m_alMethods = alMethods; m_alProperties = alProperties; m_alNestedTypes = m_sEmptyTypeList; // @todo - this is wrong m_filerange = idName.Location; //m_mods.FlagSetter = mods.Flags | Modifiers.EFlags.Abstract; m_mods = mods; m_mods.SetAbstract(); m_genre = TypeEntry.Genre.cInterface; }
public EnumDecl(Identifier idName, FieldDecl[] fields, Modifiers mods) { Debug.Assert(fields != null); m_fields = fields; m_idName = idName; m_mods = mods; }