Skip to content

Commit

Permalink
Merge branch 'cleanup-montitrans-todos' into 'dev'
Browse files Browse the repository at this point in the history
Cleanup MontiTrans ToDos

See merge request monticore/monticore!879
  • Loading branch information
MisterErwin committed Oct 6, 2023
2 parents e9b0ad6 + a762425 commit 7ffec7d
Showing 1 changed file with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import de.monticore.ast.Comment;
import de.monticore.dstlgen.ruletranslation.DSTLGenInheritanceHelper;
import de.monticore.dstlgen.util.DSTLUtil;
import de.monticore.expressions.commonexpressions.CommonExpressionsMill;
import de.monticore.grammar.grammar.GrammarMill;
import de.monticore.grammar.grammar._ast.*;
import de.monticore.grammar.grammar._symboltable.MCGrammarSymbol;
import de.monticore.grammar.grammar._visitor.GrammarTraverser;
import de.monticore.grammar.grammar_withconcepts.Grammar_WithConceptsMill;
import de.monticore.grammar.grammar_withconcepts._parser.Grammar_WithConceptsParser;
import de.monticore.literals.mccommonliterals.MCCommonLiteralsMill;
import de.monticore.types.MCTypeFacade;
import de.monticore.types.mcbasictypes._ast.ASTMCType;
import de.se_rwth.commons.StringTransformations;
import de.se_rwth.commons.logging.Log;
Expand Down Expand Up @@ -106,7 +105,7 @@ public ASTInterfaceProd createInterfaceProd(ASTClassProd srcNode, int grammar_de
}

public ASTInterfaceProd createInterfaceProd(ASTInterfaceProd srcNode, int grammar_depth) {
return this.createInterfaceProd(srcNode, grammar_depth, false);
return this.createInterfaceProd(srcNode, grammar_depth, true);
}


Expand All @@ -120,7 +119,6 @@ public ASTInterfaceProd createInterfaceProd(ASTInterfaceProd srcNode, int gramma
* @return the interface production as an ASTInterfaceProd object
*/
public ASTInterfaceProd createInterfaceProd(ASTInterfaceProd srcNode, int grammar_depth, boolean reduceParserAlts) {
reduceParserAlts = true; // TODO: remove it all together?
String ITFPart = "I" + srcNode.getSymbol().getEnclosingScope().getName() + "TFPart";
final String tfReplacementRule = "interface ITF" + srcNode.getName() + " astextends de.monticore.tf.ast.ITFElement " + (reduceParserAlts ? "" : " extends " +ITFPart+"<" + grammar_depth + ">") + ";";
ASTInterfaceProd result = parseInterfaceProd(tfReplacementRule);
Expand Down Expand Up @@ -217,7 +215,7 @@ public ASTClassProd createPatternProd(ASTClassProd srcNode,
postProcessingTraverser.add4Grammar(new PostprocessPatternAttributesVisitor(grammarSymbol));

// create "astimplements ..."
result.getASTSuperInterfaceList().add(parseGenericType(PSYM_PATTERN));
result.getASTSuperInterfaceList().add(MCTypeFacade.getInstance().createQualifiedType(PSYM_PATTERN));

// change name
result.setName(srcNode.getName() + PATTERN_SUFFIX);
Expand Down Expand Up @@ -274,10 +272,11 @@ private static List<ASTAlt> createPatternAlternates(ASTClassProd srcNode, Gramma
ASTAlt aDeepClone = srcNode.getAltList().get(0).deepClone();
postProcessingTraverser.clearTraversedElements();
aDeepClone.accept(postProcessingTraverser);
aDeepClone.setRightAssoc(false); //TODO: Do i need the rightassoc?
aDeepClone.setRightAssoc(false);
origAlt.getComponentList().addAll(aDeepClone.getComponentList()); // origAlt = AcloneComp
origBlock.getAltList().add(aDeepClone); // origBlock = Aclone
origAlt.add_PreComment(new Comment(" /* Avoid an extra block here */ "));
// if we were to introduce a block here, the left-recursiveness will cause issues
} else {
// add an extra pair of brackets/a block around the original production
origAlt.getComponentList().add(origBlock);
Expand Down Expand Up @@ -433,7 +432,7 @@ protected ASTClassProd doCreatePatternProd(ASTProd srcNode, MCGrammarSymbol gram


// create "astimplements ..."
result.getASTSuperInterfaceList().add(parseGenericType(PSYM_PATTERN));
result.getASTSuperInterfaceList().add(MCTypeFacade.getInstance().createQualifiedType(PSYM_PATTERN));

// change name
result.setName(srcNode.getName() + PATTERN_SUFFIX);
Expand Down Expand Up @@ -512,19 +511,17 @@ public ASTClassProd createProd(ASTProd srcNode, ProductionType type, boolean sup
*
* @param srcNode node to create a production for
* @param type type of production to be created
* @param superExternal if one of the super productions is an external one
* @param specialRecursion if the srcNode is left recursive
* @return production fo the given type
*/
public ASTClassProd createProd(ASTProd srcNode,
ProductionType type,
boolean superExternal,
boolean specialRecursion) {
final String name = srcNode.getName();
String relation = superExternal ? " extends " : " implements ";
String nonterminal = "ITF" + name;

//TODO: When to use special name vs
String specialname = specialRecursion ? nonterminal : (name + "_Pat");

if (type.equals(ProductionType.OPTIONAL)) {
String classProdAsString =
name + "_" + type
Expand All @@ -544,10 +541,12 @@ public ASTClassProd createProd(ASTProd srcNode,
"ITF" + name, "I" + srcNode.getSymbol().getEnclosingScope().getName() + "TFPart")) + " astimplements de.monticore.tf.ast.I" + "Negation" + " = "
+ createPrefix(name, type) + " \"[[\" "
+ StringTransformations.uncapitalize(
name) + ":" + (nonterminal /* specialName */) + " \"]]\";";
name) + ":" + (nonterminal) + " \"]]\";";

return parseClassProd(classProdAsString);
} else {
// Use the prod-pattern-interface, in case of non-left-recursiveness
String nonTermNameOrPattern = specialRecursion ? nonterminal : (name + "_Pat");
String classProdAsString =
name + "_" + type.getNameString() + helpRelation(
superExternal,
Expand All @@ -556,7 +555,7 @@ public ASTClassProd createProd(ASTProd srcNode,
+ createPrefix(name,
type) + PSYM_SCHEMAVAR + NAME + COLON + NAME + "? \"[[\" "
+ StringTransformations.uncapitalize(
name) + ":" + specialname + " \"]]\";";
name) + ":" + nonTermNameOrPattern + " \"]]\";";

return parseClassProd(classProdAsString);
}
Expand Down Expand Up @@ -790,16 +789,6 @@ protected Optional<ASTClassProd> createLexIdentifier(ASTLexProd srcNode, MCGramm
}
}

protected ASTMCType parseGenericType(String type) {
Grammar_WithConceptsParser p = Grammar_WithConceptsMill.parser();
try {
return p.parse_StringMCType(type).get();
} catch (IOException e) {
throw new RuntimeException(
"0xF1002 Unable to create GenericType for " + type);
}
}

protected ASTInterfaceProd parseInterfaceProd(
String tfReplacementRule) {
Grammar_WithConceptsParser p = Grammar_WithConceptsMill.parser();
Expand Down

0 comments on commit 7ffec7d

Please sign in to comment.