Skip to content
Snippets Groups Projects
Commit 369154ed authored by Johannes Mey's avatar Johannes Mey
Browse files

add rewrites

parent 72025e38
No related branches found
No related tags found
No related merge requests found
aspect AmbiguityResoler {
rewrite Designator_OR_FunctionReference {
when ( !hasSubstringRange_OR_ActualArgSpecList() && !hasSubstringRange() )
to ArraySection_Designator {
return new ArraySection_Designator(new ArraySection(getDataRef(), new Opt<SubstringRange>()));
}
}
rewrite ArraySection_Designator {
when (!getArraySection().hasSubstringRange()
&& getArraySection().getDataRef().getPartRefList().numChildren() == 1
&& getArraySection().getDataRef().getPartRef(0).getSectionSubscriptList().numChildren() == 0
&& !getArraySection().getDataRef().getPartRef(0).hasImageSelector())
to ObjectName_Designator {
return new ObjectName_Designator(new ObjectName(getArraySection().getDataRef().getPartRef(0).getName()));
}
when (getArraySection().isArrayElement())
to ArrayElement_Designator {
return new ArrayElement_Designator(new ArrayElement(getArraySection().getDataRef()));
}
}
// TODO: to implement this, an Expr.rank() attribute is required
// rewrite VectorSectionSubscript {
// when ( getVectorSubscript().getExpr().rank() == 0)
// to SimpleSectionSubscript {
// return new SimpleSectionSubscript(new Subscript(getVectorSubscript().getExpr()));
// }
// }
rewrite AccLoopStmt {
when (containedCollapseOne() != null)
to AccLoopStmt {
ASTNode parent = getParent();
if(parent!=null){
int i = containedCollapseOne().getParent().getIndexOfChild(containedCollapseOne());
if(i>-1){
parent.removeChild(i);
}
}
return this;
}
}
// TODO support the collapse optimisation in all Acc Statements
syn AccCollapseClause AccStmt.containedCollapseOne();
eq AccStmt.containedCollapseOne() = null;
eq AccLoopStmt.containedCollapseOne() {
for (AccClause clause: getAccClauseList()) {
if (clause.isCollapseOne() != null) {
return clause.isCollapseOne();
}
}
return null;
}
syn AccCollapseClause AccClause.isCollapseOne();
eq AccClause.isCollapseOne() = null;
eq AccCollapseClause.isCollapseOne() {
if (getCount().getDigitString().getDigits().equals("1")) {
return this;
} else {
return null;
}
}
/**
* C624 (R618) Exactly one part-ref shall have nonzero rank, and either the final part-ref shall
* have a section-subscript-list with nonzero rank, another part-ref shall have nonzero rank, or
* the complex-part-designator shall be an array.
* TODO: C624 is too relaxed
*/
syn boolean ArraySection.isArrayElement() {
if (hasSubstringRange()) {
return false;
}
for (PartRef partRef : getDataRef().getPartRefList()) {
if (!partRef.hasZeroRank()) {
return true;
}
}
return false;
}
syn boolean PartRef.hasZeroRank() {
return getSectionSubscriptList().numChildren() == 0;
}
}
\ No newline at end of file
mat(i,j) = 0
end
package org.tud.forty.test;
import java.io.File;
import java.util.Iterator;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.tud.forty.ast.Root;
public class RewriteTest extends TestBase {
@DataProvider(name = "rewrites")
public static Iterator<Object[]> fortranRuleProvider() {
return ruleProvider("test-data/rewrites");
}
@Test(dataProvider = "rewrites", groups = {"parser"})
public void testRuleParser(File f) throws Exception {
printFile(f);
testParse(f, false, true, false, true, Root.class);
}
@Test(dataProvider = "rewrites", groups = {"prettyprinter"})
public void testRulePrinter(File f) throws Exception {
testParse(f, true, false, false, true, Root.class);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment