From e1869741eb8ce17dea8ee2371578ac0b9941c5da Mon Sep 17 00:00:00 2001 From: Johannes Mey <johannes.mey@tu-dresden.de> Date: Fri, 1 Jul 2016 17:51:32 +0200 Subject: [PATCH] rewrite of loop contructs --- Parser/spec/Fortran2008.rats | 95 +++++++++++++++++++++--------------- Parser/spec/OpenAcc.rats | 2 +- Parser/spec/OpenMp.rats | 2 +- Parser/spec/Printing.jadd | 56 ++++++++++++++++++--- 4 files changed, 108 insertions(+), 47 deletions(-) diff --git a/Parser/spec/Fortran2008.rats b/Parser/spec/Fortran2008.rats index 410beee..c2571b7 100644 --- a/Parser/spec/Fortran2008.rats +++ b/Parser/spec/Fortran2008.rats @@ -4608,81 +4608,98 @@ EndCriticalStmt end_critical_stmt = //// abstract DoConstruct:ExecutableConstruct ; DoConstruct do_construct = <BEGINNING> - block_do_concurrent_construct -/ block_do_while_construct -/ block_do_construct + block_do_construct ; //// // R814 -//// BlockDoConstruct:DoConstruct ::= DoStmt DoBlock EndDo ; +//// BlockDoConstruct:DoConstruct ::= DoBlock EndDo ; BlockDoConstruct block_do_construct = - s:do_stmt b:do_block e:end_do +<BEGINNING> + do_concurrent_construct +/ do_while_construct +/ simple_do_construct +/ infinite_do_construct +; + +//// SimpleDoConstruct:BlockDoConstruct ::= DoStmt:SimpleDoStmt DoBlock EndDo ; +SimpleDoConstruct simple_do_construct = + s:simple_do_stmt b:do_block e:end_do { - yyValue = new BlockDoConstruct(s, b, e); + yyValue = new SimpleDoConstruct(s, b, e); } ; -//// BlockDoConcurrentConstruct:DoConstruct ::= DoStmt DoBlock EndDo ; -BlockDoConcurrentConstruct block_do_concurrent_construct = +//// InfiniteDoConstruct:BlockDoConstruct ::= DoStmt:InfiniteDoStmt DoBlock EndDo ; +InfiniteDoConstruct infinite_do_construct = + s:infinite_do_stmt b:do_block e:end_do + { + yyValue = new InfiniteDoConstruct(s, b, e); + } +; + +//// DoConcurrentConstruct:BlockDoConstruct ::= DoStmt:DoConcurrentStmt DoBlock EndDo ; +DoConcurrentConstruct do_concurrent_construct = s:do_concurrent_stmt b:do_block e:end_do { - yyValue = new BlockDoConcurrentConstruct(s, b, e); + yyValue = new DoConcurrentConstruct(s, b, e); } ; -//// BlockDoWhileConstruct:DoConstruct ::= DoStmt DoBlock EndDo ; -BlockDoWhileConstruct block_do_while_construct = +//// DoWhileConstruct:BlockDoConstruct ::= DoStmt:DoWhileStmt DoBlock EndDo ; +DoWhileConstruct do_while_construct = s:do_while_stmt b:do_block e:end_do { - yyValue = new BlockDoWhileConstruct(s, b, e); + yyValue = new DoWhileConstruct(s, b, e); } ; //// // R815 -//// DoStmt:AbstractStmt ::= [DoConstructName:Name] [LoopControl]; +//// abstract DoStmt:AbstractStmt ::= [DoConstructName:Name]; DoStmt do_stmt = - n:(yyValue:name COLON)? DO l:label c:(simple_loop_control)? lnc:comment - { - Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); - Opt<LoopControl> c_opt = (c==null) ? new Opt<LoopControl>() : new Opt<LoopControl>(c); - yyValue = new DoStmt(new Opt<Label>(l), lnc, n_opt, c_opt); - } -/ n:(yyValue:name COLON)? DO c:(simple_loop_control)? lnc:comment - { - Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); - Opt<LoopControl> c_opt = (c==null) ? new Opt<LoopControl>() : new Opt<LoopControl>(c); - yyValue = new DoStmt(new Opt<Label>(), lnc, n_opt, c_opt); - } + infinite_do_stmt +/ simple_do_stmt +/ do_concurrent_stmt +/ do_while_stmt ; -DoStmt do_concurrent_stmt = - n:(yyValue:name COLON)? DO l:label c:concurrent_loop_control lnc:comment +//// InfiniteDoStmt:DoStmt ; +InfiniteDoStmt infinite_do_stmt = + n:(yyValue:name COLON)? DO l:label? lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); - Opt<LoopControl> c_opt = (c==null) ? new Opt<LoopControl>() : new Opt<LoopControl>(c); - yyValue = new DoStmt(new Opt<Label>(l), lnc, n_opt, c_opt); + Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); + yyValue = new InfiniteDoStmt(l_opt, lnc, n_opt); } -/ n:(yyValue:name COLON)? DO c:concurrent_loop_control lnc:comment +; + +//// SimpleDoStmt:DoStmt ::= SimpleLoopControl; +SimpleDoStmt simple_do_stmt = + n:(yyValue:name COLON)? DO l:label? c:simple_loop_control lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); - Opt<LoopControl> c_opt = (c==null) ? new Opt<LoopControl>() : new Opt<LoopControl>(c); - yyValue = new DoStmt(new Opt<Label>(), lnc, n_opt, c_opt); + Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); + yyValue = new SimpleDoStmt(l_opt, lnc, n_opt, c); } ; -DoStmt do_while_stmt = - n:(yyValue:name COLON)? DO l:label c:while_loop_control lnc:comment +//// DoConcurrentStmt:DoStmt ::= ConcurrentLoopControl ; +DoConcurrentStmt do_concurrent_stmt = + n:(yyValue:name COLON)? DO l:label? c:concurrent_loop_control lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); - Opt<LoopControl> c_opt = (c==null) ? new Opt<LoopControl>() : new Opt<LoopControl>(c); - yyValue = new DoStmt(new Opt<Label>(l), lnc, n_opt, c_opt); + Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); + yyValue = new DoConcurrentStmt(l_opt, lnc, n_opt, c); } -/ n:(yyValue:name COLON)? DO c:while_loop_control lnc:comment +; + +//// DoWhileStmt:DoStmt ::= WhileLoopControl ; +DoWhileStmt do_while_stmt = + n:(yyValue:name COLON)? DO l:label? c:while_loop_control lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); - Opt<LoopControl> c_opt = (c==null) ? new Opt<LoopControl>() : new Opt<LoopControl>(c); - yyValue = new DoStmt(new Opt<Label>(), lnc, n_opt, c_opt); + Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); + yyValue = new DoWhileStmt(l_opt, lnc, n_opt, c); } ; diff --git a/Parser/spec/OpenAcc.rats b/Parser/spec/OpenAcc.rats index e99cf13..6aac0d1 100644 --- a/Parser/spec/OpenAcc.rats +++ b/Parser/spec/OpenAcc.rats @@ -244,7 +244,7 @@ AccEndAtomicStmt acc_end_atomic_stmt = ; // loop constructs ------------------------------------------------------------- -//// abstract AccDoConstruct:DoConstruct ; +//// abstract AccDoConstruct:DoConstruct ::= DoConstruct ; AccDoConstruct acc_do_construct = acc_loop_construct / acc_parallel_loop_construct diff --git a/Parser/spec/OpenMp.rats b/Parser/spec/OpenMp.rats index f45019d..aee2ba2 100644 --- a/Parser/spec/OpenMp.rats +++ b/Parser/spec/OpenMp.rats @@ -798,7 +798,7 @@ OmpEndOrderedStmt omp_end_ordered_stmt = // Loop Constructs // ============================================================================= -//// abstract OmpLoopConstruct:DoConstruct ; +//// abstract OmpLoopConstruct:DoConstruct ::= DoConstruct ; OmpLoopConstruct omp_loop_construct = omp_do_construct / omp_simd_construct diff --git a/Parser/spec/Printing.jadd b/Parser/spec/Printing.jadd index 325f92f..7cd9641 100644 --- a/Parser/spec/Printing.jadd +++ b/Parser/spec/Printing.jadd @@ -2881,7 +2881,7 @@ class PrettyPrint { } // R814 - public void BlockDoConstruct.prettyPrint(PrettyPrinter s) { + public void SimpleDoConstruct.prettyPrint(PrettyPrinter s) { getDoStmt().prettyPrint(s); s.ind(); getDoBlock().prettyPrint(s); @@ -2889,7 +2889,7 @@ class PrettyPrint { getEndDo().prettyPrint(s); } - public void BlockDoConcurrentConstruct.prettyPrint(PrettyPrinter s) { + public void InfiniteDoConstruct.prettyPrint(PrettyPrinter s) { getDoStmt().prettyPrint(s); s.ind(); getDoBlock().prettyPrint(s); @@ -2897,7 +2897,15 @@ class PrettyPrint { getEndDo().prettyPrint(s); } - public void BlockDoWhileConstruct.prettyPrint(PrettyPrinter s) { + public void DoConcurrentConstruct.prettyPrint(PrettyPrinter s) { + getDoStmt().prettyPrint(s); + s.ind(); + getDoBlock().prettyPrint(s); + s.und(); + getEndDo().prettyPrint(s); + } + + public void DoWhileConstruct.prettyPrint(PrettyPrinter s) { getDoStmt().prettyPrint(s); s.ind(); getDoBlock().prettyPrint(s); @@ -2906,7 +2914,32 @@ class PrettyPrint { } // R815 - public void DoStmt.prettyPrint(PrettyPrinter s) { + public void InfiniteDoStmt.prettyPrint(PrettyPrinter s) { + if (hasDoConstructName()) { + getDoConstructName().prettyPrint(s); + s.append(": "); + } + s.append("DO"); + if (hasLabel()) { + s.append(" "); + getLabel().prettyPrint(s); + } + getComment().prettyPrint(s); + } + public void SimpleDoStmt.prettyPrint(PrettyPrinter s) { + if (hasDoConstructName()) { + getDoConstructName().prettyPrint(s); + s.append(": "); + } + s.append("DO "); + if (hasLabel()) { + getLabel().prettyPrint(s); + s.append(" "); + } + getSimpleLoopControl().prettyPrint(s); + getComment().prettyPrint(s); + } + public void DoConcurrentStmt.prettyPrint(PrettyPrinter s) { if (hasDoConstructName()) { getDoConstructName().prettyPrint(s); s.append(": "); @@ -2916,9 +2949,20 @@ class PrettyPrint { getLabel().prettyPrint(s); s.append(" "); } - if (hasLoopControl()) { - getLoopControl().prettyPrint(s); + getConcurrentLoopControl().prettyPrint(s); + getComment().prettyPrint(s); + } + public void DoWhileStmt.prettyPrint(PrettyPrinter s) { + if (hasDoConstructName()) { + getDoConstructName().prettyPrint(s); + s.append(": "); + } + s.append("DO "); + if (hasLabel()) { + getLabel().prettyPrint(s); + s.append(" "); } + getWhileLoopControl().prettyPrint(s); getComment().prettyPrint(s); } -- GitLab