From 1303b204738e56f58769152b912515a701eea660 Mon Sep 17 00:00:00 2001 From: Bert Date: Sat, 30 Apr 2016 07:23:16 +0200 Subject: [PATCH] add file, line, column details for preprocessor error --- .../cxx/preprocessor/CxxPreprocessor.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cxx-squid/src/main/java/org/sonar/cxx/preprocessor/CxxPreprocessor.java b/cxx-squid/src/main/java/org/sonar/cxx/preprocessor/CxxPreprocessor.java index e7b91028ab..8f18bd0b4d 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/preprocessor/CxxPreprocessor.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/preprocessor/CxxPreprocessor.java @@ -102,16 +102,19 @@ public final void reset() { } static class MismatchException extends Exception { + private static final long serialVersionUID = 1960113363232807009L; - private final String why; - - MismatchException(String why) { - this.why = why; + MismatchException(String message) { + super(message); } - - @Override - public String toString() { - return why; + MismatchException(Throwable cause) { + super(cause); + } + MismatchException(String message, Throwable cause) { + super(message, cause); + } + MismatchException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace);; } } @@ -252,7 +255,7 @@ public CxxPreprocessor(SquidAstVisitorContext context, if (!"".equals(define)) { Macro macro = parseMacroDefinition("#define " + define); if (macro != null) { - LOG.info("storing external macro: '{}'", macro); + LOG.debug("storing external macro: '{}'", macro); macros.put(macro.name, macro); } } @@ -576,6 +579,9 @@ PreprocessorAction handleIncludeLine(AstNode ast, Token token, String filename) currentFileState = globalStateStack.pop(); } } +// else { +// LOG.debug("[{}:{}]: skipping already included file '{}'", new Object[] {filename, token.getLine(), includedFile}); +// } return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList()); } @@ -743,9 +749,7 @@ private int matchArguments(List tokens, List arguments) { break; } } while (true); - } catch (MismatchException me) { - LOG.debug("Mismatch: expected ','got: '" + rest.get(0).getValue() + "'"); - } + } catch (MismatchException me) {} try { rest = match(rest, ")"); } catch (MismatchException me) { @@ -758,7 +762,8 @@ private int matchArguments(List tokens, List arguments) { private List match(List tokens, String str) throws MismatchException { if (!tokens.get(0).getValue().equals(str)) { throw new MismatchException("Mismatch: expected '" + str + "' got: '" - + tokens.get(0).getValue() + "'"); + + tokens.get(0).getValue() + "'" + " [" + tokens.get(0).getURI() + "(" + + tokens.get(0).getLine() + "," + tokens.get(0).getColumn() + ")]"); } return tokens.subList(1, tokens.size()); }