-
Notifications
You must be signed in to change notification settings - Fork 12
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
first set of changes #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
bin.includes = META-INF/,\ | ||
java-cup-12joho.jar,\ | ||
ant.jar,\ | ||
. | ||
output.. = bin/ | ||
jars.extra.classpath = ant.jar | ||
jars.extra.classpath = ../ant.jar | ||
source.. = src/ | ||
jre.compilation.profile = JavaSE-1.8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,113 @@ | ||
|
||
package com.github.jhoenicke.javacup; | ||
|
||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import com.github.jhoenicke.javacup.runtime.Symbol; | ||
public class ErrorManager{ | ||
private static ErrorManager errorManager; | ||
private int errors = 0; | ||
private int warnings = 0; | ||
private int fatals = 0; | ||
public int getFatalCount() { return fatals; } | ||
public int getErrorCount() { return errors; } | ||
public int getWarningCount() { return warnings; } | ||
static { | ||
errorManager = new ErrorManager(); | ||
} | ||
public static ErrorManager getManager() { return errorManager; } | ||
private ErrorManager(){ | ||
} | ||
|
||
//TODO: migrate to java.util.logging | ||
/** | ||
* Error message format: | ||
* ERRORLEVEL at (LINE/COLUMN)@SYMBOL: MESSAGE | ||
* ERRORLEVEL : MESSAGE | ||
**/ | ||
public void emit_fatal(String message){ | ||
System.err.println("Fatal: "+message); | ||
fatals++; | ||
} | ||
public void emit_fatal(String message, Symbol sym){ | ||
System.err.println("Fatal: "+message+" @ "+sym); | ||
fatals++; | ||
} | ||
public void emit_warning(String message){ | ||
System.err.println("Warning: " + message); | ||
warnings++; | ||
} | ||
public void emit_warning(String message, Symbol sym){ | ||
System.err.println("Warning: " + message+" @ "+sym); | ||
warnings++; | ||
} | ||
public void emit_error(String message){ | ||
System.err.println("Error: " + message); | ||
errors++; | ||
} | ||
public void emit_error(String message, Symbol sym){ | ||
System.err.println("Error: "+message+" @ "+sym); | ||
errors++; | ||
} | ||
|
||
public class ErrorManager { | ||
|
||
private static ErrorManager errorManager; | ||
|
||
static enum Severity { | ||
Info, | ||
Warning, | ||
Error, | ||
Fatal, | ||
} | ||
|
||
private int infos = 0; | ||
private int warnings = 0; | ||
private int errors = 0; | ||
private int fatals = 0; | ||
|
||
private Set<String> filter; | ||
|
||
private ErrorManager() { | ||
} | ||
|
||
public static ErrorManager getManager() { | ||
if (errorManager == null) errorManager = new ErrorManager(); | ||
return errorManager; | ||
} | ||
|
||
public static void clear () { | ||
errorManager = null; | ||
} | ||
|
||
private Set<String> getFilter () { | ||
if (filter == null) filter = new TreeSet<>(); | ||
return filter; | ||
} | ||
|
||
public int getFatalCount() { | ||
return fatals; | ||
} | ||
|
||
public int getErrorCount() { | ||
return errors; | ||
} | ||
|
||
public int getWarningCount() { | ||
return warnings; | ||
} | ||
|
||
/** | ||
* Error message format: | ||
* ERRORLEVEL : MESSAGE @ Symbol: name#token=="value"(line/column) | ||
* ERRORLEVEL : MESSAGE | ||
**/ | ||
|
||
private void emit (Severity severity, String message, Symbol sym) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit-pick: no space before "(". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I did not know this rule. I will respect it later. |
||
if (sym != null && sym.value != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is a good idea. What is the intention? It looks like it stops printing multiple error messages for the same location. Also since the ErrorManager is static, this would mean that on the second run the errors are no longer printed, doesn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a filter on the same symbol. IOn the previous release only the first message is emitted and subsequent messages vanishes. With this filter, a second (third,...) message about the same symbol (should exists and have a value) is not printed. So only the first one is printed but other error about other symbols are printed too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I forgot to reply about the second run. No problem, In Main I call a clear method which nullify the instance so the getter will recreate one fresh with all fields set to initial value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a bit dangerous and sym.value may not even mean the right thing. The symbol is really the location in the source file where the error happened and it can be any error like undeclared symbol, symbols declared multiple times, or a unrecoverable syntax error. You may hide some error message here. If you just don't want to get multiple warnings about undefined symbols, it would be better to do this in the parser and keep a set of symbols that were already warned about there. This way you can be sure that only these kind of double reports are omitted and you get for free the clearing of the set. |
||
if (getFilter().contains(sym.value.toString())) return; | ||
getFilter().add(sym.value.toString()); | ||
} | ||
StringBuilder tmp = new StringBuilder(); | ||
tmp.append(severity.name()); | ||
tmp.append(": "); | ||
tmp.append(message); | ||
if (sym != null) { | ||
tmp.append(" @ "); | ||
tmp.append(sym); | ||
} | ||
System.err.println(tmp); | ||
} | ||
|
||
public void emit_info(String message) { | ||
emit_info(message, null); | ||
} | ||
|
||
public void emit_info(String message, Symbol sym) { | ||
emit(Severity.Info, message, sym); | ||
infos++; | ||
} | ||
|
||
public void emit_warning(String message) { | ||
emit_warning(message, null); | ||
} | ||
|
||
public void emit_warning(String message, Symbol sym) { | ||
emit(Severity.Warning, message, sym); | ||
warnings++; | ||
} | ||
|
||
public void emit_error(String message) { | ||
emit_error(message, null); | ||
} | ||
|
||
public void emit_error(String message, Symbol sym) { | ||
emit(Severity.Error, message, sym); | ||
errors++; | ||
} | ||
|
||
public void emit_fatal(String message) { | ||
emit_fatal(message, null); | ||
} | ||
|
||
public void emit_fatal(String message, Symbol sym) { | ||
emit(Severity.Fatal, message, sym); | ||
fatals++; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes/no, in fact I move the ant.jat outside the projet as I have to download it separatly. Unfortunatly, I have to update the build.properties (but may be it is environnement dependant and should not be part of a git.