From 22a6b7b6395a2f7704d5077f6e28c0b6f6cabbf9 Mon Sep 17 00:00:00 2001
From: Johannes Mey <johannes.mey@tu-dresden.de>
Date: Fri, 7 Apr 2017 12:59:21 +0200
Subject: [PATCH] change handling of comments: now, a comment can have multiple
 lines

---
 Parser/spec/parser/Fortran2008.rats           | 21 +++++--------
 Parser/spec/parser/OpenAcc.rats               | 30 +++++++++----------
 Parser/spec/printer/Printing.jadd             | 16 +++++-----
 Parser/spec/semantics/Types.jrag              |  2 +-
 .../B_Designator_OR_FunctionReference.f90     |  3 +-
 5 files changed, 34 insertions(+), 38 deletions(-)

diff --git a/Parser/spec/parser/Fortran2008.rats b/Parser/spec/parser/Fortran2008.rats
index 9cc8d46..6a96484 100644
--- a/Parser/spec/parser/Fortran2008.rats
+++ b/Parser/spec/parser/Fortran2008.rats
@@ -91,21 +91,14 @@ CommentConstruct comment_construct =
 //// CommentExternalSubprogram:ExternalSubprogram ::= Comment ;
 
 
-//// Comment ::= [CommentContent] ;
+//// Comment ::= CommentContent* ;
 //// CommentContent ::= <String> ;
 Comment comment =
-    EXCLAMATIONMARK c:COMMENT_CONTENT LB
-        {
-            yyValue = new Comment(new Opt<CommentContent>(new CommentContent(c)));
-        }
-/   SS LB
-        {
-            yyValue = new Comment(new Opt<CommentContent>());
-        }
-/   SS SEMICOLON
-        {
-            yyValue = new Comment(new Opt<CommentContent>());
-        }
+    l:(
+        EXCLAMATIONMARK s:COMMENT_CONTENT LB {yyValue = new CommentContent(s); }
+      / SS LB { yyValue = new CommentContent(""); }
+      / SS SEMICOLON { yyValue = new CommentContent(""); }
+    )+ { yyValue = new Comment(new List<CommentContent>().addAll(((Pair) l).list())); }
 ;
 
 // =============================================================================
@@ -4910,7 +4903,7 @@ EndIfStmt end_if_stmt =
 IfStmt if_stmt =
     IF LPAREN e:expr RPAREN s:action_stmt
         {
-            yyValue = new IfStmt(new Opt<Label>(), new Comment(new Opt<CommentContent>()), e, s);
+            yyValue = new IfStmt(new Opt<Label>(), new Comment(new List<CommentContent>()), e, s);
         }
 ;
 
diff --git a/Parser/spec/parser/OpenAcc.rats b/Parser/spec/parser/OpenAcc.rats
index 9f5a623..768563f 100644
--- a/Parser/spec/parser/OpenAcc.rats
+++ b/Parser/spec/parser/OpenAcc.rats
@@ -377,11 +377,11 @@ AccDirective acc_directive =
 AccEnterDataDirective acc_enter_data_directive =
 	A_P A_ENTER A_DATA clauses:acc_clause_list LB
 		{
-			yyValue = new AccEnterDataDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), clauses);
+			yyValue = new AccEnterDataDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), clauses);
 		}
 /	A_P A_ENTER A_DATA LB
 		{
-			yyValue = new AccEnterDataDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), new List());
+			yyValue = new AccEnterDataDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), new List());
 		}
 ;
 
@@ -389,11 +389,11 @@ AccEnterDataDirective acc_enter_data_directive =
 AccExitDataDirective acc_exit_data_directive =
 	A_P A_EXIT A_DATA clauses:acc_clause_list LB
 		{
-			yyValue = new AccExitDataDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), clauses);
+			yyValue = new AccExitDataDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), clauses);
 		}
 /	A_P A_EXIT A_DATA LB
 		{
-			yyValue = new AccExitDataDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), new List());
+			yyValue = new AccExitDataDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), new List());
 		}
 ;
 
@@ -402,7 +402,7 @@ AccExitDataDirective acc_exit_data_directive =
 AccCacheDirective acc_cache_directive =
 	A_P A_CACHE list:p_var_list LB
 		{
-			yyValue = new AccCacheDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), list);
+			yyValue = new AccCacheDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), list);
 		}
 ;
 
