diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java index a4b21c1ff18..2e6b9ba430b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner/PreprocessorBugsTests.java @@ -32,7 +32,7 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase { public void testMacroInInclusion_Bug122891() throws Exception { initializeScanner(); validateEOF(); - validateProblem(0, IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, "regxag4.sfr"); + validateProblem(0, IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, ""); validateProblemCount(1); } @@ -63,7 +63,7 @@ public class PreprocessorBugsTests extends PreprocessorTestsBase { public void testEmptyStringInMacroInInclusion_Bug145270() throws Exception { initializeScanner(); validateEOF(); - validateProblem(0, IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, "bar.h"); + validateProblem(0, IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, "\"bar.h\""); validateProblemCount(1); } diff --git a/core/org.eclipse.cdt.core/.options b/core/org.eclipse.cdt.core/.options index 4b2af371095..eb67f9a90e3 100644 --- a/core/org.eclipse.cdt.core/.options +++ b/core/org.eclipse.cdt.core/.options @@ -30,7 +30,16 @@ org.eclipse.cdt.core/debug/indexer/activity=false # Reports statistics for indexer org.eclipse.cdt.core/debug/indexer/statistics=false -# Reports problems for indexer +# Reports unresolved inclusions for indexer +org.eclipse.cdt.core/debug/indexer/problems/inclusion=false + +# Reports scanner-problems for indexer (other than unresolved includes) +org.eclipse.cdt.core/debug/indexer/problems/scanner=false + +# Reports syntax-problems for indexer +org.eclipse.cdt.core/debug/indexer/problems/syntax=false + +# Reports problems for indexer, including inclusion-, scanner-, syntax- and resolution-problems. org.eclipse.cdt.core/debug/indexer/problems=false # Code formatter debugging diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java index 49f2619eadf..785b99d4b22 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java @@ -130,7 +130,7 @@ public class CModelBuilder2 implements IContributedModelBuilder { * @see org.eclipse.cdt.core.parser.IProblem#getMessage() */ public String getMessage() { - return fASTProblem.getMessage(); + return fASTProblem.getMessageWithoutLocation(); } /* diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java index 9523c760233..7490a69898c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IPDOMIndexerTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems + * Copyright (c) 2005, 2008 QNX Software Systems * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,6 +23,9 @@ import org.eclipse.core.runtime.IProgressMonitor; public interface IPDOMIndexerTask { public static final String TRACE_ACTIVITY = CCorePlugin.PLUGIN_ID + "/debug/indexer/activity"; //$NON-NLS-1$ public static final String TRACE_STATISTICS = CCorePlugin.PLUGIN_ID + "/debug/indexer/statistics"; //$NON-NLS-1$ + public static final String TRACE_INCLUSION_PROBLEMS = CCorePlugin.PLUGIN_ID + "/debug/indexer/problems/inclusion"; //$NON-NLS-1$ + public static final String TRACE_SCANNER_PROBLEMS = CCorePlugin.PLUGIN_ID + "/debug/indexer/problems/scanner"; //$NON-NLS-1$ + public static final String TRACE_SYNTAX_PROBLEMS = CCorePlugin.PLUGIN_ID + "/debug/indexer/problems/syntax"; //$NON-NLS-1$ public static final String TRACE_PROBLEMS = CCorePlugin.PLUGIN_ID + "/debug/indexer/problems"; //$NON-NLS-1$ /** diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblem.java index 0dcf8ccccd9..b67d045d93f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblem.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast; @@ -38,13 +39,19 @@ public interface IASTProblem extends IASTNode { /** * Answer a localized, human-readable message string which describes the - * problem. + * problem including its location * * @return a localized, human-readable message string which describes the * problem */ String getMessage(); + /** + * Returns a human-readable message string describing the problem, without + * location information. + */ + String getMessageWithoutLocation(); + /** * Return to the client a map between parameter names and values. * diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java index 9fe999998d0..7c909837577 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java @@ -163,6 +163,11 @@ public interface IASTTranslationUnit extends IASTNode, IAdaptable { */ public IASTProblem[] getPreprocessorProblems(); + /** + * Fast access to the count of preprocessor problems to support statistics. + */ + public int getPreprocessorProblemsCount(); + /** * Get the translation unit's full path. * @return String representation of path. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java new file mode 100644 index 00000000000..aec81fade78 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2004, 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) + *******************************************************************************/ +package org.eclipse.cdt.internal.core.dom.parser; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.internal.core.parser.ParserMessages; + + +/** + * Models problems, all problems should derive from this class. + */ +public class ASTProblem extends ASTNode implements IASTProblem { + + private final int id; + private final char[] arg; + private boolean isError= false; + + public ASTProblem(IASTNode parent, ASTNodeProperty property, int id, char[] arg, boolean isError, int startNumber, int endNumber) { + setParent(parent); + setPropertyInParent(property); + setOffset(startNumber); + setLength(endNumber-startNumber); + + this.isError= isError; + this.id = id; + this.arg = arg; + } + + public ASTProblem(int id, char[] arg, boolean isError) { + this.id = id; + this.arg = arg; + this.isError= isError; + } + + public int getID() { + return id; + } + + public boolean isError() { + return isError; + } + + public boolean isWarning() { + return !isError; + } + + public String getMessage() { + String msg= getMessageWithoutLocation(); + + IASTFileLocation f = getFileLocation(); + String file = null; + int line = 0; + if( f == null ) + { + file = ""; //$NON-NLS-1$ + } else { + file = f.getFileName(); + line = f.getStartingLineNumber(); + } + Object[] args = new Object[] { msg, file, new Integer(line) }; + return ParserMessages.getFormattedString(PROBLEM_PATTERN, args); + } + + public String getMessageWithoutLocation() { + String msg = errorMessages.get(new Integer(id)); + if (msg == null) + msg = ""; //$NON-NLS-1$ + + if (arg != null) { + return MessageFormat.format(msg, new Object[] { new String(arg) }); + } + return msg; + } + + public boolean checkCategory(int bitmask) { + return ((id & bitmask) != 0); + } + + public String getArguments() { + return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ + } + + + protected static final Map errorMessages; + static { + errorMessages = new HashMap(); + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_WARNING), + ParserMessages.getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_DEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_UNBALANCE_CONDITION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_MACRO_USAGE_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_CIRCULAR_INCLUSION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_DIRECTIVE), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_MACRO_PASTING_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), + ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_INVALID_VA_ARGS), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_INVALID_ESCAPECHAR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_UNBOUNDED_STRING), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_FLOATING_POINT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_HEX_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_OCTAL_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_DECIMAL_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), + ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_DIVIDE_BY_ZERO), + ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_MISSING_R_PAREN), + ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_ILLEGAL_IDENTIFIER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_UNEXPECTED_EOF), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SCANNER_BAD_CHARACTER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ + errorMessages.put(new Integer(IASTProblem.SYNTAX_ERROR), + ParserMessages.getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ + } + + protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$ +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java index f216bb1d393..aecaad8b69c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java @@ -1,265 +1,32 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) - * Anton Leherbauer (Wind River Systems) + * IBM - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTFileLocation; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTProblem; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.internal.core.parser.ParserMessages; +import org.eclipse.cdt.internal.core.dom.parser.ASTProblem; /** - * @author jcamelon + * C-specific implementation of ASTProblem, allows an action to visit a problem. */ -public class CASTProblem extends CASTNode implements IASTProblem { +public class CASTProblem extends ASTProblem { - - private final char[] arg; - - private final int id; - - private final boolean isError; - - private final boolean isWarning; - - private String message = null; - - public CASTProblem(int id, char[] arg, boolean warn, boolean error) { - this.id = id; - this.arg = arg; - this.isWarning = warn; - this.isError = error; + public CASTProblem(int id, char[] arg, boolean isError) { + super(id, arg, isError); } - public int getID() { - return id; - } - - - public boolean isError() { - return isError; - } - - public boolean isWarning() { - return isWarning; - } - - protected static final Map errorMessages; - static { - errorMessages = new HashMap(); - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ - errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_WARNING), ParserMessages - .getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_DEFN), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_UNBALANCE_CONDITION), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ - errorMessages - .put( - new Integer( - IASTProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_MACRO_USAGE_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_CIRCULAR_INCLUSION), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_DIRECTIVE), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_MACRO_PASTING_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ - errorMessages - .put( - new Integer( - IASTProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_VA_ARGS), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_INVALID_ESCAPECHAR), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_UNBOUNDED_STRING), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_FLOATING_POINT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_HEX_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_OCTAL_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_DECIMAL_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_DIVIDE_BY_ZERO), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_MISSING_R_PAREN), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_ILLEGAL_IDENTIFIER), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_UNEXPECTED_EOF), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_CHARACTER), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ - errorMessages.put(new Integer(IASTProblem.SYNTAX_ERROR), ParserMessages - .getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ - } - - protected final static String AST_PROBLEM_PATTERN = "BaseProblemFactory.astProblemPattern"; //$NON-NLS-1$ - - public String getMessage() { - if (message != null) - return message; - - String msg = (String) errorMessages.get(new Integer(id)); - if (msg == null) - msg = ""; //$NON-NLS-1$ - - if (arg != null) { - msg = MessageFormat.format(msg, new Object[] { new String(arg) }); - } - - - String file = null; - int offset = 0; - IASTFileLocation f = getFileLocation(); - if( f == null ) - { - file = ""; //$NON-NLS-1$ - offset = 0; - } - else - { - file = f.getFileName(); - offset = f.getNodeOffset(); - } - - Object[] args = new Object[] { msg, file, new Integer( offset ) }; - message = ParserMessages.getFormattedString(AST_PROBLEM_PATTERN, args); - return message; - } - - - public boolean checkCategory(int bitmask) { - return ((id & bitmask) != 0); - } - - - public String getArguments() { - return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ - } - - public IASTTranslationUnit getTranslationUnit() { - if (this instanceof IASTTranslationUnit) - return (IASTTranslationUnit) this; - IASTNode node = getParent(); - while (!(node instanceof IASTTranslationUnit) && node != null) { - node = node.getParent(); - } - return (IASTTranslationUnit) node; - } - - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitProblems ){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java index c9f0a57f137..3fb8783bad9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemDeclaration.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * IBM - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -29,6 +30,7 @@ public class CASTProblemDeclaration extends CASTProblemOwner implements super(problem); } + @Override public boolean accept( ASTVisitor action ){ if( action.shouldVisitDeclarations ){ switch( action.visit( this ) ){ @@ -37,6 +39,7 @@ public class CASTProblemDeclaration extends CASTProblemOwner implements default : break; } } + super.accept(action); // visits the problem if( action.shouldVisitDeclarations ){ switch( action.leave( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -46,5 +49,4 @@ public class CASTProblemDeclaration extends CASTProblemOwner implements } return true; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java index 77aef7f151d..1f4041aae68 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemExpression.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * IBM - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -29,6 +30,7 @@ public class CASTProblemExpression extends CASTProblemOwner implements IASTProbl super(problem); } + @Override public boolean accept( ASTVisitor action ){ if( action.shouldVisitExpressions ){ switch( action.visit( this ) ){ @@ -37,6 +39,7 @@ public class CASTProblemExpression extends CASTProblemOwner implements IASTProbl default : break; } } + super.accept(action); // visits the problem if( action.shouldVisitExpressions ){ switch( action.leave( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java index 404c8c84478..c84818965c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemOwner.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemHolder; @@ -38,5 +40,21 @@ abstract class CASTProblemOwner extends CASTNode implements IASTProblemHolder { p.setPropertyInParent(PROBLEM); } } - + + @Override + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitProblems ){ + switch( action.visit( getProblem() ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + switch( action.leave( getProblem() ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java index 6292014deda..91740787c4c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblemStatement.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Yuan Zhang / Beth Tibbitts (IBM Research) + * IBM - Initial API and implementation + * Yuan Zhang / Beth Tibbitts (IBM Research) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.c; @@ -19,15 +20,15 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; * @author jcamelon */ public class CASTProblemStatement extends CASTProblemOwner implements IASTProblemStatement { - - - public CASTProblemStatement() { + + public CASTProblemStatement() { } public CASTProblemStatement(IASTProblem problem) { super(problem); } + @Override public boolean accept( ASTVisitor action ){ if( action.shouldVisitStatements ){ switch( action.visit( this ) ){ @@ -36,6 +37,7 @@ public class CASTProblemStatement extends CASTProblemOwner implements IASTProble default : break; } } + super.accept(action); // visits the problem if( action.shouldVisitStatements ){ switch( action.leave( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java index b4237588b52..04835a2ae09 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java @@ -78,7 +78,8 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit private boolean fIsHeader= true; private IIndexFileSet fIndexFileSet; - public IASTTranslationUnit getTranslationUnit() { + @Override + public IASTTranslationUnit getTranslationUnit() { return this; } @@ -246,6 +247,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) */ + @Override public int visit(IASTDeclaration declaration) { // use declarations to determine if the search has gone past the // offset (i.e. don't know the order the visitor visits the nodes) @@ -261,6 +263,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) */ + @Override public int visit(IASTDeclarator declarator) { int ret = processNode(declarator); @@ -283,6 +286,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) */ + @Override public int visit(ICASTDesignator designator) { return processNode(designator); } @@ -292,6 +296,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) */ + @Override public int visit(IASTDeclSpecifier declSpec) { return processNode(declSpec); } @@ -301,6 +306,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) */ + @Override public int visit(IASTEnumerator enumerator) { return processNode(enumerator); } @@ -310,6 +316,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) */ + @Override public int visit(IASTExpression expression) { return processNode(expression); } @@ -319,6 +326,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) */ + @Override public int visit(IASTInitializer initializer) { return processNode(initializer); } @@ -328,6 +336,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) */ + @Override public int visit(IASTName name) { if (name.toString() != null) return processNode(name); @@ -339,6 +348,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) */ + @Override public int visit( IASTParameterDeclaration parameterDeclaration) { return processNode(parameterDeclaration); @@ -349,6 +359,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) */ + @Override public int visit(IASTStatement statement) { return processNode(statement); } @@ -358,6 +369,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit * * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) */ + @Override public int visit(IASTTypeId typeId) { return processNode(typeId); } @@ -469,6 +481,11 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit return result; } + + public int getPreprocessorProblemsCount() { + return resolver == null ? 0 : resolver.getScannerProblemsCount(); + } + /* * (non-Javadoc) * @@ -480,7 +497,8 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit return new String(resolver.getTranslationUnitPath()); } - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitTranslationUnit){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java index 906e2d25d9c..f37c6d5b76a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java @@ -201,9 +201,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { result.addInitializer(initializer); } else { ICASTDesignatedInitializer desigInitializer = createDesignatorInitializer(); - ((CASTNode) desigInitializer).setOffsetAndLength( - ((CASTNode) newDesignators.get(0)).getOffset(), - ((CASTNode)initializer).getOffset() + ((CASTNode)initializer).getLength() - ((CASTNode) newDesignators.get(0)).getOffset()); + ((ASTNode) desigInitializer).setOffsetAndLength( + ((ASTNode) newDesignators.get(0)).getOffset(), + ((ASTNode)initializer).getOffset() + ((ASTNode)initializer).getLength() - ((ASTNode) newDesignators.get(0)).getOffset()); for (int i = 0; i < newDesignators.size(); ++i) { ICASTDesignator d = (ICASTDesignator) newDesignators.get(i); desigInitializer.addDesignator(d); @@ -390,7 +390,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTFieldDesignator(); } - protected IASTDeclaration declaration() throws EndOfFileException, + @Override + protected IASTDeclaration declaration() throws EndOfFileException, BacktrackException { switch (LT(1)) { case IToken.t_asm: @@ -406,7 +407,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * @throws EndOfFileException */ - protected IASTDeclaration simpleDeclaration() throws BacktrackException, + @Override + protected IASTDeclaration simpleDeclaration() throws BacktrackException, EndOfFileException { IToken firstToken = LA(1); int firstOffset = firstToken.getOffset(); @@ -511,7 +513,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { /** * @return */ - protected IASTSimpleDeclaration createSimpleDeclaration() { + @Override + protected IASTSimpleDeclaration createSimpleDeclaration() { return new CASTSimpleDeclaration(); } @@ -534,7 +537,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * * translationUnit : (declaration)* */ - protected void translationUnit() { + @Override + protected void translationUnit() { try { translationUnit = createTranslationUnit(); translationUnit.setIndex(index); @@ -569,10 +573,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTDeclaration[] declarations = translationUnit.getDeclarations(); // As expected if (declarations.length != 0) { - CASTNode d = (CASTNode) declarations[declarations.length-1]; - ((CASTNode) translationUnit).setLength(d.getOffset() + d.getLength()); + ASTNode d = (ASTNode) declarations[declarations.length-1]; + ((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength()); } else - ((CASTNode) translationUnit).setLength(0); + ((ASTNode) translationUnit).setLength(0); break; } catch (BacktrackException b) { try { @@ -580,7 +584,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { IASTProblem p = failParse(b); IASTProblemDeclaration pd = createProblemDeclaration(); pd.setProblem(p); - ((CASTNode) pd).setOffsetAndLength(((CASTNode) p).getOffset(), ((CASTNode) p).getLength()); + ((ASTNode) pd).setOffsetAndLength(((ASTNode) p).getOffset(), ((ASTNode) p).getLength()); translationUnit.addDeclaration(pd); errorHandling(); if (lastBacktrack != -1 && lastBacktrack == LA(1).hashCode()) { @@ -620,7 +624,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param expression * @throws BacktrackException */ - protected IASTExpression assignmentExpression() throws EndOfFileException, + @Override + protected IASTExpression assignmentExpression() throws EndOfFileException, BacktrackException { if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tLBRACE && supportStatementsInExpressions) { IASTExpression resultExpression = compoundStatementExpression(); @@ -664,7 +669,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param expression * @throws BacktrackException */ - protected IASTExpression relationalExpression() throws BacktrackException, + @Override + protected IASTExpression relationalExpression() throws BacktrackException, EndOfFileException { IASTExpression firstExpression = shiftExpression(); @@ -705,7 +711,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param expression * @throws BacktrackException */ - protected IASTExpression multiplicativeExpression() + @Override + protected IASTExpression multiplicativeExpression() throws BacktrackException, EndOfFileException { IASTExpression firstExpression = castExpression(); for (;;) { @@ -740,7 +747,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { /** * castExpression : unaryExpression | "(" typeId ")" castExpression */ - protected IASTExpression castExpression() throws EndOfFileException, + @Override + protected IASTExpression castExpression() throws EndOfFileException, BacktrackException { // TO DO: we need proper symbol checkint to ensure type name if (LT(1) == IToken.tLPAREN) { @@ -807,7 +815,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param expression * @throws BacktrackException */ - protected IASTExpression unaryExpression() throws EndOfFileException, + @Override + protected IASTExpression unaryExpression() throws EndOfFileException, BacktrackException { switch (LT(1)) { case IToken.tSTAR: @@ -850,7 +859,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param op * @return */ - protected IASTExpression buildTypeIdExpression(int op, IASTTypeId typeId, + @Override + protected IASTExpression buildTypeIdExpression(int op, IASTTypeId typeId, int startingOffset, int endingOffset) { IASTTypeIdExpression result = createTypeIdExpression(); result.setOperator(op); @@ -953,13 +963,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { int offset = consume().getEndOffset(); firstExpression = buildUnaryExpression( IASTUnaryExpression.op_postFixIncr, firstExpression, - ((CASTNode) firstExpression).getOffset(), offset); + ((ASTNode) firstExpression).getOffset(), offset); break; case IToken.tDECR: offset = consume().getEndOffset(); firstExpression = buildUnaryExpression( IASTUnaryExpression.op_postFixDecr, firstExpression, - ((CASTNode) firstExpression).getOffset(), offset); + ((ASTNode) firstExpression).getOffset(), offset); break; case IToken.tDOT: // member access @@ -1130,11 +1140,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { /** * @return */ - protected IASTIdExpression createIdExpression() { + @Override + protected IASTIdExpression createIdExpression() { return new CASTIdExpression(); } - protected IASTTypeId typeId(boolean forNewExpression) throws EndOfFileException { + @Override + protected IASTTypeId typeId(boolean forNewExpression) throws EndOfFileException { if (!canBeTypeSpecifier()) { return null; } @@ -1570,7 +1582,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { /** * @return */ - protected IASTNamedTypeSpecifier createNamedTypeSpecifier() { + @Override + protected IASTNamedTypeSpecifier createNamedTypeSpecifier() { return new CASTTypedefNameSpecifier(); } @@ -1657,14 +1670,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { failParseWithErrorHandling(); } } - ((CASTNode) result).setLength(endOffset - classKey.getOffset()); + ((ASTNode) result).setLength(endOffset - classKey.getOffset()); return result; } /** * @return */ - protected IASTName createName() { + @Override + protected IASTName createName() { return new CASTName(); } @@ -1712,7 +1726,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTElaboratedTypeSpecifier(); } - protected IASTDeclarator initDeclarator() throws EndOfFileException, BacktrackException { + @Override + protected IASTDeclarator initDeclarator() throws EndOfFileException, BacktrackException { IASTDeclarator d = declarator(); IASTInitializer i = optionalCInitializer(); @@ -2004,7 +2019,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { * @param t * @return */ - protected IASTName createName(IToken t) { + @Override + protected IASTName createName(IToken t) { IASTName n = new CASTName(t.getCharImage()); switch (t.getType()) { case IToken.tCOMPLETION: @@ -2158,47 +2174,58 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } - protected IASTTranslationUnit getTranslationUnit() { + @Override + protected IASTTranslationUnit getTranslationUnit() { return translationUnit; } - protected IASTCompoundStatement createCompoundStatement() { + @Override + protected IASTCompoundStatement createCompoundStatement() { return new CASTCompoundStatement(); } - protected IASTBinaryExpression createBinaryExpression() { + @Override + protected IASTBinaryExpression createBinaryExpression() { return new CASTBinaryExpression(); } - protected IASTConditionalExpression createConditionalExpression() { + @Override + protected IASTConditionalExpression createConditionalExpression() { return new CASTConditionalExpression(); } - protected IASTUnaryExpression createUnaryExpression() { + @Override + protected IASTUnaryExpression createUnaryExpression() { return new CASTUnaryExpression(); } - protected IGNUASTCompoundStatementExpression createCompoundStatementExpression() { + @Override + protected IGNUASTCompoundStatementExpression createCompoundStatementExpression() { return new CASTCompoundStatementExpression(); } - protected IASTExpressionList createExpressionList() { + @Override + protected IASTExpressionList createExpressionList() { return new CASTExpressionList(); } - protected IASTEnumerator createEnumerator() { + @Override + protected IASTEnumerator createEnumerator() { return new CASTEnumerator(); } - protected IASTLabelStatement createLabelStatement() { + @Override + protected IASTLabelStatement createLabelStatement() { return new CASTLabelStatement(); } - protected IASTGotoStatement createGoToStatement() { + @Override + protected IASTGotoStatement createGoToStatement() { return new CASTGotoStatement(); } - protected IASTReturnStatement createReturnStatement() { + @Override + protected IASTReturnStatement createReturnStatement() { return new CASTReturnStatement(); } @@ -2206,23 +2233,28 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTForStatement(); } - protected IASTContinueStatement createContinueStatement() { + @Override + protected IASTContinueStatement createContinueStatement() { return new CASTContinueStatement(); } - protected IASTDoStatement createDoStatement() { + @Override + protected IASTDoStatement createDoStatement() { return new CASTDoStatement(); } - protected IASTBreakStatement createBreakStatement() { + @Override + protected IASTBreakStatement createBreakStatement() { return new CASTBreakStatement(); } - protected IASTWhileStatement createWhileStatement() { + @Override + protected IASTWhileStatement createWhileStatement() { return new CASTWhileStatement(); } - protected IASTNullStatement createNullStatement() { + @Override + protected IASTNullStatement createNullStatement() { return new CASTNullStatement(); } @@ -2234,35 +2266,43 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return new CASTIfStatement(); } - protected IASTDefaultStatement createDefaultStatement() { + @Override + protected IASTDefaultStatement createDefaultStatement() { return new CASTDefaultStatement(); } - protected IASTCaseStatement createCaseStatement() { + @Override + protected IASTCaseStatement createCaseStatement() { return new CASTCaseStatement(); } - protected IASTExpressionStatement createExpressionStatement() { + @Override + protected IASTExpressionStatement createExpressionStatement() { return new CASTExpressionStatement(); } - protected IASTDeclarationStatement createDeclarationStatement() { + @Override + protected IASTDeclarationStatement createDeclarationStatement() { return new CASTDeclarationStatement(); } - protected IASTASMDeclaration createASMDirective() { + @Override + protected IASTASMDeclaration createASMDirective() { return new CASTASMDeclaration(); } - protected IASTEnumerationSpecifier createEnumerationSpecifier() { + @Override + protected IASTEnumerationSpecifier createEnumerationSpecifier() { return new CASTEnumerationSpecifier(); } - protected IASTCastExpression createCastExpression() { + @Override + protected IASTCastExpression createCastExpression() { return new CASTCastExpression(); } - protected IASTStatement statement() throws EndOfFileException, + @Override + protected IASTStatement statement() throws EndOfFileException, BacktrackException { switch (LT(1)) { // labeled statements @@ -2308,20 +2348,24 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { } - protected void nullifyTranslationUnit() { + @Override + protected void nullifyTranslationUnit() { translationUnit = null; } - protected IASTProblemStatement createProblemStatement() { + @Override + protected IASTProblemStatement createProblemStatement() { return new CASTProblemStatement(); } - protected IASTProblemExpression createProblemExpression() { + @Override + protected IASTProblemExpression createProblemExpression() { return new CASTProblemExpression(); } - protected IASTProblem createProblem(int signal, int offset, int length) { - IASTProblem result = new CASTProblem(signal, EMPTY_STRING, false, true); + @Override + protected IASTProblem createProblem(int signal, int offset, int length) { + IASTProblem result = new CASTProblem(signal, EMPTY_STRING, true); ((ASTNode) result).setOffsetAndLength(offset, length); return result; } @@ -2427,15 +2471,18 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser { return pd; } - protected ASTVisitor createVisitor() { + @Override + protected ASTVisitor createVisitor() { return EMPTY_VISITOR; } - protected IASTAmbiguousStatement createAmbiguousStatement() { + @Override + protected IASTAmbiguousStatement createAmbiguousStatement() { return new CASTAmbiguousStatement(); } - protected IASTAmbiguousExpression createAmbiguousExpression() { + @Override + protected IASTAmbiguousExpression createAmbiguousExpression() { return new CASTAmbiguousExpression(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java index e3e59f98112..3390543434d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; @@ -29,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; /** @@ -166,7 +168,8 @@ public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionCo return binding; } - public String toString() { + @Override + public String toString() { if (name == EMPTY_CHAR_ARRAY) return EMPTY_STRING; return new String(name); @@ -180,7 +183,8 @@ public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionCo this.name = name; } - public boolean accept(ASTVisitor action) { + @Override + public boolean accept(ASTVisitor action) { if (action.shouldVisitNames) { switch (action.visit(this)) { case ASTVisitor.PROCESS_ABORT: @@ -248,4 +252,11 @@ public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionCo } return false; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTName#getLinkage() + */ + public ILinkage getLinkage() { + return Linkage.CPP_LINKAGE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java index f6f40bb9e62..3f41d70c7bd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNode.java @@ -1,25 +1,19 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import org.eclipse.cdt.core.dom.ILinkage; -import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; /** * @author jcamelon */ public abstract class CPPASTNode extends ASTNode { - - public ILinkage getLinkage() { - return Linkage.CPP_LINKAGE; - } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java index 757a9e7ade6..983e6ef9f81 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java @@ -1,258 +1,31 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Anton Leherbauer (Wind River Systems) + * IBM - Initial API and implementation + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.cdt.core.dom.ast.ASTVisitor; -import org.eclipse.cdt.core.dom.ast.IASTFileLocation; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTProblem; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.internal.core.parser.ParserMessages; +import org.eclipse.cdt.internal.core.dom.parser.ASTProblem; /** - * @author jcamelon + * cpp-specific implementation allows actions to visit the problem. */ -public class CPPASTProblem extends CPPASTNode implements IASTProblem { +public class CPPASTProblem extends ASTProblem { - private final char[] arg; - private final int id; - private final boolean isError; - private final boolean isWarning; - private String message = null; - - - public CPPASTProblem(int id, char[] arg, boolean warn, boolean error) { - this.id = id; - this.arg = arg; - this.isWarning = warn; - this.isError = error; + public CPPASTProblem(int id, char[] arg, boolean isError) { + super(id, arg, isError); } - - public int getID() { - return id; - } - - public boolean isError() { - return isError; - } - - public boolean isWarning() { - return isWarning; - } - - protected static final Map errorMessages; - static { - errorMessages = new HashMap(); - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ - errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_WARNING), ParserMessages - .getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_DEFN), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_UNBALANCE_CONDITION), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ - errorMessages - .put( - new Integer( - IASTProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_MACRO_USAGE_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_CIRCULAR_INCLUSION), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_DIRECTIVE), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_MACRO_PASTING_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ - errorMessages - .put( - new Integer( - IASTProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_VA_ARGS), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_INVALID_ESCAPECHAR), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_UNBOUNDED_STRING), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_FLOATING_POINT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_HEX_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_OCTAL_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_DECIMAL_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_DIVIDE_BY_ZERO), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_MISSING_R_PAREN), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_ILLEGAL_IDENTIFIER), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_UNEXPECTED_EOF), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_CHARACTER), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ - errorMessages.put(new Integer(IASTProblem.SYNTAX_ERROR), ParserMessages - .getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ - } - - protected final static String AST_PROBLEM_PATTERN = "BaseProblemFactory.astProblemPattern"; //$NON-NLS-1$ - - public String getMessage() { - if (message != null) - return message; - - String msg = (String) errorMessages.get(new Integer(id)); - if (msg == null) - msg = ""; //$NON-NLS-1$ - - if (arg != null) { - msg = MessageFormat.format(msg, new Object[] { new String(arg) }); - } - - - String file = null; - int offset = 0; - IASTFileLocation f = getFileLocation(); - if( f == null ) - { - file = ""; //$NON-NLS-1$ - offset = 0; - } - else - { - file = f.getFileName(); - offset = f.getNodeOffset(); - } - Object[] args = new Object[] { msg, file, new Integer(offset) }; - message = ParserMessages.getFormattedString(AST_PROBLEM_PATTERN, args); - return message; - } - - - public boolean checkCategory(int bitmask) { - return ((id & bitmask) != 0); - } - - public String getArguments() { - return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ - } - - public IASTTranslationUnit getTranslationUnit() { - if (this instanceof IASTTranslationUnit) - return (IASTTranslationUnit) this; - IASTNode node = getParent(); - while (!(node instanceof IASTTranslationUnit) && node != null) { - node = node.getParent(); - } - return (IASTTranslationUnit) node; - } - - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitProblems ){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java index 2487d62bf2f..ce3e4557847 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemDeclaration.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -19,7 +20,8 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration; public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements IASTProblemDeclaration { - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitDeclarations ){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -27,6 +29,7 @@ public class CPPASTProblemDeclaration extends CPPASTProblemOwner implements default : break; } } + super.accept(action); // visits the problem if( action.shouldVisitDeclarations ){ switch( action.leave( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java index fdfb1e99276..6b89f629ec7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemExpression.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -20,7 +21,8 @@ import org.eclipse.cdt.core.dom.ast.IType; public class CPPASTProblemExpression extends CPPASTProblemOwner implements IASTProblemExpression { - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitExpressions ){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -28,6 +30,7 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements default : break; } } + super.accept(action); // visits the problem if( action.shouldVisitExpressions ){ switch( action.leave( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -41,5 +44,4 @@ public class CPPASTProblemExpression extends CPPASTProblemOwner implements public IType getExpressionType() { return null; } - } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java index 552080ea0d5..e0633f25c03 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemOwner.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemHolder; @@ -39,4 +41,21 @@ abstract class CPPASTProblemOwner extends CPPASTNode implements IASTProblemHolde p.setPropertyInParent(PROBLEM); } } + + @Override + public boolean accept( ASTVisitor action ){ + if( action.shouldVisitProblems ){ + switch( action.visit( getProblem() ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + switch( action.leave( getProblem() ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java index 35e272da1b7..9caf0ec9223 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemStatement.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; @@ -18,7 +19,8 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemStatement; */ public class CPPASTProblemStatement extends CPPASTProblemOwner implements IASTProblemStatement { - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitStatements ){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -26,6 +28,7 @@ public class CPPASTProblemStatement extends CPPASTProblemOwner implements default : break; } } + super.accept(action); // visits the problem if( action.shouldVisitStatements ){ switch( action.leave( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java index c293a2896f7..72be16fcc67 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblemTypeId.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId; @@ -40,4 +42,20 @@ public class CPPASTProblemTypeId extends CPPASTTypeId implements IASTProblemType } } + @Override + public final boolean accept( ASTVisitor action ){ + if( action.shouldVisitProblems ){ + switch( action.visit( getProblem() ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + switch( action.leave( getProblem() ) ){ + case ASTVisitor.PROCESS_ABORT : return false; + case ASTVisitor.PROCESS_SKIP : return true; + default : break; + } + } + return true; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java index 3abf69c65fe..52e92448697 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTQualifiedName.java @@ -6,14 +6,16 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Bryan Wilkinson (QNX) + * IBM - Initial API and implementation + * Bryan Wilkinson (QNX) + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; @@ -22,8 +24,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumeration; +import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName; @@ -34,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.Linkage; /** * @author jcamelon @@ -321,4 +324,11 @@ public class CPPASTQualifiedName extends CPPASTNode implements return CharArrayUtils.equals(potential, 0, name.length, name, true); return CharArrayUtils.equals(potential, name); } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTName#getLinkage() + */ + public ILinkage getLinkage() { + return Linkage.CPP_LINKAGE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java index 4a4c2370858..dbfc1a5ab82 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTemplateId.java @@ -1,15 +1,17 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompletionContext; import org.eclipse.cdt.core.dom.ast.IASTExpression; @@ -20,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; /** @@ -96,11 +99,13 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I public char[] toCharArray() { return templateName.toCharArray(); } - public String toString() { + @Override + public String toString() { return templateName.toString(); } - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitNames ){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -173,4 +178,11 @@ public class CPPASTTemplateId extends CPPASTNode implements ICPPASTTemplateId, I binding= new CPPASTName.RecursionResolvingBinding(this); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTName#getLinkage() + */ + public ILinkage getLinkage() { + return Linkage.CPP_LINKAGE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java index 65bd878155b..c826b8ae766 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.DOMException; @@ -62,6 +63,7 @@ import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.util.ArrayUtil; +import org.eclipse.cdt.internal.core.dom.Linkage; import org.eclipse.cdt.internal.core.dom.parser.ASTInternal; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; @@ -96,7 +98,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat public CPPASTTranslationUnit() { } - public IASTTranslationUnit getTranslationUnit() { + @Override + public IASTTranslationUnit getTranslationUnit() { return this; } @@ -284,7 +287,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat } - public int visit(IASTDeclaration declaration) { + @Override + public int visit(IASTDeclaration declaration) { // use declarations to determine if the search has gone past the offset (i.e. don't know the order the visitor visits the nodes) if (declaration instanceof ASTNode && ((ASTNode)declaration).getOffset() > offset) return PROCESS_ABORT; @@ -293,7 +297,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat } - public int visit(IASTDeclarator declarator) { + @Override + public int visit(IASTDeclarator declarator) { int ret = processNode(declarator); IASTPointerOperator[] ops = declarator.getPointerOperators(); @@ -328,38 +333,46 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat return processNode(designator); } - public int visit(IASTDeclSpecifier declSpec) { + @Override + public int visit(IASTDeclSpecifier declSpec) { return processNode(declSpec); } - public int visit(IASTEnumerator enumerator) { + @Override + public int visit(IASTEnumerator enumerator) { return processNode(enumerator); } - public int visit(IASTExpression expression) { + @Override + public int visit(IASTExpression expression) { return processNode(expression); } - public int visit(IASTInitializer initializer) { + @Override + public int visit(IASTInitializer initializer) { return processNode(initializer); } - public int visit(IASTName name) { + @Override + public int visit(IASTName name) { if ( name.toString() != null ) return processNode(name); return PROCESS_CONTINUE; } - public int visit( + @Override + public int visit( IASTParameterDeclaration parameterDeclaration) { return processNode(parameterDeclaration); } - public int visit(IASTStatement statement) { + @Override + public int visit(IASTStatement statement) { return processNode(statement); } - public int visit(IASTTypeId typeId) { + @Override + public int visit(IASTTypeId typeId) { return processNode(typeId); } @@ -436,13 +449,18 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat return result; } + public int getPreprocessorProblemsCount() { + return resolver == null ? 0 : resolver.getScannerProblemsCount(); + } + public String getFilePath() { if (resolver == null) return EMPTY_STRING; return new String(resolver.getTranslationUnitPath()); } - public boolean accept( ASTVisitor action ){ + @Override + public boolean accept( ASTVisitor action ){ if( action.shouldVisitTranslationUnit){ switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false; @@ -566,4 +584,11 @@ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslat IIndexFileSet getFileSet() { return fIndexFileSet; } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLinkage() + */ + public ILinkage getLinkage() { + return Linkage.CPP_LINKAGE; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 6d5c11dbf8d..1f8a05574c4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -1300,7 +1300,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } } - ((CPPASTNode) result).setLength(lastOffset - startingOffset); + ((ASTNode) result).setLength(lastOffset - startingOffset); return result; } @@ -2019,7 +2019,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTProblem p = failParse(bt); IASTProblemDeclaration pd = createProblemDeclaration(); pd.setProblem(p); - ((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p)); + ((ASTNode) pd).setOffsetAndLength(((ASTNode) p)); linkage.addDeclaration(pd); errorHandling(); if (checkToken == LA(1).hashCode()) @@ -2031,14 +2031,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } // consume the } int endOffset = consume(IToken.tRBRACE).getEndOffset(); - ((CPPASTNode) linkage).setLength(endOffset - firstToken.getOffset()); + ((ASTNode) linkage).setLength(endOffset - firstToken.getOffset()); return linkage; } // single declaration IASTDeclaration d = declaration(); linkage.addDeclaration(d); - ((CPPASTNode) linkage).setLength(calculateEndOffset(d) - firstToken.getOffset()); + ((ASTNode) linkage).setLength(calculateEndOffset(d) - firstToken.getOffset()); return linkage; } @@ -2406,7 +2406,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return d2; IASTAmbiguousDeclaration result = createAmbiguousDeclaration(); - ((CPPASTNode) result).setOffsetAndLength((ASTNode) d1); + ((ASTNode) result).setOffsetAndLength((ASTNode) d1); result.addDeclaration(d1); result.addDeclaration(d2); return result; @@ -2465,7 +2465,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTProblem p = failParse(bt); IASTProblemDeclaration pd = createProblemDeclaration(); pd.setProblem(p); - ((CPPASTNode) pd).setOffsetAndLength((CPPASTNode) p); + ((ASTNode) pd).setOffsetAndLength((ASTNode) p); namespaceDefinition.addDeclaration(pd); errorHandling(); if (checkToken == LA(1).hashCode()) @@ -2478,7 +2478,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // consume the } int end = consume().getEndOffset(); - ((CPPASTNode) namespaceDefinition).setLength(end - first.getOffset()); + ((ASTNode) namespaceDefinition).setLength(end - first.getOffset()); return namespaceDefinition; } else if (LT(1) == IToken.tASSIGN) { IToken assign = consume(); @@ -2791,7 +2791,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (s != null) { funcDefinition.setBody(s); } - ((CPPASTNode) funcDefinition).setLength(calculateEndOffset(s) - firstOffset); + ((ASTNode) funcDefinition).setLength(calculateEndOffset(s) - firstOffset); if (hasFunctionTryBlock && declarator instanceof ICPPASTFunctionTryBlockDeclarator) { List handlers = new ArrayList(DEFAULT_CATCH_HANDLER_LIST_SIZE); @@ -2799,7 +2799,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { for (int i = 0; i < handlers.size(); ++i) { ICPPASTCatchHandler handler = (ICPPASTCatchHandler) handlers.get(i); ((ICPPASTFunctionTryBlockDeclarator) declarator).addCatchHandler(handler); - ((CPPASTNode) funcDefinition).setLength(calculateEndOffset(handler) - firstOffset); + ((ASTNode) funcDefinition).setLength(calculateEndOffset(handler) - firstOffset); } } return funcDefinition; @@ -3249,7 +3249,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { elabSpec.setStorageClass(storageClass); elabSpec.setVirtual(isVirtual); elabSpec.setExplicit(isExplicit); - ((CPPASTNode) elabSpec).setOffsetAndLength(startOffset, calculateEndOffset(elabSpec) - startOffset); + ((ASTNode) elabSpec).setOffsetAndLength(startOffset, calculateEndOffset(elabSpec) - startOffset); return elabSpec; } if (enumSpec != null) { @@ -3262,7 +3262,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ((ICPPASTDeclSpecifier) enumSpec).setExplicit(isExplicit); enumSpec.setInline(isInline); enumSpec.setStorageClass(storageClass); - ((CPPASTNode) enumSpec).setOffsetAndLength(startOffset, calculateEndOffset(enumSpec) - startOffset); + ((ASTNode) enumSpec).setOffsetAndLength(startOffset, calculateEndOffset(enumSpec) - startOffset); return (ICPPASTDeclSpecifier) enumSpec; } if (classSpec != null) { @@ -3275,7 +3275,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { classSpec.setStorageClass(storageClass); classSpec.setVirtual(isVirtual); classSpec.setExplicit(isExplicit); - ((CPPASTNode) classSpec).setOffsetAndLength(startOffset, calculateEndOffset(classSpec) - startOffset); + ((ASTNode) classSpec).setOffsetAndLength(startOffset, calculateEndOffset(classSpec) - startOffset); return classSpec; } if (duple != null) { @@ -3292,7 +3292,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { nameSpec.setStorageClass(storageClass); nameSpec.setVirtual(isVirtual); nameSpec.setExplicit(isExplicit); - ((CPPASTNode) nameSpec).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset); + ((ASTNode) nameSpec).setOffsetAndLength(startOffset, last.getEndOffset() - startOffset); return nameSpec; } ICPPASTSimpleDeclSpecifier simpleDeclSpec = null; @@ -3716,7 +3716,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { before.getOffset(), before.getLength()); IASTProblemTypeId typeIdProblem = createTypeIDProblem(); typeIdProblem.setProblem(p); - ((CPPASTNode) typeIdProblem).setOffsetAndLength(((CPPASTNode) p)); + ((ASTNode) typeIdProblem).setOffsetAndLength(((ASTNode) p)); exceptionSpecIds.add(typeIdProblem); if (before == LA(1)) done = true; @@ -4035,7 +4035,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTProblem p = failParse(bt); IASTProblemDeclaration pd = createProblemDeclaration(); pd.setProblem(p); - ((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p)); + ((ASTNode) pd).setOffsetAndLength(((ASTNode) p)); astClassSpecifier.addMemberDeclaration(pd); if (checkToken == LA(1).hashCode()) errorHandling(); @@ -4211,7 +4211,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTProblem p = failParse(bte); IASTProblemDeclaration pd = createProblemDeclaration(); pd.setProblem(p); - ((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p)); + ((ASTNode) pd).setOffsetAndLength(((ASTNode) p)); decl = pd; } @@ -4308,10 +4308,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { failParseWithErrorHandling(); } catch (EndOfFileException e) { if (translationUnit.getDeclarations().length != 0) { - CPPASTNode d = (CPPASTNode) translationUnit.getDeclarations()[translationUnit.getDeclarations().length - 1]; - ((CPPASTNode) translationUnit).setLength(d.getOffset() + d.getLength()); + ASTNode d = (ASTNode) translationUnit.getDeclarations()[translationUnit.getDeclarations().length - 1]; + ((ASTNode) translationUnit).setLength(d.getOffset() + d.getLength()); } else - ((CPPASTNode) translationUnit).setLength(0); + ((ASTNode) translationUnit).setLength(0); break; } catch (BacktrackException b) { try { @@ -4319,7 +4319,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { IASTProblem p = failParse(b); IASTProblemDeclaration pd = createProblemDeclaration(); pd.setProblem(p); - ((CPPASTNode) pd).setOffsetAndLength(((CPPASTNode) p)); + ((ASTNode) pd).setOffsetAndLength(((ASTNode) p)); translationUnit.addDeclaration(pd); errorHandling(); } catch (EndOfFileException e) { @@ -4644,13 +4644,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { @Override protected IASTProblem createProblem(int signal, int offset, int length) { - IASTProblem result = new CPPASTProblem(signal, EMPTY_STRING, false, true); + IASTProblem result = new CPPASTProblem(signal, EMPTY_STRING, true); ((ASTNode) result).setOffsetAndLength(offset, length); ((ASTNode) result).setLength(length); return result; } - @Override protected IASTStatement parseWhileStatement() throws EndOfFileException, BacktrackException { int startOffset = consume().getOffset(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties index f5cfecd8930..5e828321b30 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserMessages.properties @@ -1,13 +1,14 @@ ############################################################################### -# Copyright (c) 2005, 2007 IBM Corporation and others. +# Copyright (c) 2005, 2008 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html # # Contributors: -# IBM Rational Software - Initial API and implementation -# Anton Leherbauer (Wind River Systems) +# IBM Rational Software - Initial API and implementation +# Anton Leherbauer (Wind River Systems) +# Markus Schorn (Wind River Systems) ############################################################################### IProblem.unknownFileName= @@ -26,12 +27,12 @@ QuickParseCallback.exception.constIterator=OffsetableIterator is a const iterato ScannerProblemFactory.error.preproc.error=#error encountered with text: {0} ScannerProblemFactory.error.preproc.warning=#warning encountered with text: {0} -ScannerProblemFactory.error.preproc.inclusionNotFound=Preprocessor Inclusion not found: {0} +ScannerProblemFactory.error.preproc.inclusionNotFound=Unresolved inclusion: {0} ScannerProblemFactory.error.preproc.definitionNotFound=Macro definition not found: {0} ScannerProblemFactory.error.preproc.invalidMacroDefn=Macro definition malformed for macro: {0} ScannerProblemFactory.error.preproc.invalidMacroRedefn=Invalid macro redefinition for macro : {0} -ScannerProblemFactory.error.preproc.unbalancedConditional=Preprocessor Conditionals unbalanced : {0} -ScannerProblemFactory.error.preproc.conditionalEval=Expression Evaluation error for condition : {0} +ScannerProblemFactory.error.preproc.unbalancedConditional=Preprocessor conditionals unbalanced : {0} +ScannerProblemFactory.error.preproc.conditionalEval=Expression evaluation error for condition : {0} ScannerProblemFactory.error.preproc.macroUsage=Macro usage error for macro : {0} ScannerProblemFactory.error.preproc.circularInclusion=Circular inclusion for file : {0} ScannerProblemFactory.error.preproc.invalidDirective=Invalid preprocessor directive : {0} @@ -54,7 +55,7 @@ ScannerProblemFactory.error.scanner.badConditionalExpression=Bad conditional exp ScannerProblemFactory.error.scanner.unexpectedEOF=Unexpected End Of File encountered ScannerProblemFactory.error.scanner.badCharacter=Bad character sequence encountered : {0} -ParserProblemFactory.error.syntax.syntaxError=Syntax error encountered +ParserProblemFactory.error.syntax.syntaxError=Syntax error ASTProblemFactory.error.semantic.uniqueNamePredefined=Attempt to introduce unique symbol failed : {0} ASTProblemFactory.error.semantic.nameNotFound=Attempt to use symbol failed : {0} @@ -64,8 +65,7 @@ ASTProblemFactory.error.semantic.malformedExpression=Malformed expression LineOffsetReconciler.error.couldNotResetReader=Could not reset Reader -BaseProblemFactory.problemPattern={0} in file: {1} on line: {2, number, integer}. -BaseProblemFactory.astProblemPattern={0} in file: {1} at offset: {2, number, integer}. +BaseProblemFactory.problemPattern={0} in file: {1}:{2, number, integer}. ASTProblemFactory.error.semantic.pst.ambiguousLookup=Ambiguity encountered during lookup: {0} ASTProblemFactory.error.semantic.pst.invalidType=Invalid type encountered in: {0} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTProblem.java deleted file mode 100644 index 128b87f4d4e..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTProblem.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * Anton Leherbauer (Wind River Systems) - *******************************************************************************/ -package org.eclipse.cdt.internal.core.parser.scanner; - -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.core.dom.ast.IASTFileLocation; -import org.eclipse.cdt.core.dom.ast.IASTProblem; -import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; -import org.eclipse.cdt.internal.core.parser.ParserMessages; - - -/** - * Models the problems found by the preprocessor or lexer. - */ -class ASTProblem extends ASTPreprocessorNode implements IASTProblem { - - private final int id; - private final char[] arg; - - private String message = null; - - public ASTProblem(IASTTranslationUnit tu, int id, char[] arg, int startNumber, int endNumber) { - super(tu, IASTTranslationUnit.SCANNER_PROBLEM, startNumber, endNumber); - this.id = id; - this.arg = arg; - } - - public int getID() { - return id; - } - - public boolean isError() { - return false; - } - - public boolean isWarning() { - return true; - } - - public String getMessage() { - if (message != null) - return message; - - String msg = errorMessages.get(new Integer(id)); - if (msg == null) - msg = ""; //$NON-NLS-1$ - - if (arg != null) { - msg = MessageFormat.format(msg, new Object[] { new String(arg) }); - } - - IASTFileLocation f = getFileLocation(); - String file = null; - int line = 0; - if( f == null ) - { - file = ""; //$NON-NLS-1$ - } else { - file = f.getFileName(); - line = f.getStartingLineNumber(); - } - Object[] args = new Object[] { msg, file, new Integer(line) }; - message = ParserMessages.getFormattedString(PROBLEM_PATTERN, args); - return message; - } - - public boolean checkCategory(int bitmask) { - return ((id & bitmask) != 0); - } - - public String getArguments() { - return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ - } - - - protected static final Map errorMessages; - static { - errorMessages = new HashMap(); - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ - errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_WARNING), ParserMessages - .getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_DEFN), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_UNBALANCE_CONDITION), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ - errorMessages - .put( - new Integer( - IASTProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_MACRO_USAGE_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_CIRCULAR_INCLUSION), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_DIRECTIVE), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_MACRO_PASTING_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ - errorMessages - .put( - new Integer( - IASTProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.PREPROCESSOR_INVALID_VA_ARGS), - ParserMessages - .getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_INVALID_ESCAPECHAR), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_UNBOUNDED_STRING), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_FLOATING_POINT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_HEX_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_OCTAL_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_DECIMAL_FORMAT), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_DIVIDE_BY_ZERO), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_MISSING_R_PAREN), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_ILLEGAL_IDENTIFIER), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_UNEXPECTED_EOF), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ - errorMessages - .put( - new Integer(IASTProblem.SCANNER_BAD_CHARACTER), - ParserMessages - .getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ - errorMessages.put(new Integer(IASTProblem.SYNTAX_ERROR), ParserMessages - .getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ - } - - protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$ -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index cd1ad383dc8..379a6e6e0ed 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -769,7 +769,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { return -1; } - public String toString() { + @Override + public String toString() { StringBuffer buffer = new StringBuffer("Scanner @ file:"); //$NON-NLS-1$ buffer.append(fCurrentContext.toString()); buffer.append(" line: "); //$NON-NLS-1$ @@ -1030,7 +1031,15 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } } else { - handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, headerName, poundOffset, condEndOffset); + final int len = headerName.length+2; + StringBuilder name= new StringBuilder(len); + name.append(userInclude ? '"' : '<'); + name.append(headerName); + name.append(userInclude ? '"' : '>'); + + final char[] nameChars= new char[len]; + name.getChars(0, len, nameChars, 0); + handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, nameChars, poundOffset, condEndOffset); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java index 13049444d49..3a240b850f0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java @@ -64,6 +64,11 @@ public interface ILocationResolver { */ IASTProblem[] getScannerProblems(); + /** + * @see IASTTranslationUnit#getPreprocessorProblemsCount() + */ + int getScannerProblemsCount(); + /** * Returns the comments encountered. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java index 9defd56ff9c..50f0be27aab 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree; import org.eclipse.cdt.core.parser.util.CharArrayUtils; +import org.eclipse.cdt.internal.core.dom.parser.ASTProblem; /** * Converts the offsets relative to various contexts to the global sequence number. Also creates and stores @@ -217,7 +218,7 @@ public class LocationMap implements ILocationResolver { public void encounterProblem(int id, char[] arg, int offset, int endOffset) { offset= getSequenceNumberForOffset(offset); endOffset= getSequenceNumberForOffset(endOffset); - ASTProblem problem = new ASTProblem(fTranslationUnit, id, arg, offset, endOffset); + ASTProblem problem = new ASTProblem(fTranslationUnit, IASTTranslationUnit.SCANNER_PROBLEM, id, arg, false, offset, endOffset); fProblems.add(problem); } @@ -545,6 +546,9 @@ public class LocationMap implements ILocationResolver { return fProblems.toArray(new IASTProblem[fProblems.size()]); } + public int getScannerProblemsCount() { + return fProblems.size(); + } public IASTName[] getDeclarations(IMacroBinding binding) { IASTPreprocessorMacroDefinition def = getMacroDefinition(binding); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerStatistics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerStatistics.java index 48e1cc0430e..b96732ad75e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerStatistics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexerStatistics.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,5 +19,7 @@ public class IndexerStatistics { public int fReferenceCount= 0; public int fDeclarationCount= 0; public int fProblemBindingCount= 0; - public int fUnresolvedIncludes= 0; + public int fUnresolvedIncludesCount= 0; + public int fPreprocessorProblemCount= 0; + public int fSyntaxProblemsCount= 0; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java index 715c99c731b..9b66c9ded8e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMWriter.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -27,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; +import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; @@ -68,8 +70,11 @@ abstract public class PDOMWriter { ArrayList fMacros= new ArrayList(); ArrayList fIncludes= new ArrayList(); } + private boolean fShowProblems; + private boolean fShowInclusionProblems; + private boolean fShowScannerProblems; + private boolean fShowSyntaxProblems; protected boolean fShowActivity; - protected boolean fShowProblems; protected final IndexerStatistics fStatistics; protected final IndexerInputAdapter fResolver; @@ -85,6 +90,18 @@ abstract public class PDOMWriter { fShowActivity= val; } + public void setShowInclusionProblems(boolean val) { + fShowInclusionProblems= val; + } + + public void setShowScannerProblems(boolean val) { + fShowScannerProblems= val; + } + + public void setShowSyntaxProblems(boolean val) { + fShowSyntaxProblems= val; + } + public void setShowProblems(boolean val) { fShowProblems= val; } @@ -116,6 +133,11 @@ abstract public class PDOMWriter { public void addSymbols(IASTTranslationUnit ast, IIndexFileLocation[] ifls, IWritableIndex index, int readlockCount, boolean flushIndex, int configHash, ITodoTaskUpdater taskUpdater, IProgressMonitor pm) throws InterruptedException, CoreException { + if (fShowProblems) { + fShowInclusionProblems= true; + fShowScannerProblems= true; + fShowSyntaxProblems= true; + } final Map symbolMap= new HashMap(); for (int i = 0; i < ifls.length; i++) { prepareInMap(symbolMap, ifls[i]); @@ -209,8 +231,12 @@ abstract public class PDOMWriter { final IASTName name = na[0]; try { final IBinding binding = name.resolveBinding(); - if (binding instanceof IProblemBinding) - reportProblem((IProblemBinding) binding); + if (binding instanceof IProblemBinding) { + fStatistics.fProblemBindingCount++; + if (fShowProblems) { + reportProblem((IProblemBinding) binding); + } + } else if (name.isReference()) { if (fSkipReferences == SKIP_TYPE_REFERENCES) { if (isTypeReferenceBinding(binding) && !isRequiredReference(name)) { @@ -249,6 +275,7 @@ abstract public class PDOMWriter { final IIndexFileLocation astIFL = fResolver.resolveASTPath(ast.getFilePath()); // includes + int unresolvedIncludes= 0; IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives(); for (int i= 0; i < includes.length; i++) { final IASTPreprocessorIncludeStatement include = includes[i]; @@ -260,7 +287,7 @@ abstract public class PDOMWriter { } if (include.isActive()) { if (!include.isResolved()) { - reportProblem(include); + unresolvedIncludes++; } else if (updateSource) { // the include was parsed, check if we want to update the included file in the index @@ -271,7 +298,7 @@ abstract public class PDOMWriter { } } } - + // macros IASTPreprocessorMacroDefinition[] macros = ast.getMacroDefinitions(); for (int i2 = 0; i2 < macros.length; ++i2) { @@ -282,9 +309,9 @@ abstract public class PDOMWriter { addToMap(symbolMap, path2, macro); } } - + // names - ast.accept(new IndexerASTVisitor() { + final IndexerASTVisitor visitor = new IndexerASTVisitor() { @Override public void visit(IASTName name, IASTName caller) { if (fSkipReferences == SKIP_ALL_REFERENCES) { @@ -305,7 +332,28 @@ abstract public class PDOMWriter { } } } - }); + }; + ast.accept(visitor); + + fStatistics.fUnresolvedIncludesCount += unresolvedIncludes; + fStatistics.fPreprocessorProblemCount+= ast.getPreprocessorProblemsCount() - unresolvedIncludes; + if (fShowScannerProblems || fShowSyntaxProblems) { + final boolean reportAll= fShowScannerProblems && fShowSyntaxProblems; + IASTProblem[] scannerProblems= ast.getPreprocessorProblems(); + for (IASTProblem problem : scannerProblems) { + if (reportAll || (problem.getID() == IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND) == fShowInclusionProblems) { + reportProblem(problem); + } + } + } + + final List problems= visitor.getProblems(); + fStatistics.fSyntaxProblemsCount+= problems.size(); + if (fShowSyntaxProblems) { + for (IASTProblem problem : problems) { + reportProblem(problem); + } + } } protected final boolean isRequiredReference(IASTName name) { @@ -335,30 +383,6 @@ abstract public class PDOMWriter { return false; } - - private void reportProblem(IASTPreprocessorIncludeStatement problem) { - fStatistics.fUnresolvedIncludes++; - if (fShowProblems) { - String msg= "Indexer: unresolved include"; //$NON-NLS-1$ - IASTFileLocation loc= problem.getFileLocation(); - if (loc != null && loc.getFileName() != null) { - msg += " at " + loc.getFileName() + ": " + loc.getStartingLineNumber(); //$NON-NLS-1$ //$NON-NLS-2$ - } - System.out.println(msg); - } - } - - private void reportProblem(IProblemBinding problem) { - fStatistics.fProblemBindingCount++; - if (fShowProblems) { - String msg= "Indexer: problem at "+ problem.getFileName() + ": " + problem.getLineNumber(); //$NON-NLS-1$//$NON-NLS-2$ - String pmsg= problem.getMessage(); - if (pmsg != null && pmsg.length() > 0) - msg+= "; " + problem.getMessage(); //$NON-NLS-1$ - System.out.println(msg); - } - } - private void addToMap(Map map, IIndexFileLocation location, IASTName[] thing) { Symbols lists= map.get(location); if (lists != null) @@ -444,4 +468,22 @@ abstract public class PDOMWriter { fInfo.fTotalSourcesEstimate+= totalEstimate; } } + + private String getLocationInfo(String filename, int lineNumber) { + return " at " + filename + "(" + lineNumber + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + private void reportProblem(IProblemBinding problem) { + String msg= "Indexer: unresolved name" + getLocationInfo(problem.getFileName(), problem.getLineNumber()); //$NON-NLS-1$ + String pmsg= problem.getMessage(); + if (pmsg != null && pmsg.length() > 0) + msg+= "; " + problem.getMessage(); //$NON-NLS-1$ + System.out.println(msg); + } + + private void reportProblem(IASTProblem problem) { + String msg= "Indexer: " + problem.getMessage(); //$NON-NLS-1$ + System.out.println(msg); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerASTVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerASTVisitor.java index e0204bd5016..8bd7a24730e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerASTVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/IndexerASTVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.pdom.indexer; import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; @@ -22,25 +23,42 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.c.ICASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; abstract public class IndexerASTVisitor extends ASTVisitor { + private static class Definition { + Definition(IASTName name, IASTNode node) { + fName= name; + fNode= node; + } + IASTName fName; + IASTNode fNode; + } + private IASTName fDefinitionName; private IASTNode fDefinitionNode; - private ArrayList fStack= new ArrayList(); + private ArrayList fStack= new ArrayList(); + private ArrayList fProblems= new ArrayList(); public IndexerASTVisitor() { shouldVisitNames= true; shouldVisitDeclarations= true; shouldVisitInitializers= true; shouldVisitDeclSpecifiers= true; + shouldVisitProblems= true; + } + + public List getProblems() { + return fProblems; } abstract public void visit(IASTName name, IASTName definitionName); + @Override final public int visit(IASTName name) { if (!(name instanceof ICPPASTQualifiedName)) { if (name != fDefinitionName) { @@ -52,7 +70,7 @@ abstract public class IndexerASTVisitor extends ASTVisitor { private void push(IASTName name, IASTNode node) { if (fDefinitionName != null) { - fStack.add(new Object[] {fDefinitionName, fDefinitionNode}); + fStack.add(new Definition(fDefinitionName, fDefinitionNode)); } name = getLastInQualified(name); fDefinitionName= name; @@ -73,14 +91,15 @@ abstract public class IndexerASTVisitor extends ASTVisitor { fDefinitionNode= null; } else { - Object[] old= (Object[]) fStack.remove(fStack.size()-1); - fDefinitionName= (IASTName) old[0]; - fDefinitionNode= (IASTNode) old[1]; + Definition old= fStack.remove(fStack.size()-1); + fDefinitionName= old.fName; + fDefinitionNode= old.fNode; } } } // functions and methods + @Override public int visit(IASTDeclaration decl) { if (decl instanceof IASTFunctionDefinition) { IASTFunctionDefinition fdef= (IASTFunctionDefinition) decl; @@ -111,12 +130,14 @@ abstract public class IndexerASTVisitor extends ASTVisitor { return PROCESS_CONTINUE; } + @Override public int leave(IASTDeclaration decl) { pop(decl); return PROCESS_CONTINUE; } // class definitions, typedefs + @Override public int visit(IASTDeclSpecifier declspec) { if (declspec instanceof ICPPASTCompositeTypeSpecifier) { ICPPASTCompositeTypeSpecifier cts= (ICPPASTCompositeTypeSpecifier) declspec; @@ -133,12 +154,20 @@ abstract public class IndexerASTVisitor extends ASTVisitor { return PROCESS_CONTINUE; } + @Override public int leave(IASTDeclSpecifier declspec) { pop(declspec); return PROCESS_CONTINUE; } + + @Override + public int visit(IASTProblem problem) { + fProblems.add(problem); + return PROCESS_SKIP; + } // variable and field initializers + @Override public int visit(IASTInitializer initializer) { if (!(fDefinitionNode instanceof IASTFunctionDefinition)) { IASTNode cand= initializer.getParent(); @@ -149,6 +178,7 @@ abstract public class IndexerASTVisitor extends ASTVisitor { return PROCESS_CONTINUE; } + @Override public int leave(IASTInitializer initializer) { pop(initializer); return PROCESS_CONTINUE; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java index 4657737690d..ad7a4c439ad 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMIndexerTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,6 +32,7 @@ import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask; import org.eclipse.cdt.internal.core.pdom.ITodoTaskUpdater; import org.eclipse.cdt.internal.core.pdom.IndexerProgress; import org.eclipse.cdt.internal.core.pdom.db.ChunkCache; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -52,6 +53,9 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD super(concat(addFiles, updateFiles), removeFiles, new ProjectIndexerInputAdapter(indexer.getProject()), isFastIndexer); fIndexer= indexer; setShowActivity(checkDebugOption(TRACE_ACTIVITY, TRUE)); + setShowInclusionProblems(checkDebugOption(TRACE_INCLUSION_PROBLEMS, TRUE)); + setShowScannerProblems(checkDebugOption(TRACE_SCANNER_PROBLEMS, TRUE)); + setShowSyntaxProblems(checkDebugOption(TRACE_SYNTAX_PROBLEMS, TRUE)); setShowProblems(checkDebugOption(TRACE_PROBLEMS, TRUE)); if (checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES)) { setSkipReferences(SKIP_ALL_REFERENCES); @@ -145,7 +149,9 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD IScannerInfoProvider provider= CCorePlugin.getDefault().getScannerInfoProvider(project); IScannerInfo scanInfo; if (provider != null) { - scanInfo= provider.getScannerInformation(project); + String filename= linkageID == ILinkage.C_LINKAGE_ID ? "__cdt__.c" : "__cdt__.cpp"; //$NON-NLS-1$//$NON-NLS-2$ + IFile file= project.getFile(filename); + scanInfo= provider.getScannerInformation(file); } else { scanInfo= new ScannerInfo(); @@ -175,18 +181,20 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD protected void traceEnd(long start, IWritableIndex index) { if (checkDebugOption(IPDOMIndexerTask.TRACE_STATISTICS, TRUE)) { IndexerProgress info= getProgressInformation(); - String name= getClass().getName(); - name= name.substring(name.lastIndexOf('.')+1); - - System.out.println(name + " " + getProject().getElementName() //$NON-NLS-1$ - + " (" + info.fCompletedSources + " sources, " //$NON-NLS-1$ //$NON-NLS-2$ + String kind= getIndexer().getClass().getName(); + kind= kind.substring(kind.lastIndexOf('.')+1); + String name= " "; //$NON-NLS-1$ + + System.out.println("C/C++ Indexer: Project '" + getProject().getElementName() //$NON-NLS-1$ + + "' (" + info.fCompletedSources + " sources, " //$NON-NLS-1$ //$NON-NLS-2$ + info.fCompletedHeaders + " headers)"); //$NON-NLS-1$ boolean allFiles= getIndexAllFiles(); boolean skipRefs= checkProperty(IndexerPreferences.KEY_SKIP_ALL_REFERENCES); boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES); System.out.println(name + " Options: " //$NON-NLS-1$ - + "parseAllFiles=" + allFiles //$NON-NLS-1$ - + ",skipReferences=" + skipRefs //$NON-NLS-1$ + + "indexer='" + kind //$NON-NLS-1$ + + "', parseAllFiles=" + allFiles //$NON-NLS-1$ + + ", skipReferences=" + skipRefs //$NON-NLS-1$ + ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$ + "."); //$NON-NLS-1$ System.out.println(name + " Timings: " //$NON-NLS-1$ @@ -195,18 +203,20 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD + fStatistics.fResolutionTime + " resolution, " //$NON-NLS-1$ + fStatistics.fAddToIndexTime + " index update."); //$NON-NLS-1$ System.out.println(name + " Errors: " //$NON-NLS-1$ - + fStatistics.fUnresolvedIncludes + " unresolved includes, " //$NON-NLS-1$ - + fStatistics.fErrorCount + " unexpected errors."); //$NON-NLS-1$ + + fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$ + + fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$ + + fStatistics.fSyntaxProblemsCount + " syntax, " //$NON-NLS-1$ + + fStatistics.fErrorCount + " internal errors."); //$NON-NLS-1$ int sum= fStatistics.fDeclarationCount+fStatistics.fReferenceCount+fStatistics.fProblemBindingCount; double problemPct= sum==0 ? 0.0 : (double) fStatistics.fProblemBindingCount / (double) sum; NumberFormat nf= NumberFormat.getPercentInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); - System.out.println(name + " Result: " //$NON-NLS-1$ + System.out.println(name + " Names: " //$NON-NLS-1$ + fStatistics.fDeclarationCount + " declarations, " //$NON-NLS-1$ + fStatistics.fReferenceCount + " references, " //$NON-NLS-1$ - + fStatistics.fProblemBindingCount + "(" + nf.format(problemPct) + ") problems."); //$NON-NLS-1$ //$NON-NLS-2$ + + fStatistics.fProblemBindingCount + "(" + nf.format(problemPct) + ") unresolved."); //$NON-NLS-1$ //$NON-NLS-2$ if (index != null) { long misses= index.getCacheMisses(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index 90204d8d058..17fafc8eb50 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -314,8 +314,13 @@ public class BaseUITestCase extends BaseTestCase { if (text.length() > 0 && !text.equals("...")) { item= root.getItem(i1); assertNotNull("Unexpected tree node " + item.getText(), label); - assertEquals(label, item.getText()); - return item; + if (label.equals(item.getText())) { + return item; + } + if (i > 100) { + assertEquals(label, item.getText()); + return item; + } } } catch (IllegalArgumentException e) { @@ -330,6 +335,7 @@ public class BaseUITestCase extends BaseTestCase { } runEventQueue(10); } + runEventQueue(30000); fail("Timeout expired waiting for tree node " + label + "{" + i0 + "," + i1 + "}"); return null; }