dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] pnet ChangeLog ilasm/ilasm_build.c ilasm/ilasm_...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog ilasm/ilasm_build.c ilasm/ilasm_...
Date: Sat, 21 Jul 2007 13:05:07 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      07/07/21 13:05:07

Modified files:
        .              : ChangeLog 
        ilasm          : ilasm_build.c ilasm_build.h ilasm_grammar.y 
                         ilasm_scanner.l 
        image          : class.c 

Log message:
        Add support for resolving generic parameters by name. Fix a bug in
        ILClassSetParent.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3480&r2=1.3481
http://cvs.savannah.gnu.org/viewcvs/pnet/ilasm/ilasm_build.c?cvsroot=dotgnu-pnet&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/pnet/ilasm/ilasm_build.h?cvsroot=dotgnu-pnet&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/pnet/ilasm/ilasm_grammar.y?cvsroot=dotgnu-pnet&r1=1.48&r2=1.49
http://cvs.savannah.gnu.org/viewcvs/pnet/ilasm/ilasm_scanner.l?cvsroot=dotgnu-pnet&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/pnet/image/class.c?cvsroot=dotgnu-pnet&r1=1.36&r2=1.37

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3480
retrieving revision 1.3481
diff -u -b -r1.3480 -r1.3481
--- ChangeLog   20 Jul 2007 20:11:54 -0000      1.3480
+++ ChangeLog   21 Jul 2007 13:05:06 -0000      1.3481
@@ -1,3 +1,19 @@
+2007-07-21  Klaus Treichel  <address@hidden>
+
+       * ilasm/ilasm_build.h, ilasm/ilasm_build.h: Add the functions for 
resolving
+       generic parameters by name.
+
+       * ilasm/ilasm_grammar.y: Add the D_STACKRESERVE keyword and add the
+       resolution of generic parameters by name (which is undocumented in the 
ECMA
+       specs but supported by MS ilasm). The resolution of method generic
+       parameters by name in method parameters and returntypes is still TODO.
+
+       * ilasm/ilasm_scanner.l: Add the keyword D_STACKRESERVE (.stackreserve 
is
+       in the output of MS ildasm).
+
+       * image/class.c: Import the parent class in to the image of the subclass
+       instead of it's own image.
+
 2007-07-20  Klaus Treichel  <address@hidden>
 
        * image/writer.c: Get the default metadata version string from the 
profile

Index: ilasm/ilasm_build.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ilasm/ilasm_build.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- ilasm/ilasm_build.c 17 Jul 2007 17:30:29 -0000      1.31
+++ ilasm/ilasm_build.c 21 Jul 2007 13:05:07 -0000      1.32
@@ -1151,13 +1151,100 @@
        if(!genPar)
        {
                ILAsmPrintMessage(ILAsmFilename, ILAsmLineNum,
-                 "no generic parameter parameter numbered %lu for the current 
method",
+                 "no generic parameter numbered %lu for the current method",
                                                  (unsigned long)paramNum);
                ILAsmErrors = 1;
        }
        return genPar;
 }
 
+static ILGenericPar *FindGenericParByName(ILProgramItem *owner, const char 
*name)
+{
+       ILUInt32 parNum = 0;
+       ILGenericPar *par;
+
+       while((par = ILGenericParGetFromOwner(owner, parNum)) != 0)
+       {
+               if(!strcmp(ILGenericParGetName(par), name))
+               {
+                       return par;
+               }
+               parNum++;
+       }
+       return 0;
+}
+
+ILGenericPar *ILAsmResolveGenericPar(ILProgramItem *scope, const char *name)
+{
+       return FindGenericParByName(scope, name);
+}
+
+ILType *ILAsmResolveGenericClassPar(ILProgramItem *scope, const char *name)
+{
+       ILClass *info;
+
+       if((info = ILProgramItemToClass(scope)) == 0)
+       {
+               /* We might be in a method declaration */
+               ILMethod *method;
+
+               if((method = ILProgramItemToMethod(scope)) != 0)
+               {
+                       info = ILMethod_Owner(method);
+               }
+       }
+       if(info)
+       {
+               ILGenericPar *par = FindGenericParByName(ILToProgramItem(info), 
name);
+
+               if(par)
+               {
+                       return ILTypeCreateVarNum(ILAsmContext,
+                                                                         
IL_TYPE_COMPLEX_VAR,
+                                                                         
ILGenericParGetNumber(par));
+               }
+               ILAsmPrintMessage(ILAsmFilename, ILAsmLineNum,
+                         "no generic class parameter with the name %s in the 
current class",
+                                                 name);
+               ILAsmErrors = 1;
+       }
+       else
+       {
+               ILAsmPrintMessage(ILAsmFilename, ILAsmLineNum,
+                         "generic class parameter reference outside a class");
+               ILAsmErrors = 1;
+       }
+       return 0;
+}
+
+ILType *ILAsmResolveGenericMethodPar(ILProgramItem *scope, const char *name)
+{
+       ILMethod *method;
+
+       if((method = ILProgramItemToMethod(scope)) != 0)
+       {
+               ILGenericPar *par = FindGenericParByName(scope, name);
+
+               if(par)
+               {
+                       return ILTypeCreateVarNum(ILAsmContext,
+                                                                         
IL_TYPE_COMPLEX_MVAR,
+                                                                         
ILGenericParGetNumber(par));
+               }
+               ILAsmPrintMessage(ILAsmFilename, ILAsmLineNum,
+                         "no generic method parameter with the name %s in the 
current method",
+                                                 name);
+               ILAsmErrors = 1;
+       }
+       else
+       {
+               ILAsmPrintMessage(ILAsmFilename, ILAsmLineNum,
+                         "generic method parameter reference outside a 
method");
+               ILAsmErrors = 1;
+       }
+       return 0;
+}
+
 void ILAsmAddSemantics(int type, ILToken token)
 {
        if(token)

Index: ilasm/ilasm_build.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ilasm/ilasm_build.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- ilasm/ilasm_build.h 3 Jul 2007 20:25:26 -0000       1.15
+++ ilasm/ilasm_build.h 21 Jul 2007 13:05:07 -0000      1.16
@@ -235,6 +235,7 @@
  */
 ILParameter *ILAsmFindParameter(ILMethod *method, ILUInt32 paramNum);
 
+
 /*
  * Find the generic parameter with the 0 based paramNum for the class or
  * method.
@@ -244,6 +245,32 @@
                                                                                
ILUInt32 paramNum);
 
 /*
+ * Resolve the generic parameter for the scope by name.
+ * Returns NULL if there is no generic parameter with the given name
+ * for the scope.
+ */
+ILGenericPar *ILAsmResolveGenericPar(ILProgramItem *scope,
+                                                                        const 
char *name);
+
+/*
+ * Create a generic class var type reference to the generic class parameter
+ * with the given name.
+ * Returns 0 if the scope is not in a class or a generic parameter with the
+ * name could not be found.
+ */
+ILType *ILAsmResolveGenericClassPar(ILProgramItem *scope,
+                                                                       const 
char *name);
+
+/*
+ * Create a generic method var type reference to the generic method parameter
+ * with the given name.
+ * Returns 0 if the scope is not a method or a generic parameter with the
+ * name could not be found.
+ */
+ILType *ILAsmResolveGenericMethodPar(ILProgramItem *scope,
+                                                                        const 
char *name);
+
+/*
  * Add semantics to an event or property.
  */
 void ILAsmAddSemantics(int type, ILToken token);

Index: ilasm/ilasm_grammar.y
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ilasm/ilasm_grammar.y,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- ilasm/ilasm_grammar.y       8 Jul 2007 20:13:38 -0000       1.48
+++ ilasm/ilasm_grammar.y       21 Jul 2007 13:05:07 -0000      1.49
@@ -821,6 +821,7 @@
 %token D_REMOVEON                      "`.removeon'"
 %token D_SET                           "`.set'"
 %token D_SIZE                          "`.size'"
+%token D_STACKRESERVE          "`.stackreserve'"
 %token D_SUBSYSTEM                     "`.subsystem'"
 %token D_TITLE                         "`.title'"
 %token D_TRY                           "`.try'"
@@ -1068,7 +1069,7 @@
 %type <opcode>         I_NEWARRAY I_MULTINEWARRAY
 %type <floatValue>     Float64 InstructionFloat
 %type <byteList>       ByteList
-%type <classInfo>      ExtendsClause ClassName CatchClause ClassNameTypeSpec
+%type <classInfo>      ClassName CatchClause ClassNameTypeSpec
 %type <type>           Type ArrayBounds Bounds
 %type <marshType>      MarshalledType
 %type <typeSpec>       TypeSpecification
@@ -1162,6 +1163,7 @@
        | D_CORFLAGS INTEGER_CONSTANT
        | D_IMAGEBASE INTEGER_CONSTANT
        | D_FILE K_ALIGNMENT INTEGER_CONSTANT
+       | D_STACKRESERVE INTEGER_CONSTANT
        ;
 
 LanguageDeclaration
@@ -1381,13 +1383,13 @@
  */
 
 ClassHeading
-       : D_CLASS ClassAttributes Identifier FormalGenericParamsOpt 
ExtendsClause {
+       : D_CLASS ClassAttributes Identifier FormalGenericParamsOpt {
                                /* Create the new class */
                                ILAsmBuildNewClass($3.string, $4.paramFirst,
-                                                                  $5, 
(ILUInt32)($2));
+                                                                  0, 
(ILUInt32)($2));
                                ILAsmBuildPushScope(ILAsmClass);
                        }
-         ImplementsClause
+         ExtendsClause ImplementsClause
        ;
 
 FormalGenericParamsOpt
@@ -1507,6 +1509,17 @@
                                        ILAsmLastToken = 
ILProgramItem_Token(ILToProgramItem(genPar));
                                }
                        }
