Skip to content

Commit

Permalink
fixing corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 21, 2023
1 parent 7d60d3e commit 123a3f5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/org/rascalmpl/library/ParseTree.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*******************************************************************************/
package org.rascalmpl.semantics.dynamic;

import org.rascalmpl.ast.Name;
import org.rascalmpl.interpreter.IEvaluator;
import org.rascalmpl.interpreter.env.Environment;
import org.rascalmpl.interpreter.result.Result;
Expand Down
98 changes: 95 additions & 3 deletions src/org/rascalmpl/types/ModifySyntaxRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public Syntax(Type arg) {
super(arg);
}

Check warning on line 113 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L112-L113

Added lines #L112 - L113 were not covered by tests

@Override
public String toString() {
return "syntax[" + arg.toString() + "]";

Check warning on line 117 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L117

Added line #L117 was not covered by tests
}

@Override
public IConstructor asSymbol(IValueFactory vf, TypeStore store, ISetWriter grammar, Set<IConstructor> done) {
return vf.constructor(RascalValueFactory.Symbol_SyntaxModifier, arg.asSymbol(vf, store, grammar, done));

Check warning on line 122 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L122

Added line #L122 was not covered by tests
Expand Down Expand Up @@ -153,6 +158,20 @@ public boolean isSubtypeOfSyntaxModifier(RascalType type) {
return type instanceof Syntax;

Check warning on line 158 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L158

Added line #L158 was not covered by tests
}

@Override
protected boolean isSupertypeOf(RascalType type) {
assert isOpen();

if (type instanceof NonTerminalType) {
NonTerminalType nt = (NonTerminalType) type;
IConstructor sym = nt.getSymbol();

Check warning on line 167 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L166-L167

Added lines #L166 - L167 were not covered by tests

return SymbolAdapter.isSort(sym) || SymbolAdapter.isParameterizedSort(sym);
}

return false;

Check warning on line 172 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L172

Added line #L172 was not covered by tests
}

@Override
public boolean isSubtypeOfNonTerminal(RascalType type) {
assert isOpen(); // otherwise we wouldn't be here
Expand Down Expand Up @@ -248,6 +267,25 @@ public Lexical(Type arg) {
super(arg);
}

Check warning on line 268 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L267-L268

Added lines #L267 - L268 were not covered by tests

@Override
public String toString() {
return "lexical[" + arg.toString() + "]";

Check warning on line 272 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L272

Added line #L272 was not covered by tests
}

@Override
protected boolean isSupertypeOf(RascalType type) {
assert isOpen();

if (type instanceof NonTerminalType) {
NonTerminalType nt = (NonTerminalType) type;
IConstructor sym = nt.getSymbol();

Check warning on line 281 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L280-L281

Added lines #L280 - L281 were not covered by tests

return SymbolAdapter.isLex(sym) || SymbolAdapter.isParameterizedLex(sym);
}

return false;

Check warning on line 286 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L286

Added line #L286 was not covered by tests
}

@Override
public boolean isSubtypeOfSyntaxModifier(RascalType type) {
assert isOpen();
Expand Down Expand Up @@ -382,12 +420,32 @@ public Layout(Type arg) {
super(arg);
}

Check warning on line 421 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L420-L421

Added lines #L420 - L421 were not covered by tests

@Override
public String toString() {
return "layout[" + arg.toString() + "]";

Check warning on line 425 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L425

Added line #L425 was not covered by tests
}

@Override
public boolean isSubtypeOfSyntaxModifier(RascalType type) {
assert isOpen();
return type instanceof Layout;

Check warning on line 431 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L431

Added line #L431 was not covered by tests
}

@Override
protected boolean isSupertypeOf(RascalType type) {
assert isOpen();

if (type instanceof NonTerminalType) {
NonTerminalType nt = (NonTerminalType) type;
IConstructor sym = nt.getSymbol();

Check warning on line 440 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L439-L440

Added lines #L439 - L440 were not covered by tests

return SymbolAdapter.isLayouts(sym);

Check warning on line 442 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L442

Added line #L442 was not covered by tests
}

return false;

Check warning on line 445 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L445

Added line #L445 was not covered by tests
}


@Override
protected Type lubWithModifySyntax(RascalType type) {
if (type instanceof Syntax) {
Expand Down Expand Up @@ -516,6 +574,11 @@ public Keyword(Type arg) {
super(arg);
}

Check warning on line 575 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L574-L575

Added lines #L574 - L575 were not covered by tests

@Override
public String toString() {
return "keyword[" + arg.toString() + "]";

Check warning on line 579 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L579

Added line #L579 was not covered by tests
}

@Override
public IConstructor asSymbol(IValueFactory vf, TypeStore store, ISetWriter grammar, Set<IConstructor> done) {
return vf.constructor(RascalValueFactory.Symbol_KeywordModifier, arg.asSymbol(vf, store, grammar, done));

Check warning on line 584 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L584

Added line #L584 was not covered by tests
Expand Down Expand Up @@ -552,6 +615,17 @@ protected Type glbWithModifySyntax(RascalType type) {
return tf.voidType();

Check warning on line 615 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L615

Added line #L615 was not covered by tests
}

@Override
protected boolean isSupertypeOf(RascalType type) {
if (type instanceof NonTerminalType) {
NonTerminalType nt = (NonTerminalType) type;
IConstructor sym = nt.getSymbol();

Check warning on line 622 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L621-L622

Added lines #L621 - L622 were not covered by tests

return SymbolAdapter.isKeyword(sym);

Check warning on line 624 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L624

Added line #L624 was not covered by tests
}

return false;

Check warning on line 627 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L627

Added line #L627 was not covered by tests
}

@Override
public boolean isSubtypeOfSyntaxModifier(RascalType type) {
Expand Down Expand Up @@ -644,12 +718,24 @@ public Data(Type arg) {
super(arg);
}

Check warning on line 719 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L718-L719

Added lines #L718 - L719 were not covered by tests

@Override
public String toString() {
return "data[" + arg.toString() + "]";

Check warning on line 723 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L723

Added line #L723 was not covered by tests
}

@Override
public boolean isSubtypeOfSyntaxModifier(RascalType type) {
assert isOpen();
return type instanceof Data;

Check warning on line 729 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L729

Added line #L729 was not covered by tests
}

@Override
protected boolean isSupertypeOf(RascalType type) {
assert isOpen();
// Here is it essential that {@link NonTerminalType#isAbstractData()} returns true.
return type.isAbstractData();

Check warning on line 736 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L736

Added line #L736 was not covered by tests
}

@Override
protected Type lubWithModifySyntax(RascalType type) {
if (type instanceof Syntax) {
Expand Down Expand Up @@ -770,6 +856,11 @@ protected Type glbWithAbstractData(Type type) {
}
}

@Override
public boolean isOpen() {
return arg.isOpen();

Check warning on line 861 in src/org/rascalmpl/types/ModifySyntaxRole.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/types/ModifySyntaxRole.java#L861

Added line #L861 was not covered by tests
}

@Override
protected Type lubWithAbstractData(Type type) {
// this is for all the syntax roles that are not data. Data overrides this
Expand All @@ -787,9 +878,7 @@ protected Type glbWithAbstractData(Type type) {
}

@Override
protected boolean isSupertypeOf(RascalType type) {
return type.isSubtypeOfSyntaxModifier(this);
}
abstract protected boolean isSupertypeOf(RascalType type);

@Override
protected boolean isSubtypeOfNode(Type type) {
Expand Down Expand Up @@ -835,6 +924,9 @@ public Type asAbstractDataType() {
@Override
abstract public boolean match(Type matched, Map<Type, Type> bindings) throws FactTypeUseException;

@Override
abstract public String toString();

@Override
public IValue randomValue(Random random, IValueFactory vf, TypeStore store, Map<Type, Type> typeParameters,
int maxDepth, int maxBreadth) {
Expand Down

0 comments on commit 123a3f5

Please sign in to comment.