Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion k-distribution/tests/regression-new/macro_vars/macro-vars.k
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ module MACRO-VARS
syntax CPPType ::= underlyingType(CPPType) [function]
syntax CPPType ::= "cppEnumType"
rule cppEnumType => bar(_, scopedEnum() #Or unscopedEnum() ) [macro, unboundVariables(_)]
endmodule

syntax Int ::= "hookedMacro" [macro]
rule hookedMacro => 5

endmodule
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void check(Production prod) {
Att sortAtt = m.sortAttributesFor().getOrElse(prod.sort().head(), () -> Att.empty());
if (sortAtt.contains(Att.HOOK()) && !sortAtt.get(Att.HOOK()).equals("ARRAY.Array") && !(sortAtt.get(Att.HOOK()).equals("KVAR.KVar") && isSymbolicKast)) {
if (!prod.att().contains(Att.FUNCTION()) && !prod.att().contains(Att.BRACKET()) &&
!prod.att().contains("token") && !(prod.klabel().isDefined() && macros.contains(prod.klabel().get()))) {
!prod.att().contains("token") && !prod.att().contains("macro") && !(prod.klabel().isDefined() && macros.contains(prod.klabel().get()))) {
Copy link
Copy Markdown
Contributor

@Baltoli Baltoli Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a change to this specific PR (which looks good to me), but it would be nice in general to have this kind of deeply nested / long chain code factored out into a helper method with a comment explaining the logic. Perhaps it would be worth someone spending some time on the API design of the frontend to make this kind of code easier to write

if (!(prod.sort().equals(Sorts.K()) && ((prod.klabel().isDefined() && (prod.klabel().get().name().equals("#EmptyK") || prod.klabel().get().name().equals("#KSequence"))) || prod.isSubsort()))) {
if (!(sortAtt.contains("cellCollection") && prod.isSubsort())) {
errors.add(KEMException.compilerError("Cannot add new constructors to hooked sort " + prod.sort(), prod));
Expand Down