diff --git a/src/org/rascalmpl/library/ParseTree.rsc b/src/org/rascalmpl/library/ParseTree.rsc index 7135e23f6cf..eccd3bf4d5f 100644 --- a/src/org/rascalmpl/library/ParseTree.rsc +++ b/src/org/rascalmpl/library/ParseTree.rsc @@ -352,17 +352,26 @@ Symbol \layout(\keywords(n)) = layouts(n); Symbol \layout(\layouts(n)) = layouts(n); -bool subtype(Symbol::\sort(_), Symbol::\adt("Tree", _)) = true; -bool subtype(Symbol::\parameterized-sort(_,_), Symbol::\adt("Tree", _)) = true; -bool subtype(Symbol::\lex(_), Symbol::\adt("Tree", _)) = true; -bool subtype(Symbol::\parameterized-lex(_,_), Symbol::\adt("Tree", _)) = true; -bool subtype(Symbol::\layouts(_), Symbol::\adt("Tree", _)) = true; -bool subtype(Symbol::\keywords(_), Symbol::\adt("Tree", _)) = true; -bool subtype(Symbol::\layouts(_), Symbol::\adt("Tree", _)) = true; -bool subtype(\syntax(_), Symbol::\adt("Tree", _)) = true; -bool subtype(\lexical(_), Symbol::\adt("Tree", _)) = true; -bool subtype(\layout(_), Symbol::\adt("Tree", _)) = true; -bool subtype(\keyword(_), Symbol::\adt("Tree", _)) = true; +bool subtype(Symbol::\sort(_), Symbol::\adt("Tree", [])) = true; +bool subtype(Symbol::\parameterized-sort(_,_), Symbol::\adt("Tree", [])) = true; +bool subtype(Symbol::\lex(_), Symbol::\adt("Tree", [])) = true; +bool subtype(Symbol::\parameterized-lex(_,_), Symbol::\adt("Tree", [])) = true; +bool subtype(Symbol::\layouts(_), Symbol::\adt("Tree", [])) = true; +bool subtype(Symbol::\keywords(_), Symbol::\adt("Tree", [])) = true; +bool subtype(Symbol::\layouts(_), Symbol::\adt("Tree", [])) = true; + +bool subtype(\syntax(_), Symbol::\adt("Tree", [])) = true; +bool subtype(\lexical(_), Symbol::\adt("Tree", [])) = true; +bool subtype(\layout(_), Symbol::\adt("Tree", [])) = true; +bool subtype(\keyword(_), Symbol::\adt("Tree", [])) = true; + +bool subtype(\data(parameter(_,_)), adt(_,_)) = true; +bool subtype(\syntax(parameter(_,_)), sort(_)) = true; +bool subtype(\syntax(parameter(_,_)), \parameterized-sort(_,_)) = true; +bool subtype(\lexical(parameter(_,_)), lex(_)) = true; +bool subtype(\lexical(parameter(_,_)), \parameterized-lex(_,_)) = true; +bool subtype(\keyword(parameter(_,_)), keywords(_)) = true; +bool subtype(\layout(parameter(_,_)), layouts(_)) = true; @synopsis{Datatype for declaring preconditions and postconditions on symbols} diff --git a/src/org/rascalmpl/library/Type.rsc b/src/org/rascalmpl/library/Type.rsc index 09f5787f52f..d392d7dfb1d 100644 --- a/src/org/rascalmpl/library/Type.rsc +++ b/src/org/rascalmpl/library/Type.rsc @@ -98,7 +98,8 @@ data Symbol = \data(Symbol modified); // to-data modifier Symbol \data(\data(Symbol s)) = \data(s); Symbol \data(adt(n, ps)) = adt(n, ps); -bool subtype(\data(Symbol s), \node()) = true; +bool subtype(\data(Symbol s), \node()) = true; +bool subtype(\data(parameter(_,_)), adt(_,_)) = true; @synopsis{A production in a grammar or constructor in a data type.} @description{ diff --git a/src/org/rascalmpl/types/ModifySyntaxRole.java b/src/org/rascalmpl/types/ModifySyntaxRole.java index f55520af20e..6a83d5356de 100644 --- a/src/org/rascalmpl/types/ModifySyntaxRole.java +++ b/src/org/rascalmpl/types/ModifySyntaxRole.java @@ -12,12 +12,8 @@ import java.util.Set; import java.util.stream.StreamSupport; -import org.rascalmpl.ast.Nonterminal; -import org.rascalmpl.ast.SyntaxRoleModifier; -import org.rascalmpl.values.IRascalValueFactory; import org.rascalmpl.values.RascalValueFactory; import org.rascalmpl.values.parsetrees.SymbolAdapter; - import io.usethesource.vallang.IConstructor; import io.usethesource.vallang.ISetWriter; import io.usethesource.vallang.IValue; @@ -79,18 +75,18 @@ else if (arg.isAbstractData()) { return applyToData(arg); } else if (arg instanceof NonTerminalType) { - Type kind = ((NonTerminalType) arg).getSymbol().getConstructorType(); + IConstructor symbol = ((NonTerminalType) arg).getSymbol(); - if (kind == RascalValueFactory.Symbol_Sort || kind == RascalValueFactory.Symbol_ParameterizedSort) { + if (isSort(symbol) || isParameterizedSort(symbol)) { return applyToSyntax((NonTerminalType) arg); } - else if (kind == RascalValueFactory.Symbol_Lex || kind == RascalValueFactory.Symbol_ParameterizedLex) { + else if (isLex(symbol) || isParameterizedLex(symbol)) { return applyToLexical((NonTerminalType) arg); } - else if (kind == RascalValueFactory.Symbol_Layouts) { + else if (isLayouts(symbol)) { return applyToLayout((NonTerminalType) arg); } - else if (kind == RascalValueFactory.Symbol_Keywords) { + else if (isKeyword(symbol)) { return applyToKeyword((NonTerminalType) arg); } } @@ -135,10 +131,19 @@ else if (type instanceof Keyword) { return RascalValueFactory.Tree; } else if (type instanceof Data) { - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); } - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); + } + + @Override + protected Type glbWithModifySyntax(RascalType type) { + if (type instanceof Syntax) { + return TF.modifyToSyntax(((ModifySyntaxRole) type).arg.glb(arg)); + } + + return tf.voidType(); } @Override @@ -247,10 +252,19 @@ else if (type instanceof Keyword) { return RascalValueFactory.Tree; } else if (type instanceof Data) { - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); } - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); + } + + @Override + protected Type glbWithModifySyntax(RascalType type) { + if (type instanceof Lexical) { + return TF.modifyToLexical(((ModifySyntaxRole) type).arg.glb(arg)); + } + + return tf.voidType(); } @Override @@ -347,10 +361,19 @@ else if (type instanceof Keyword) { return RascalValueFactory.Tree; } else if (type instanceof Data) { - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); } - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); + } + + @Override + protected Type glbWithModifySyntax(RascalType type) { + if (type instanceof Layout) { + return TF.modifyToLayout(((ModifySyntaxRole) type).arg.glb(arg)); + } + + return tf.voidType(); } @@ -434,8 +457,6 @@ public IConstructor asSymbol(IValueFactory vf, TypeStore store, ISetWriter gramm return vf.constructor(RascalValueFactory.Symbol_KeywordModifier, arg.asSymbol(vf, store, grammar, done)); } - - @Override protected Type lubWithModifySyntax(RascalType type) { if (type instanceof Syntax) { @@ -451,10 +472,20 @@ else if (type instanceof Keyword) { return TF.modifyToKeyword(((ModifySyntaxRole) type).arg.lub(arg)); } else if (type instanceof Data) { - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); + } + + return tf.nodeType(); + } + + @Override + protected Type glbWithModifySyntax(RascalType type) { + if (type instanceof Keyword) { + return TF.modifyToKeyword(((ModifySyntaxRole) type).arg.glb(arg)); } + - return TypeFactory.getInstance().nodeType(); + return tf.voidType(); } @@ -552,7 +583,16 @@ else if (type instanceof Data) { return this; } - return TypeFactory.getInstance().nodeType(); + return tf.nodeType(); + } + + @Override + protected Type glbWithModifySyntax(RascalType type) { + if (type instanceof Data) { + return this; + } + + return tf.voidType(); } @Override @@ -582,10 +622,10 @@ public Type applyToSyntax(NonTerminalType arg) { if (arg.isParameterized()) { Type[] params = SymbolAdapter.getParameters(arg.getSymbol()).stream().map(c -> TF.nonTerminalType((IConstructor) c)).toArray(Type[]::new); - return TypeFactory.getInstance().abstractDataType(new TypeStore(), name, params); + return tf.abstractDataType(new TypeStore(), name, params); } else { - return TypeFactory.getInstance().abstractDataType(new TypeStore(), name); + return tf.abstractDataType(new TypeStore(), name); } } @@ -603,7 +643,7 @@ public Type applyToKeyword(NonTerminalType arg) { @Override public Type applyToLayout(NonTerminalType arg) { String name = SymbolAdapter.getName(arg.getSymbol()); - return TypeFactory.getInstance().abstractDataType(new TypeStore(), name); + return tf.abstractDataType(new TypeStore(), name); } @Override @@ -629,13 +669,13 @@ protected Type lubWithAbstractData(Type type) { return type; } - return TypeFactory.getInstance().valueType(); + return tf.valueType(); } @Override protected Type glbWithAbstractData(Type type) { // this is for all the syntax roles that are not data. Data overrides this - return type == RascalValueFactory.Tree ? this : TypeFactory.getInstance().voidType(); + return type == RascalValueFactory.Tree ? this : tf.voidType(); } @Override @@ -659,6 +699,9 @@ protected Type glb(RascalType type) { return type.glbWithModifySyntax(this); } + @Override + abstract protected Type glbWithModifySyntax(RascalType type); + @Override protected boolean intersects(RascalType type) { return type.intersectsWithModifySyntax(this); diff --git a/src/org/rascalmpl/values/parsetrees/SymbolAdapter.java b/src/org/rascalmpl/values/parsetrees/SymbolAdapter.java index 5d147f453f6..512f4671f0e 100644 --- a/src/org/rascalmpl/values/parsetrees/SymbolAdapter.java +++ b/src/org/rascalmpl/values/parsetrees/SymbolAdapter.java @@ -138,12 +138,7 @@ public static boolean isStartSort(IConstructor tree) { tree = delabel(tree); return tree.getConstructorType() == Symbol_Start; } - -// public static boolean isStart(IConstructor tree) { -// tree = delabel(tree); -// return tree.getConstructorType() == Factory.Symbol_START; -// } - + public static IConstructor getStart(IConstructor tree) { if (isStartSort(tree)) { tree = delabel(tree);