@@ -411,11 +411,11 @@ AccCacheDirective acc_cache_directive =
 AccUpdateDirective acc_update_directive =
 	A_P A_UPDATE clauses:acc_clause_list LB
 		{
-			yyValue = new AccUpdateDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), clauses);
+			yyValue = new AccUpdateDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), clauses);
 		}
 /	A_P A_UPDATE LB
 		{
-			yyValue = new AccUpdateDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), new List());
+			yyValue = new AccUpdateDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), new List());
 		}
 ;
 
@@ -426,11 +426,11 @@ AccUpdateDirective acc_update_directive =
 AccDeclareDirective acc_declare_directive =
 	A_P A_DECLARE clauses:acc_clause_list LB
 		{
-			yyValue = new AccDeclareDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), clauses);
+			yyValue = new AccDeclareDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), clauses);
 		}
 /	A_P A_DECLARE LB
 		{
-			yyValue = new AccDeclareDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), new List());
+			yyValue = new AccDeclareDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), new List());
 		}
 ;
 
@@ -440,12 +440,12 @@ AccRoutineDirective acc_routine_directive =
  	A_P A_ROUTINE n:(LPAREN yyValue:name RPAREN)? clauses:acc_clause_list LB
 		{
 		    Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n);
-			yyValue = new AccRoutineDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), n_opt, clauses);
+			yyValue = new AccRoutineDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), n_opt, clauses);
 		}
 /	A_P A_ROUTINE n:(LPAREN yyValue:name RPAREN) LB
 		{
 		    Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n);
-			yyValue = new AccRoutineDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), n_opt, new List());
+			yyValue = new AccRoutineDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), n_opt, new List());
 		}
 ;
 
@@ -454,19 +454,19 @@ AccRoutineDirective acc_routine_directive =
 AccWaitDirective acc_wait_directive =
 	A_P A_WAIT clauses:acc_clause_list LB
 		{
-			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), new List(), clauses);
+			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), new List(), clauses);
 		}
 /	A_P A_WAIT LPAREN list:expr_list RPAREN clauses:acc_clause_list LB
 		{
-			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), list, clauses);
+			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), list, clauses);
 		}
 /	A_P A_WAIT LB
 		{
-			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), new List(), new List());
+			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), new List(), new List());
 		}
 /	A_P A_WAIT  LPAREN list:expr_list RPAREN LB
 		{
-			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new Opt<CommentContent>()), list, new List());
+			yyValue = new AccWaitDirective(new Opt<Label>(), new Comment(new List<CommentContent>()), list, new List());
 		}
 ;
 
diff --git a/Parser/spec/printer/Printing.jadd b/Parser/spec/printer/Printing.jadd
index d28ebe2..2a6a817 100644
--- a/Parser/spec/printer/Printing.jadd
+++ b/Parser/spec/printer/Printing.jadd
@@ -36,14 +36,16 @@ class PrettyPrint {
     }
 
     public void Comment.prettyPrint(PrettyPrinter s){
-        if (hasCommentContent()) {
-            s.ensureWs();
-            s.append("!");
-            getCommentContent().prettyPrint(s);
-        } else {
-            s.append("");
+        for (CommentContent cc : getCommentContentList()) {
+            if (!cc.getString().trim().isEmpty()) {
+                s.ensureWs();
+                s.append("!");
+                cc.prettyPrint(s);
+            } else {
+                s.append("");
+            }
+            s.lb();
         }
-        s.lb();
     }
 
     public void CommentContent.prettyPrint(PrettyPrinter s) {
diff --git a/Parser/spec/semantics/Types.jrag b/Parser/spec/semantics/Types.jrag
index 17fa1be..1be4696 100644
--- a/Parser/spec/semantics/Types.jrag
+++ b/Parser/spec/semantics/Types.jrag
@@ -415,4 +415,4 @@ aspect Types {
   eq BlockData.getEndBlockDataStmt().enclosingScope() = this;
 
   // TODO do not forget the COMMON block
-}
\ No newline at end of file
+}
diff --git a/Parser/test-data/rewrites/B_Designator_OR_FunctionReference.f90 b/Parser/test-data/rewrites/B_Designator_OR_FunctionReference.f90
index efbe7a8..164d067 100644
--- a/Parser/test-data/rewrites/B_Designator_OR_FunctionReference.f90
+++ b/Parser/test-data/rewrites/B_Designator_OR_FunctionReference.f90
@@ -2,12 +2,13 @@
 
 TYPE FULLNAME
   CHARACTER (LEN = 50) FIRST,LAST
-  
+
 END TYPE PERSON
 
 TYPE PERSON
   INTEGER AGE
   TYPE (FULLNAME) NAME
+  
 END TYPE PERSON
 
 TYPE (PERSON) :: CHAIRMAN
-- 
GitLab