+       | D_PARAM K_TYPE Identifier                     {
+                               ILGenericPar *genPar;
+                               genPar = 
ILAsmResolveGenericPar(ILToProgramItem(ILAsmCurrScope),
+                                                                               
                ($3).string);
+                               if(genPar)
+                               {
+                                       /* Set the last token, to allow custom 
attributes
+                                          to be attached to the parameter */
+                                       ILAsmLastToken = 
ILProgramItem_Token(ILToProgramItem(genPar));
+                               }
+                       }
        ;
 
 ClassAttributes
@@ -1557,11 +1570,10 @@
 ExtendsClause
        : /* empty */                   {
                                /* Probably "System.Object" or an interface */
-                               $$ = 0;
                        }
        | K_EXTENDS ClassNameTypeSpec   {
                                /* Extend a named class */
-                               $$ = $2;
+                               ILClassSetParent(ILAsmClass, $2);
                        }
        ;
 
@@ -3223,11 +3235,19 @@
                                $$ = ILTypeCreateVarNum
                                                (ILAsmContext, 
IL_TYPE_COMPLEX_VAR, (int)($2));
                        }
+       | '!' Identifier                                {
+                               /* Reference to a class generic parameter */
+                               $$ = 
ILAsmResolveGenericClassPar(ILAsmCurrScope, ($2).string);
+                       }
        | EXCL_EXCL Integer32                                   {
                                /* Reference to a method generic parameter */
                                $$ = ILTypeCreateVarNum
                                                (ILAsmContext, 
IL_TYPE_COMPLEX_MVAR, (int)($2));
                        }
+       | EXCL_EXCL Identifier                  {
+                               /* Reference to a method generic parameter */
+                               $$ = 
ILAsmResolveGenericMethodPar(ILAsmCurrScope, ($2).string);
+                       }
        | Type '<' ActualGenericParams '>'      {
                                /* Reference to a generic type instantiation */
                                ($3)->un.method__.retType__ = $1;

Index: ilasm/ilasm_scanner.l
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ilasm/ilasm_scanner.l,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- ilasm/ilasm_scanner.l       8 Jul 2007 20:13:39 -0000       1.16
+++ ilasm/ilasm_scanner.l       21 Jul 2007 13:05:07 -0000      1.17
@@ -322,6 +322,7 @@
 <INITIAL,JAVAMODE>".removeon"                  { return D_REMOVEON; }
 <INITIAL,JAVAMODE>".set"                               { return D_SET; }
 <INITIAL,JAVAMODE>".size"                              { return D_SIZE; }
+<INITIAL,JAVAMODE>".stackreserve"              { return D_STACKRESERVE; }
 <INITIAL,JAVAMODE>".subsystem"                 { return D_SUBSYSTEM; }
 <INITIAL,JAVAMODE>".title"                             { return D_TITLE; }
 <INITIAL,JAVAMODE>".try"                               { return D_TRY; }

Index: image/class.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/class.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- image/class.c       15 Jul 2007 19:55:24 -0000      1.36
+++ image/class.c       21 Jul 2007 13:05:07 -0000      1.37
@@ -600,7 +600,7 @@
                return;
        }
 
-       image = ILClassToImage(parent);
+       image = ILClassToImage(info);
        parent = ILClassImport(image, parent);
        info->parent = parent;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]