From 163b651cd6bb6ed2e497cb945dc5ad0e98318f17 Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Fri, 7 Jan 2011 16:18:47 +0100 Subject: [PATCH] change class_base to be a list of ^(IMPLEMENTS type). Easier to convert first to EXTENDS if its a class --- .../antlr3/src/cs2j/CSharp/JavaMaker.g | 8 ++++---- .../antlr3/src/cs2j/CSharp/JavaPrettyPrint.g | 16 ++++++++++++---- .../antlr3/src/cs2j/CSharp/NetMaker.g | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g index 8ef9128..6702a70 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaMaker.g @@ -869,10 +869,10 @@ type_parameter returns [string name]: class_base: // just put all types in a single list. In NetMaker we will extract the base class if necessary - ':' interface_type_list -> ^(IMPLEMENTS interface_type_list); + ':' ts+=type (',' ts+=type)* -> ^(IMPLEMENTS $ts)*; -interface_type_list: - ts+=type (',' ts+=type)* -> $ts+; +//interface_type_list: +// ts+=type (',' ts+=type)* -> $ts+; class_body: '{' class_member_declarations? '}' ; @@ -1163,7 +1163,7 @@ scope TypeContext; -> ^(INTERFACE[$c.Token] identifier type_parameter_constraints_clauses? variant_generic_parameter_list? interface_base? interface_body ); interface_base: - ':' interface_type_list -> ^(EXTENDS interface_type_list); + ':' ts+=type (',' ts+=type)* -> ^(IMPLEMENTS $ts)*; interface_modifiers: modifier+ ; diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g index 64ead39..59caa6e 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/JavaPrettyPrint.g @@ -221,8 +221,9 @@ compilation_unit initPrecedence(); } : - ^(PACKAGE nm=PAYLOAD modifiers? type_declaration[$modifiers.st] { if (IsLast) collectComments(); }) -> - package(now = {DateTime.Now}, includeDate = {Cfg.TranslatorAddTimeStamp}, packageName = {($nm.text != null && $nm.text.Length > 0 ? $nm.text : null)}, + ^(PACKAGE nm=PAYLOAD imports? modifiers? type_declaration[$modifiers.st] { if (IsLast) collectComments(); }) -> + package(now = {DateTime.Now}, includeDate = {Cfg.TranslatorAddTimeStamp}, packageName = {($nm.text != null && $nm.text.Length > 0 ? $nm.text : null)}, + imports = {$imports.st}, type = {$type_declaration.st}, endComments = { CollectedComments }); @@ -247,6 +248,11 @@ modifier (m='new' | m='public' | m='protected' | m='private' | m='abstract' | m='sealed' | m='static' | m='readonly' | m='volatile' | m='extern' { thetext = "/* [UNSUPPORTED] 'extern' modifier not supported */"; } | m='virtual' | m='override' | m=FINAL) -> string(payload={ (thetext == null ? $m.text : thetext) }); + +imports: + imps+=importns+ -> seplist(items = { $imps }, sep= { "\n" }); +importns: + IMPORT PAYLOAD -> import_template(ns = { $PAYLOAD.text }); class_member_declaration returns [List preComments]: ^(CONST attributes? modifiers? type { $preComments = CollectedComments; } constant_declarators) @@ -831,9 +837,11 @@ type_parameter [Dictionary tpConstraints] identifier {if (tpConstraints == null || !tpConstraints.TryGetValue($identifier.text, out mySt)) {mySt = $identifier.st;}; } -> { mySt } ; class_extends: - ^(EXTENDS ts+=type*) -> extends(types = { $ts }) ; + ^(EXTENDS ts=type) -> extends(types = { $ts.st }) ; class_implements: - ^(IMPLEMENTS ts+=type*) -> imps(types = { $ts }) ; + ts+=class_implement+ -> imps(types = { $ts }) ; +class_implement: + ^(IMPLEMENTS ts=type) -> seplist(items = { $ts.st }, sep={", "}) ; interface_type_list: ts+=type (',' ts+=type)* -> commalist(items={ $ts }); diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g index 1812ba0..b8f0744 100644 --- a/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g +++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/NetMaker.g @@ -535,10 +535,18 @@ type_parameter_list: type_parameter: identifier ; -class_extends: - ^(EXTENDS type*) ; +//class_extends: +// ^(EXTENDS type*) ; + +// If first implements type is a class then convert to extends class_implements: - ^(IMPLEMENTS type*) ; + class_implement_or_extend class_implement* ; + +class_implement_or_extend: + ^(i=IMPLEMENTS type) -> ^(EXTENDS[$i.token, "extends"] type); + +class_implement: + ^(IMPLEMENTS type) ; interface_type_list: type (',' type)* ; @@ -678,7 +686,7 @@ parameter_array: /////////////////////////////////////////////////////// interface_declaration: ^(INTERFACE identifier type_parameter_constraints_clauses? variant_generic_parameter_list? - class_extends? interface_body ) ; + class_implements? interface_body ) ; interface_modifiers: modifier+ ; interface_base: