//----------------------------------------------------------------------------- // Structs & Interfaces can only derive from interfaces //----------------------------------------------------------------------------- public static SymbolErrorException MustDeriveFromInterface(ClassDecl nodeThis, TypeEntry tBase) { return new SymbolErrorException( Code.cMustDeriveFromInterface, nodeThis.Location, "'" + tBase.FullName + "' is not an interface and so it can't be in the base-list for '" + nodeThis.Name +"'"); }
//----------------------------------------------------------------------------- // C# only supports single inheritence. //----------------------------------------------------------------------------- public static SymbolErrorException OnlySingleInheritence(ClassDecl c) { return new SymbolErrorException( Code.cOnlySingleInheritence, c.Location, "Can only derive from a single class (For multiple inheritence, use interfaces)" ); }
//----------------------------------------------------------------------------- // The class must be abstract. //----------------------------------------------------------------------------- public static SymbolErrorException ClassMustBeAbstract( ClassDecl node) { return new SymbolErrorException( Code.cClassMustBeAbstract, node.Location, "The class '"+node.Symbol.FullName + "' must be abstract because it contains abstract members."); }
// 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 }
// Any of the array parameters may be null public NamespaceDecl( Identifier idName, // must be non-null UsingDirective [] arUsingDirectives, NamespaceDecl[] arNestedNamespaces, ClassDecl[] arClasses, TypeDeclBase[] arTypes ) { m_idName = idName; m_arUsingDirectives = (arUsingDirectives == null) ? new UsingDirective [0] : arUsingDirectives; m_arNestedNamespaces = (arNestedNamespaces == null) ? new NamespaceDecl[0] : arNestedNamespaces; //m_arClasses = (arClasses == null) ? new ClassDecl[0] : arClasses; Debug.Assert(arClasses == null); m_arTypes = (arTypes == null) ? new TypeDeclBase[0] : arTypes; }
//----------------------------------------------------------------------------- // Parse an interface // // ** rules ** // InterfaceDecl-> 'interface' id:name '{' body '}' // InterfaceDecl-> 'interface' id:name ':' base_list '{' body '}' //----------------------------------------------------------------------------- protected ClassDecl ParseInterface(Modifiers modsInterface) { Token t; ReadExpectedToken(Token.Type.cInterface); Identifier idName = ReadExpectedIdentifier(); TypeSig[] arBase = null; //if (!modsInterface.IsPublic) //modsInterface.FlagSetter |= Modifiers.EFlags.Private; if (modsInterface.VisibilityNotSet) modsInterface.SetPrivate(); ArrayList alMethods = new ArrayList(); ArrayList alProperties = new ArrayList(); // Read list of base interfaces that we derive from t = m_lexer.PeekNextToken(); if (t.TokenType == Token.Type.cColon) { ConsumeNextToken(); // ':' arBase = ParseIdNameList(); } ReadExpectedToken(Token.Type.cLCurly); // Read members t = m_lexer.PeekNextToken(); while(t.TokenType != Token.Type.cRCurly) { // member: // method -> rettype id:name '(' param_list ')' ';' // property -> rettype id:name '{' set ';' get ';' '}' TypeSig rettype = ParseTypeSig(); Identifier idMember = ReadExpectedIdentifier(); t = m_lexer.PeekNextToken(); // All interface members have these attributes /* AST.Modifiers mods = new AST.Modifiers( AST.Modifiers.EFlags.Abstract | AST.Modifiers.EFlags.Virtual | AST.Modifiers.EFlags.Public ); */ Modifiers mods = new Modifiers(); mods.SetAbstract(); mods.SetVirtual(); mods.SetPublic(); // Method if (t.TokenType == Token.Type.cLParen) { MemberDecl m = this.PartialParseMethodDecl(mods, rettype, idMember, Genre.cInterface); alMethods.Add(m); } // Property else if (t.TokenType == Token.Type.cLCurly) { PropertyDecl p = PartialParsePropertyDecl(mods, rettype, idMember); alProperties.Add(p); } // Indexer else if (t.TokenType == Token.Type.cLSquare) { PropertyDecl p = PartialParseIndexerDecl(mods, rettype, idMember); alProperties.Add(p); } // Error else { //this.ThrowError_UnexpectedToken(t); ThrowError(E_UnexpectedToken(t)); } t = m_lexer.PeekNextToken(); } ReadExpectedToken(Token.Type.cRCurly); // '}' MethodDecl [] arMethods = this.MethodDeclFromArray(alMethods); PropertyDecl [] arProperties = this.PropertyDeclFromArray(alProperties); ClassDecl d = new ClassDecl(idName, arBase, arMethods, arProperties, modsInterface); return d; }