Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labels with same letters but different cases break the compilation on the c backend #479

Closed
praduca opened this issue Apr 23, 2024 · 2 comments · Fixed by #480
Closed

labels with same letters but different cases break the compilation on the c backend #479

praduca opened this issue Apr 23, 2024 · 2 comments · Fixed by #480
Labels
AST Concerning the generated abstract syntax C Java
Milestone

Comments

@praduca
Copy link

praduca commented Apr 23, 2024

If you have labels with the same letters (like Eexp and EExp), bnfc will check and not accuse an error, but the compilation will fail with an error stating that duplicate members exist.

for instance, the following generate code and compile ok in cpp and haskell, but not in C (didn't test with others):

CalcList . CalcL ::= [Calc] ;
terminator Calc ";"         ;
Cal   .    Calc ::= Exp     ; 

EAdd  .  Exp  ::= Exp  "+"  Exp1 ;
ESub  .  Exp  ::= Exp  "-"  Exp1 ;
EMul  .  Exp1 ::= Exp1 "*"  Exp2 ;
EDiv  .  Exp1 ::= Exp1 "/"  Exp2 ;
Eexp  .  Exp2 ::= Exp2 "^"  Exp3 ;
EExp  .  Exp2 ::= Exp2 "**" Exp3 ;
EFact .  Exp3 ::= Exp4 "!"       ;
EInt  .  Exp4 ::= Integer        ;
coercions Exp 4 ;
comment "#";

Apparently the name is forced to be lowercase on the c code, but have the case preserved on the CPP backend.

@andreasabel andreasabel added C Java AST Concerning the generated abstract syntax labels Apr 23, 2024
@andreasabel andreasabel added this to the 2.9.6 milestone Apr 23, 2024
@andreasabel
Copy link
Member

andreasabel commented Apr 23, 2024

This is also a problem in the java backends:

test/Absyn/Eexp.java:5: error: class EExp is public, should be declared in a file named EExp.java
public class EExp  extends Exp {
       ^
test/Absyn/Exp.java:12: error: cannot access Eexp
    public R visit(test.Absyn.Eexp p, A arg);
                             ^
  bad source file: ./test/Absyn/Eexp.java
    file does not contain class test.Absyn.Eexp
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.
test/Absyn/Exp.java:8: error: name clash: interface Visitor has two methods with the same erasure, yet neither overrides the other
    public R visit(test.Absyn.EAdd p, A arg);
             ^
  first method:  visit(Eexp,A) in Visitor
  second method: visit(EDiv,A) in Visitor

Related:

@andreasabel
Copy link
Member

I suppose we want a warning for labels that clash in case-insensitive mode, and an error for the C and Java backends.
Or maybe for C we could preserve the case in field names instead.

andreasabel added a commit that referenced this issue Apr 23, 2024
Java does not suffer case-sensitive labels as each label becomes a class in its own file.
Thus, we check this and throw an error.
Consequently, test 479_LabelsCaseSensitive is broken for the java backends.
andreasabel added a commit that referenced this issue Apr 23, 2024
Java does not suffer case-sensitive labels as each label becomes a class in its own file.
Thus, we check this and throw an error.
Consequently, test 479_LabelsCaseSensitive is broken for the java backends.
andreasabel added a commit that referenced this issue Apr 28, 2024
Java does not suffer case-sensitive labels as each label becomes a class in its own file.
Thus, we check this and throw an error.
Consequently, test 479_LabelsCaseSensitive is broken for the java backends.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AST Concerning the generated abstract syntax C Java
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants