From 71f0fad3f0e1bdd295317ffdd1a2a7009a6004c6 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 13 Mar 2003 06:44:03 +0000 Subject: [PATCH] * ILParser.jay: Create TypeRefs instead of types, define methods. svn path=/trunk/mcs/; revision=12468 --- mcs/ilasm/parser/ChangeLog | 4 + mcs/ilasm/parser/ILParser.jay | 136 +++++++++++++++++++++------------- 2 files changed, 89 insertions(+), 51 deletions(-) diff --git a/mcs/ilasm/parser/ChangeLog b/mcs/ilasm/parser/ChangeLog index 545d9f24656..cbed84ea2af 100644 --- a/mcs/ilasm/parser/ChangeLog +++ b/mcs/ilasm/parser/ChangeLog @@ -1,3 +1,7 @@ +2003-03-11 Jackson Harper + + * ILParser.jay: Create TypeRefs instead of types, define methods. + 2003-03-09 Jackson Harper * ILParser.jay: Set Call Conventions and Implementation Flags diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index 8f197df65d5..ab27ee9e24d 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -430,15 +430,16 @@ nameSpaceHead : D_NAMESPACE name1 classHead : D_CLASS type_attr id extendsClause implClause { if ($4 != null) { - codegen.AddClass ((TypeAttr) $2, (string) $3, $4 as Class, null); + codegen.AddClass ((TypeAttr) $2, (string) $3, + ((TypeRef)$4).Type as Class, null); } else { codegen.AddClass ((TypeAttr)$2, (string) $3, null); } ArrayList impl_list = (ArrayList) $5; if (impl_list != null) { - foreach (Class klass in impl_list) - codegen.CurrentClass.AddImplementedInterface (klass); + foreach (TypeRef type_ref in impl_list) + codegen.CurrentClass.AddImplementedInterface (type_ref.Type as Class); } } ; @@ -496,19 +497,19 @@ classAttr : /* EMPTY */ ; extendsClause : /* EMPTY */ - | K_EXTENDS type_ref {$$ = $2;} + | K_EXTENDS class_ref {$$ = $2;} ; implClause : /* EMPTY */ | K_IMPLEMENTS classNames {$$ = $2; } ; -classNames : classNames COMMA type_ref +classNames : classNames COMMA class_ref { ArrayList class_list = (ArrayList) $1; class_list.Add ($3); } - | type_ref + | class_ref { ArrayList class_list = new ArrayList (); class_list.Add ($1); @@ -550,7 +551,7 @@ classDecl : methodAll fieldDecl : D_FIELD repeatOpt fieldAttr type_ref id atOpt initOpt { codegen.CurrentClass.AddField ((FieldAttr) $3, - (string) $5, (PEAPI.Type) $4); + (string) $5, ((TypeRef) $4).Type); } ; @@ -559,31 +560,51 @@ type_ref : primative_type_ref | external_type_ref ; -primative_type_ref : K_CHAR {$$ = PrimitiveType.Char; } - | K_VOID {$$ = PrimitiveType.Void; } - | K_BOOL {$$ = PrimitiveType.Boolean; } - | K_INT8 {$$ = PrimitiveType.Int8; } - | K_INT16 {$$ = PrimitiveType.Int16; } - | K_INT32 {$$ = PrimitiveType.Int32; } - | K_INT64 {$$ = PrimitiveType.Int64; } - | K_FLOAT32 {$$ = PrimitiveType.Float32; } - | K_FLOAT64 {$$ = PrimitiveType.Float64; } - | K_UNSIGNED K_INT8 {$$ = PrimitiveType.UInt8; } - | K_UNSIGNED K_INT16 {$$ = PrimitiveType.UInt16; } - | K_UNSIGNED K_INT32 {$$ = PrimitiveType.UInt32; } - | K_UNSIGNED K_INT64 {$$ = PrimitiveType.UInt64; } - | K_STRING {$$ = PrimitiveType.String; } +class_ref : internal_type_ref + | external_type_ref + ; + +primative_type_ref : K_CHAR + {$$ = new TypeRef (PrimitiveType.Char, "System.Char"); } + | K_VOID + {$$ = new TypeRef (PrimitiveType.Void, "System.Void"); } + | K_BOOL + {$$ = new TypeRef (PrimitiveType.Boolean, "System.Bool"); } + | K_INT8 + {$$ = new TypeRef (PrimitiveType.Int8, "System.Int8"); } + | K_INT16 + {$$ = new TypeRef (PrimitiveType.Int16, "System.Int16"); } + | K_INT32 + {$$ = new TypeRef (PrimitiveType.Int32, "System.Int32"); } + | K_INT64 + {$$ = new TypeRef (PrimitiveType.Int64, "System.Int64"); } + | K_FLOAT32 + {$$ = new TypeRef (PrimitiveType.Float32, "System.Float32"); } + | K_FLOAT64 + {$$ = new TypeRef (PrimitiveType.Float64, "System.Float64"); } + | K_UNSIGNED K_INT8 + {$$ = new TypeRef (PrimitiveType.UInt8, "System.UInt8"); } + | K_UNSIGNED K_INT16 + {$$ = new TypeRef (PrimitiveType.UInt16, "System.UInt16"); } + | K_UNSIGNED K_INT32 + {$$ = new TypeRef (PrimitiveType.UInt32, "System.UInt32"); } + | K_UNSIGNED K_INT64 + {$$ = new TypeRef (PrimitiveType.UInt64, "System.UInt64"); } + | K_STRING + {$$ = new TypeRef (PrimitiveType.String, "System.String"); } ; internal_type_ref : name1 { - $$ = codegen.ClassTable.GetReference ((string) $1, null); + $$ = new TypeRef (codegen.ClassTable.GetReference ((string) $1, null), + (string) $1); } ; external_type_ref : assembly_name namespace_name DOT id { - $$ = codegen.ExternTable.GetClass ($1 as string, $2 as string, $4 as string); + $$ = new TypeRef (codegen.ExternTable.GetClass ($1 as string, + $2 as string, $4 as string), String.Format ("{0}.{1}", $2, $4)); } ; @@ -670,14 +691,25 @@ propDecl : D_SET callConv type typeSpec DOUBLE_COLON methodName O methodHead : D_METHOD methAttr callConv type_ref methodName OPEN_PARENS arg_list CLOSE_PARENS implAttr OPEN_BRACE { - /* - Console.WriteLine ("Method Attributes: {0}", $2); - Console.WriteLine ("Method CallConv: {0}", $3); - Console.WriteLine ("Method Return Type: {0}", $4); - Console.WriteLine ("Method Name: {0}", $5); - Console.WriteLine ("Method ParamList: {0}", $7); - Console.WriteLine ("Method ImplAttr: {0}", $9); - */ + Param[] param_array; + TypeRef[] typeref_array; + if ($7 != null) { + ArrayList param_list = $7 as ArrayList; + int index = 0; + param_array = new Param[param_list.Count]; + typeref_array = new TypeRef[param_list.Count]; + foreach (DictionaryEntry entry in param_list) { + param_array[index] = entry.Key as Param; + typeref_array[index] = entry.Value as TypeRef; + index++; + } + } else { + param_array = new Param[0]; + typeref_array = new TypeRef[0]; + } + + codegen.AddMethod ((MethAttr) $2, (ImplAttr) $9, (CallConv) $3, (string) $5, + (TypeRef) $4, param_array, typeref_array, null); } | methodHeadPart1 methAttr callConv paramAttr type K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS methodName OPEN_PARENS sigArgs0 CLOSE_PARENS implAttr OPEN_BRACE ; @@ -736,11 +768,11 @@ methodName : D_CTOR | name1 ; -paramAttr : /* EMPTY */ - | paramAttr OPEN_BRACKET K_IN CLOSE_BRACKET - | paramAttr OPEN_BRACKET K_OUT CLOSE_BRACKET - | paramAttr OPEN_BRACKET K_OPT CLOSE_BRACKET - | paramAttr OPEN_BRACKET int32 CLOSE_BRACKET +paramAttr : /* EMPTY */ {$$ = ParamAttr.Default; } + | paramAttr OPEN_BRACKET K_IN CLOSE_BRACKET {$$ = (ParamAttr) $1 | ParamAttr.In; } + | paramAttr OPEN_BRACKET K_OUT CLOSE_BRACKET {$$ = (ParamAttr) $1 | ParamAttr.Out; } + | paramAttr OPEN_BRACKET K_OPT CLOSE_BRACKET {$$ = (ParamAttr) $1 | ParamAttr.Opt; } + /* | paramAttr OPEN_BRACKET int32 CLOSE_BRACKET */ ; fieldAttr : /* EMPTY */ {$$ = FieldAttr.Default; } @@ -767,7 +799,7 @@ fieldAttr : /* EMPTY */ {$$ = FieldAttr.Default; } ; -implAttr : /* empty */ +implAttr : /* empty */ {$$ = new ImplAttr (); } | implAttr K_NATIVE {$$ = (ImplAttr) $1 | ImplAttr.Native; } | implAttr K_IL {$$ = (ImplAttr) $1 | ImplAttr.IL; } | implAttr K_CIL { /* Do nothing */ } @@ -1006,26 +1038,28 @@ instr : INSTR_NONE {/* currentInstr = new InstrNone ((OpCode) | INSTR_PHI int16s ; -full_type - : type - | ID { $$ = $1; } - | assembly_name name1 { $$ = String.Format ("[{0}]{1}", $1, $2); } - ; +param_name : /* EMPTY */ + | name1 + ; arg_list : /* EMPTY */ - | full_type + | paramAttr type_ref param_name { ArrayList arg_list = new ArrayList (); - arg_list.Add ($1); - + Param param = new Param ((ParamAttr) $1, $3 as string, ((TypeRef) $2).Type); + DictionaryEntry entry = new DictionaryEntry (param, $2); + + arg_list.Add (entry); $$ = arg_list; } - | arg_list COMMA type + | arg_list COMMA paramAttr type_ref param_name { ArrayList arg_list = (ArrayList) $1; - arg_list.Add ($3); - + Param param = new Param ((ParamAttr) $3, $5 as string, ((TypeRef) $4).Type); + DictionaryEntry entry = new DictionaryEntry (param, $4); + + arg_list.Add (entry); $$ = arg_list; } ; @@ -1073,8 +1107,8 @@ sigArgs1 : sigArg | sigArgs1 COMMA sigArg { $$ = String.Format ("{0},{1}", $1, $2); } ; -sigArg : ELLIPSIS - | paramAttr type +sigArg : ELLIPSIS + | paramAttr type_ref | paramAttr type id { $$ = String.Format ("{0} {1}", $2, $3); } | paramAttr type K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS | paramAttr type K_MARSHAL OPEN_PARENS nativeType CLOSE_PARENS id @@ -1124,7 +1158,7 @@ callConv : K_INSTANCE callConv { $$ = (CallConv) $1 | CallConv.In | callKind ; -callKind : /* EMPTY */ +callKind : /* EMPTY */ { $$ = CallConv.Default; } | K_DEFAULT { $$ = (CallConv) $1 | CallConv.Default; } | K_VARARG { $$ = (CallConv) $1 | CallConv.Vararg; } | K_UNMANAGED K_CDECL { $$ = (CallConv) $1 | CallConv.Cdecl; } -- 2.25.1