sergutsan / JDecafCompiler

A Java precompiler for educational purposes
1 stars 0 forks source link

Method is not preprocessed into static method #5

Open sergutsan opened 10 years ago

sergutsan commented 10 years ago

Java Decaf Code

int a=1;
print (decimal2binary(a));
print(add(a,2));

int add(int a, int b) {
   return a+b;
}

String decimal2binary(int number) {
  while (number>0) {
    int bin=number%2;
    binaryString=binaryString+bin;
    number=(number-bin)/2;
  }
  return binaryString;
}

Expected Java Code

...
private static String decimal2binary(int number) {
  while (number>0) {
    int bin=number%2;
    binaryString=binaryString+bin;
    number=(number-bin)/2;
  }
  return binaryString;
}
...

Actual Java Code

...
String decimal2binary(int number) {
  while (number>0) {
    int bin=number%2;
    binaryString=binaryString+bin;
    number=(number-bin)/2;
  }
  return binaryString;
}
...

resulting in errors like

Error on line 2 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: non-static method decimal2binary(int) cannot be referenced from a static context Error on line 12 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: cannot find symbol symbol: variable binaryString location: class tmp Error on line 12 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: cannot find symbol symbol: variable binaryString location: class tmp Error on line 15 in file:/home/sergut/git/JDecafCompiler/tmp.jdc Problem: cannot find symbol symbol: variable binaryString location: class tmp

sergutsan commented 10 years ago

Fixed by 6e7593f.