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 new file mode 100644 index 00000000000..b9b1a5c6926 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTProblem.java @@ -0,0 +1,463 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.core.dom.ast; + +import org.eclipse.cdt.internal.core.parser.ParserMessages; + +/** + * @author jcamelon + * + * Description of a C/C++ parse/compilation problem, as detected by the parser or some of the underlying + * clients of the parser. + * + * A problem provides access to: + * + */ +public interface IASTProblem extends IASTNode { + /** + * Returns the problem id + * + * @return the problem id + */ + int getID(); + + /** + * Answer a localized, human-readable message string which describes the problem. + * + * @return a localized, human-readable message string which describes the problem + */ + String getMessage(); + + /** + * Return to the client a map between parameter names and values. + * + * The keys and values are all Strings. + * + * + * @return a map between parameter names and values. + */ + String getArguments(); + + /** + * Checks the severity to see if the Error bit is set. + * + * @return true if the Error bit is set for the severity, false otherwise + */ + boolean isError(); + + /** + * Checks the severity to see if the Warning bit is not set. + * + * @return true if the Warning bit is not set for the severity, false otherwise + */ + boolean isWarning(); + + /** + * Unknown Numeric Value for line numbers and offsets; use this constant + */ + public final static int INT_VALUE_NOT_PROVIDED = -1; + + /** + * Unknown filename sentinel value + */ + public final static String FILENAME_NOT_PROVIDED = ParserMessages.getString("IProblem.unknownFileName"); //$NON-NLS-1$ + + /** + * Problem Categories + * The high bits of a problem ID contains information about the category of a problem. + * For example, (problemID & TypeRelated) != 0, indicates that this problem is type related. + * + * A problem category can help to implement custom problem filters. Indeed, when numerous problems + * are listed, focusing on import related problems first might be relevant. + * + * When a problem is tagged as Internal, it means that no change other than a local source code change + * can fix the corresponding problem. + */ + + /** + * IProblem relates to a valid error on the Scanner + */ + public final static int SCANNER_RELATED = 0x01000000; + + /** + * IProblem relates to a valid error on the preprocessor + */ + public final static int PREPROCESSOR_RELATED = 0x02000000; + + /** + * IProblem relates to a valid syntax error in the parser + */ + public final static int SYNTAX_RELATED = 0x04000000; + + /** + * IProblem relates to a valid semantical error in the parser + */ + public final static int SEMANTICS_RELATED = 0x08000000; + + /** + * IProblem relates to an implementation of design limitation + */ + public final static int INTERNAL_RELATED = 0x10000000; + + + /** + * Check the parameter bitmask against an IProblem's ID to broadly segregate the + * types of problems. + * + * @param bitmask + * @return true if ( (id & bitmask ) != 0 ) + */ + public boolean checkCategory(int bitmask); + + /** + * Mask to use in order to filter out the category portion of the problem ID. + */ + public final static int IGNORE_CATEGORIES_MASK = 0xFFFFFF; + + /** + * Below are listed all available problem attributes. The JavaDoc for each problem ID indicates + * when they should be contributed to creating a problem of that type. + */ + + // Preprocessor IProblem attributes + /** + * The text that follows a #error preprocessor directive + */ + public final static String A_PREPROC_POUND_ERROR = ParserMessages.getString("IProblem.preproc.poundError"); //$NON-NLS-1$ + + /** + * The filename that failed somehow in an preprocessor include directive + */ + public final static String A_PREPROC_INCLUDE_FILENAME = ParserMessages.getString("IProblem.preproc.include"); //$NON-NLS-1$ + + /** + * A preprocessor macro name + */ + public final static String A_PREPROC_MACRO_NAME = ParserMessages.getString("IProblem.preproc.macro"); //$NON-NLS-1$ + + /** + * A preprocessor conditional that could not be evaluated + * + * #if X + Y == Z <== that one, if X, Y or Z are not defined + * #endif + */ + public final static String A_PREPROC_CONDITION = ParserMessages.getString("IProblem.preproc.condition"); //$NON-NLS-1$ + + /** + * A preprocessor directive that could not be interpretted + * + * e.g. #blah + */ + public final static String A_PREPROC_UNKNOWN_DIRECTIVE = ParserMessages.getString("IProblem.preproc.unknownDirective"); //$NON-NLS-1$ + + /** + * The preprocessor conditional statement that caused an unbalanced mismatch. + * + * #if X + * #else + * #else <=== that one + * #endif + */ + public final static String A_PREPROC_CONDITIONAL_MISMATCH = ParserMessages.getString("IProblem.preproc.conditionalMismatch"); //$NON-NLS-1$ + + /** + * The Bad character encountered in scanner + */ + public static final String A_SCANNER_BADCHAR = null; + + /** + * A_SYMBOL_NAME - symbol name + */ + public static final String A_SYMBOL_NAME = ParserMessages.getString("IProblem.symbolName"); //$NON-NLS-1$ + + /** + * A_NAMESPACE_NAME = namespace name + */ + public static final String A_NAMESPACE_NAME = ParserMessages.getString("IProblem.namespaceName"); //$NON-NLS-1$ + + /** + * A_TYPE_NAME - type name + */ + public static final String A_TYPE_NAME = ParserMessages.getString("IProblem.typeName"); //$NON-NLS-1$ + + /** + * Below are listed all available problem IDs. Note that this list could be augmented in the future, + * as new features are added to the C/C++ core implementation. + */ + + /* + * Scanner Problems + */ + + /** + * Bad character encountered by Scanner. + * Required attributes: A_SCANNER_BADCHAR + * @see #A_SCANNER_BADCHAR + */ + public final static int SCANNER_BAD_CHARACTER = SCANNER_RELATED | 0x001; + + /** + * Unbounded literal string encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_UNBOUNDED_STRING = SCANNER_RELATED | 0x002; + + /** + * Invalid escape sequence encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_INVALID_ESCAPECHAR = SCANNER_RELATED | 0x003; + + /** + * Bad floating point encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_BAD_FLOATING_POINT = SCANNER_RELATED | 0x004; + + /** + * Bad hexidecimal encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_BAD_HEX_FORMAT = SCANNER_RELATED | 0x005; + + /** + * Unexpected EOF encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_UNEXPECTED_EOF = SCANNER_RELATED | 0x006; + + /** + * Bad octal encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_BAD_OCTAL_FORMAT = SCANNER_RELATED | 0x007; + + /** + * Bad decimal encountered by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_BAD_DECIMAL_FORMAT = SCANNER_RELATED | 0x008; + + /** + * Assignment '=' encountered in macro by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_ASSIGNMENT_NOT_ALLOWED = SCANNER_RELATED | 0x009; + + /** + * Division by 0 encountered in macro by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_DIVIDE_BY_ZERO = SCANNER_RELATED | 0x00A; + + /** + * Missing ')' encountered in macro by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_MISSING_R_PAREN = SCANNER_RELATED | 0x00B; + + /** + * Expression syntax error encountered in macro by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_EXPRESSION_SYNTAX_ERROR = SCANNER_RELATED | 0x00C; + + /** + * Expression syntax error encountered in macro by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_ILLEGAL_IDENTIFIER = SCANNER_RELATED | 0x00D; + + /** + * Division by 0 encountered in macro by Scanner. + * Required attributes: none. + */ + public final static int SCANNER_BAD_CONDITIONAL_EXPRESSION = SCANNER_RELATED | 0x00E; + + + /* + * Preprocessor Problems + */ + + /** + * #error encountered by Preprocessor. + * Required attributes: A_PREPROC_POUND_ERROR + * @see #A_PREPROC_POUND_ERROR + */ + public final static int PREPROCESSOR_POUND_ERROR = PREPROCESSOR_RELATED | 0x001; + + /** + * Inclusion not found by Preprocessor. + * Required attributes: A_PREPROC_INCLUDE_FILENAME + * @see #A_PREPROC_INCLUDE_FILENAME + */ + public final static int PREPROCESSOR_INCLUSION_NOT_FOUND = PREPROCESSOR_RELATED | 0x002; + + /** + * Macro definition not found by Preprocessor. + * Required attributes: A_PREPROC_MACRO_NAME + * @see #A_PREPROC_MACRO_NAME + */ + public final static int PREPROCESSOR_DEFINITION_NOT_FOUND = PREPROCESSOR_RELATED | 0x003; + + /** + * Preprocessor conditionals seem unbalanced. + * Required attributes: A_PREPROC_CONDITIONAL_MISMATCH + * @see #A_PREPROC_CONDITIONAL_MISMATCH + */ + + public final static int PREPROCESSOR_UNBALANCE_CONDITION = PREPROCESSOR_RELATED | 0x004; + + /** + * Invalid format to Macro definition. + * Required attributes: A_PREPROC_MACRO_NAME + * @see #A_PREPROC_MACRO_NAME + */ + public final static int PREPROCESSOR_INVALID_MACRO_DEFN = PREPROCESSOR_RELATED | 0x005; + + /** + * Invalid or unknown preprocessor directive encountered by Preprocessor. + * Required attributes: A_PREPROC_UNKNOWN_DIRECTIVE + * @see #A_PREPROC_UNKNOWN_DIRECTIVE + */ + public final static int PREPROCESSOR_INVALID_DIRECTIVE = PREPROCESSOR_RELATED | 0x006; + + /** + * Invalid macro redefinition encountered by Preprocessor. + * Required attributes: A_PREPROC_MACRO_NAME + * @see #A_PREPROC_MACRO_NAME + */ + public final static int PREPROCESSOR_INVALID_MACRO_REDEFN = PREPROCESSOR_RELATED | 0x007; + + /** + * Preprocessor Conditional cannot not be evaluated due. + * Required attributes: A_PREPROC_CONDITION + * @see #A_PREPROC_CONDITION + */ + public final static int PREPROCESSOR_CONDITIONAL_EVAL_ERROR = PREPROCESSOR_RELATED | 0x008; + + /** + * Invalid macro usage encountered by Preprocessor. + * Required attributes: A_PREPROC_MACRO_NAME + * @see #A_PREPROC_MACRO_NAME + */ + public final static int PREPROCESSOR_MACRO_USAGE_ERROR = PREPROCESSOR_RELATED | 0x009; + + /** + * Invalid Macro Pasting encountered by Preprocessor. + * Required attributes: A_PREPROC_MACRO_NAME + * @see #A_PREPROC_MACRO_NAME + */ + public final static int PREPROCESSOR_MACRO_PASTING_ERROR = PREPROCESSOR_RELATED | 0x00A; + + /** + * Circular inclusion encountered by Preprocessor. + * Required attributes: A_PREPROC_INCLUDE_FILENAME + * @see #A_PREPROC_INCLUDE_FILENAME + */ + public final static int PREPROCESSOR_CIRCULAR_INCLUSION = PREPROCESSOR_RELATED | 0x00B; + + /** + * macro argument "..." encountered without the required ')' i.e. must be last argument if used + * Required attributes: none + */ + public final static int PREPROCESSOR_MISSING_RPAREN_PARMLIST = PREPROCESSOR_RELATED | 0x00C; + + /** + * __VA_ARGS__ encountered in macro definition without the required '...' parameter + * Required attributes: none + */ + public final static int PREPROCESSOR_INVALID_VA_ARGS = PREPROCESSOR_RELATED | 0x00D; + + /* + * Parser Syntactic Problems + */ + public final static int SYNTAX_ERROR = SYNTAX_RELATED | 0x001; + + /* + * Parser Semantic Problems + */ + + /** + * Attempt to add a unique symbol, yet the value was already defined. + * Require attributes: A_SYMBOL_NAME + * @see #A_SYMBOL_NAME + */ + public final static int SEMANTIC_UNIQUE_NAME_PREDEFINED = SEMANTICS_RELATED | 0x001; + + /** + * Attempt to use a symbol that was not found. + * Require attributes: A_SYMBOL_NAME + * @see #A_SYMBOL_NAME + */ + public final static int SEMANTIC_NAME_NOT_FOUND = SEMANTICS_RELATED | 0x002; + + /** + * Name not provided in context that it was required. + * Require attributes: none + */ + public final static int SEMANTIC_NAME_NOT_PROVIDED = SEMANTICS_RELATED | 0x003; + + /** + * Invalid overload of a particular name. + * Required attributes: A_SYMBOL_NAME + * @see #A_SYMBOL_NAME + */ + public static final int SEMANTIC_INVALID_OVERLOAD = SEMANTICS_RELATED | 0x004; + + /** + * Invalid using directive. + * Required attributes: A_NAMESPACE_NAME + * @see #A_NAMESPACE_NAME + */ + public static final int SEMANTIC_INVALID_USING = SEMANTICS_RELATED | 0x005; + + /** + * Ambiguous lookup for given name. + * Required attributes: A_SYMBOL_NAME + * @see #A_SYMBOL_NAME + */ + public static final int SEMANTIC_AMBIGUOUS_LOOKUP = SEMANTICS_RELATED | 0x006; + + /** + * Invalid type provided + * Required attribugtes: A_TYPE_NAME + * @see #A_TYPE_NAME + */ + public static final int SEMANTIC_INVALID_TYPE = SEMANTICS_RELATED | 0x007; + + public static final int SEMANTIC_CIRCULAR_INHERITANCE = SEMANTICS_RELATED | 0x008; + + public static final int SEMANTIC_INVALID_TEMPLATE = SEMANTICS_RELATED | 0x009; + + public static final int SEMANTIC_BAD_VISIBILITY = SEMANTICS_RELATED | 0x00A; + + public static final int SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION = SEMANTICS_RELATED | 0x00B; + + public static final int SEMANTIC_INVALID_TEMPLATE_ARGUMENT = SEMANTICS_RELATED | 0x00C; + + public static final int SEMANTIC_INVALID_TEMPLATE_PARAMETER = SEMANTICS_RELATED | 0x00D; + + public static final int SEMANTIC_REDECLARED_TEMPLATE_PARAMETER = SEMANTICS_RELATED | 0x00E; + + public static final int SEMANTIC_INVALID_CONVERSION_TYPE = SEMANTICS_RELATED | 0x00F; + + public static final int SEMANTIC_MALFORMED_EXPRESSION = SEMANTICS_RELATED | 0x010; + + public static final int SEMANTIC_ILLFORMED_FRIEND = SEMANTICS_RELATED | 0x011; + + public static final int SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION = SEMANTICS_RELATED | 0x012; +} 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 03c2818643d..18e2c5fdda3 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 @@ -18,7 +18,8 @@ package org.eclipse.cdt.core.dom.ast; */ public interface IASTTranslationUnit extends IASTNode { - ASTNodeProperty OWNED_DECLARATION = new ASTNodeProperty( "OWNED" ); //$NON-NLS-1$ + public static final ASTNodeProperty OWNED_DECLARATION = new ASTNodeProperty( "Owned" ); //$NON-NLS-1$ + public static final ASTNodeProperty SCANNER_PROBLEM = new ASTNodeProperty( "Scanner Problem"); //$NON-NLS-1$ /** * A translation unit contains an ordered sequence of declarations. @@ -64,5 +65,6 @@ public interface IASTTranslationUnit extends IASTNode { public IASTMacroDefinition [] getMacroDefinitions(); public IASTPreprocessorIncludeStatement [] getIncludeDirectives(); public IASTPreprocessorStatement [] getAllPreprocessorStatements(); + public IASTProblem [] getPreprocesorProblems(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java index 8d78ade2af5..20fe7cc3524 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IProblem.java @@ -28,9 +28,6 @@ import org.eclipse.cdt.internal.core.parser.ParserMessages; */ public interface IProblem { - - - /** * Returns the problem id * 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..5ff9e40d942 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTProblem.java @@ -0,0 +1,280 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +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.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.internal.core.parser.ParserMessages; + +/** + * @author jcamelon + */ +public class ASTProblem extends ASTNode implements IASTProblem { + + private IASTNode parent; + private ASTNodeProperty property; + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getParent() + */ + public IASTNode getParent() { + return parent; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode) + */ + public void setParent(IASTNode node) { + this.parent = node; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent() + */ + public ASTNodeProperty getPropertyInParent() { + return property; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.ASTNodeProperty) + */ + public void setPropertyInParent(ASTNodeProperty property) { + this.property = property; + } + + private final char[] arg; + private final int id; + + private final boolean isError; + private final boolean isWarning; + + private String message = null; + + public ASTProblem( int id, char[] arg, boolean warn, boolean error ) + { + this.id = id; + this.arg = arg; + this.isWarning = warn; + this.isError = error; + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IProblem#getID() + */ + public int getID() { + return id; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IProblem#isError() + */ + public boolean isError() { + return isError; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IProblem#isWarning() + */ + public boolean isWarning() { + return isWarning; + } + + protected static final Map errorMessages; + static { + errorMessages = new HashMap(); + errorMessages.put( + new Integer( IProblem.SEMANTIC_UNIQUE_NAME_PREDEFINED), + ParserMessages.getString("ASTProblemFactory.error.semantic.uniqueNamePredefined")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_NAME_NOT_FOUND), + ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotFound")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_NAME_NOT_PROVIDED), + ParserMessages.getString("ASTProblemFactory.error.semantic.nameNotProvided")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_CONVERSION_TYPE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.invalidConversionType")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_MALFORMED_EXPRESSION ), + ParserMessages.getString("ASTProblemFactory.error.semantic.malformedExpression")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_AMBIGUOUS_LOOKUP ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.ambiguousLookup")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TYPE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidType")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_CIRCULAR_INHERITANCE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.circularInheritance")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_OVERLOAD ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidOverload")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TEMPLATE ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplate")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_USING ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidUsing")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_BAD_VISIBILITY ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.badVisibility")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_UNABLE_TO_RESOLVE_FUNCTION ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.unableToResolveFunction")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TEMPLATE_ARGUMENT ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplateArgument")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_INVALID_TEMPLATE_PARAMETER ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.invalidTemplateParameter")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_REDECLARED_TEMPLATE_PARAMETER ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.redeclaredTemplateParameter")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SEMANTIC_RECURSIVE_TEMPLATE_INSTANTIATION ), + ParserMessages.getString("ASTProblemFactory.error.semantic.pst.recursiveTemplateInstantiation")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_POUND_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_DEFINITION_NOT_FOUND), + ParserMessages.getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_MACRO_REDEFN), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_UNBALANCE_CONDITION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_CIRCULAR_INCLUSION), + ParserMessages.getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_DIRECTIVE), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST), + ParserMessages.getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.PREPROCESSOR_INVALID_VA_ARGS), + ParserMessages.getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_INVALID_ESCAPECHAR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_UNBOUNDED_STRING), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_FLOATING_POINT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_HEX_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_OCTAL_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_DECIMAL_FORMAT), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED), + ParserMessages.getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_DIVIDE_BY_ZERO), + ParserMessages.getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_MISSING_R_PAREN), + ParserMessages.getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR), + ParserMessages.getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_ILLEGAL_IDENTIFIER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_UNEXPECTED_EOF), + ParserMessages.getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$ + errorMessages.put( + new Integer(IProblem.SCANNER_BAD_CHARACTER), + ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ + errorMessages.put( + new Integer( IProblem.SYNTAX_ERROR ), + ParserMessages.getString( "ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$ + } + protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$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) } ); + } + + Object [] args = new Object[] { msg, new String( "" ), new Integer( 0 ) }; //$NON-NLS-1$ + message = ParserMessages.getFormattedString( PROBLEM_PATTERN, args ); + return message; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IProblem#checkCategory(int) + */ + public boolean checkCategory(int bitmask) { + return ((id & bitmask) != 0 ); + } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.parser.IProblem#getArguments() + */ + public String getArguments() { + return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit() + */ + public IASTTranslationUnit getTranslationUnit() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 2d31f1513f3..0b228be4dcf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -49,7 +49,6 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IParserLogService; @@ -59,6 +58,7 @@ import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.OffsetLimitReachedException; import org.eclipse.cdt.core.parser.ParseError; import org.eclipse.cdt.core.parser.ParserMode; +import org.eclipse.cdt.internal.core.parser.BacktrackException; import org.eclipse.cdt.internal.core.parser.ParserProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java index 2528fce58df..421904c1198 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTNode.java @@ -55,7 +55,7 @@ public class CASTNode extends ASTNode implements IASTNode { public IASTTranslationUnit getTranslationUnit() { if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this; IASTNode node = getParent(); - while( ! (node instanceof IASTTranslationUnit )) + while( ! (node instanceof IASTTranslationUnit ) && node != null ) { node = node.getParent(); } 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 2f587eaddf1..c5bb9304581 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 @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; +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.IScope; @@ -40,6 +41,7 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0]; private static final IASTMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTMacroDefinition[0]; private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; + private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0]; public void addDeclaration( IASTDeclaration d ) { @@ -187,4 +189,20 @@ public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit if( resolver != null ) resolver.cleanup(); super.finalize(); } + + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems() + */ + public IASTProblem[] getPreprocesorProblems() { + if( resolver == null ) return EMPTY_PROBLEM_ARRAY; + IASTProblem [] result = resolver.getScannerProblems(); + for( int i = 0; i < result.length; ++i ) + { + IASTProblem p = result[i]; + p.setParent( this ); + p.setPropertyInParent( IASTTranslationUnit.SCANNER_PROBLEM ); + } + return result; + } } 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 8f569811754..b7fbdee2808 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 @@ -80,7 +80,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.c.ICASTTypedefNameSpecifier; import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IParserLogService; @@ -91,6 +90,7 @@ import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.IProblemRequestor; +import org.eclipse.cdt.internal.core.parser.BacktrackException; /** * @author jcamelon 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 12d678af4cc..794b4e32e01 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 @@ -10,7 +10,6 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.dom.parser.cpp; - import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -18,6 +17,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; +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.IScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit; @@ -31,36 +32,52 @@ import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; */ public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslationUnit, IRequiresLocationInformation { - private IASTDeclaration [] decls = null; + private IASTDeclaration[] decls = null; + private ICPPNamespace binding = null; + private ICPPScope scope = null; + private static final int DEFAULT_CHILDREN_LIST_SIZE = 8; + private int currentIndex = 0; + private ILocationResolver resolver; - - public void addDeclaration( IASTDeclaration d ) - { - if( decls == null ) - { - decls = new IASTDeclaration[ DEFAULT_CHILDREN_LIST_SIZE ]; + + private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0]; + + private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0]; + + private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0]; + + private static final IASTMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTMacroDefinition[0]; + + private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0]; + + private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0]; + + public void addDeclaration(IASTDeclaration d) { + if (decls == null) { + decls = new IASTDeclaration[DEFAULT_CHILDREN_LIST_SIZE]; currentIndex = 0; } - if( decls.length == currentIndex ) - { - IASTDeclaration [] old = decls; - decls = new IASTDeclaration[ old.length * 2 ]; - for( int i = 0; i < old.length; ++i ) + if (decls.length == currentIndex) { + IASTDeclaration[] old = decls; + decls = new IASTDeclaration[old.length * 2]; + for (int i = 0; i < old.length; ++i) decls[i] = old[i]; } - decls[ currentIndex++ ] = d; + decls[currentIndex++] = d; } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations() */ public IASTDeclaration[] getDeclarations() { - if( decls == null ) return IASTDeclaration.EMPTY_DECLARATION_ARRAY; + if (decls == null) + return IASTDeclaration.EMPTY_DECLARATION_ARRAY; removeNullDeclarations(); return decls; } @@ -69,115 +86,164 @@ public class CPPASTTranslationUnit extends CPPASTNode implements * @param decls2 */ private void removeNullDeclarations() { - int nullCount = 0; - for( int i = 0; i < decls.length; ++i ) - if( decls[i] == null ) + int nullCount = 0; + for (int i = 0; i < decls.length; ++i) + if (decls[i] == null) ++nullCount; - if( nullCount == 0 ) return; - IASTDeclaration [] old = decls; + if (nullCount == 0) + return; + IASTDeclaration[] old = decls; int newSize = old.length - nullCount; - decls = new IASTDeclaration[ newSize ]; - for( int i = 0; i < newSize; ++i ) + decls = new IASTDeclaration[newSize]; + for (int i = 0; i < newSize; ++i) decls[i] = old[i]; currentIndex = newSize; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getScope() */ public IScope getScope() { - if( scope == null ) - scope = new CPPNamespaceScope( this ); + if (scope == null) + scope = new CPPNamespaceScope(this); return scope; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) - */ - public IASTDeclaration[] getDeclarations(IBinding b) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) - */ - public IASTName[] getReferences(IBinding b) { - // TODO Auto-generated method stub - return null; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getDeclarations(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public IASTDeclaration[] getDeclarations(IBinding b) { + // TODO Auto-generated method stub + return null; + } - /* (non-Javadoc) + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getReferences(org.eclipse.cdt.core.dom.ast.IBinding) + */ + public IASTName[] getReferences(IBinding b) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int) */ public IASTNodeLocation getLocationInfo(int offset) { + if (resolver == null) + return null; return resolver.getLocation(offset); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, int) + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getLocationInfo(int, + * int) */ public IASTNodeLocation[] getLocationInfo(int offset, int length) { - return resolver.getLocations(offset,length); + if (resolver == null) + return EMPTY_PREPROCESSOR_LOCATION_ARRAY; + return resolver.getLocations(offset, length); } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation) */ public IASTNode[] selectNodesForLocation(String path, int offset, int length) { return null; } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getMacroDefinitions() */ public IASTMacroDefinition[] getMacroDefinitions() { + if (resolver == null) + return EMPTY_PREPROCESSOR_MACRODEF_ARRAY; return resolver.getMacroDefinitions(this); } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getIncludeDirectives() */ public IASTPreprocessorIncludeStatement[] getIncludeDirectives() { + if (resolver == null) + return EMPTY_PREPROCESSOR_INCLUSION_ARRAY; return resolver.getIncludeDirectives(this); } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getAllPreprocessorStatements() */ public IASTPreprocessorStatement[] getAllPreprocessorStatements() { + if (resolver == null) + return EMPTY_PREPROCESSOR_STATEMENT_ARRAY; return resolver.getAllPreprocessorStatements(this); } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser2.IRequiresLocationInformation#setLocationResolver(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver) */ public void setLocationResolver(ILocationResolver resolver) { this.resolver = resolver; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#selectNodesForLocation(int, int) + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#selectNodesForLocation(int, + * int) */ public IASTNode[] selectNodesForLocation(int offset, int length) { - return selectNodesForLocation( resolver.getTranslationUnitPath(), offset, length ); //$NON-NLS-1$ + if (resolver == null) + return EMPTY_NODE_ARRAY; + return selectNodesForLocation(resolver.getTranslationUnitPath(), + offset, length); //$NON-NLS-1$ } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit#resolveBinding() + */ + public IBinding resolveBinding() { + if (binding == null) + binding = new CPPNamespace(this); + return binding; + } - /* (non-Javadoc) - * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit#resolveBinding() - */ - public IBinding resolveBinding() { - if( binding == null ) - binding = new CPPNamespace( this ); - return binding; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getPreprocesorProblems() + */ + public IASTProblem[] getPreprocesorProblems() { + if (resolver == null) + return EMPTY_PROBLEM_ARRAY; + IASTProblem[] result = resolver.getScannerProblems(); + for (int i = 0; i < result.length; ++i) { + IASTProblem p = result[i]; + p.setParent(this); + p.setPropertyInParent(IASTTranslationUnit.SCANNER_PROBLEM); + } + return result; + } } 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 599c4a80a2a..e6a15b00ed7 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 @@ -115,7 +115,6 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IGCCToken; import org.eclipse.cdt.core.parser.IParserLogService; @@ -129,6 +128,7 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser; import org.eclipse.cdt.internal.core.dom.parser.IProblemRequestor; +import org.eclipse.cdt.internal.core.parser.BacktrackException; import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy; import org.eclipse.cdt.internal.core.parser.TemplateParameterManager; import org.eclipse.cdt.internal.core.parser.token.TokenFactory; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/BacktrackException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java similarity index 95% rename from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/BacktrackException.java rename to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java index 132babe53eb..187c12631fa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/BacktrackException.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/BacktrackException.java @@ -8,7 +8,9 @@ * Contributors: * IBM Rational Software - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.core.parser; +package org.eclipse.cdt.internal.core.parser; + +import org.eclipse.cdt.core.parser.IProblem; /** * @author jcamelon diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java index 5947a1ce55d..f18900347aa 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/DeclarationWrapper.java @@ -16,7 +16,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.ITokenDuple; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java index 471633ec9cc..cdb0fdf9cdd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/GCCParserExtension.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.internal.core.parser; import java.util.Hashtable; import java.util.Map; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.Enum; import org.eclipse.cdt.core.parser.IGCCToken; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java index fa32c674b1f..0e64a6ae1db 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserData.java @@ -8,7 +8,6 @@ * Contributors: * IBM Rational Software - Initial API and implementation */ package org.eclipse.cdt.internal.core.parser; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParserLogService; import org.eclipse.cdt.core.parser.IToken; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index 96851a17a5a..c64a1937f33 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.EndOfFileException; import org.eclipse.cdt.core.parser.IParser; import org.eclipse.cdt.core.parser.IParserLogService; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java index 00e8ac1c0ce..a22bd07b04a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/gcc/GCCASTCompleteExtension.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.GCCKeywords; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ITokenDuple; @@ -36,6 +35,7 @@ import org.eclipse.cdt.core.parser.ast.IASTTypeId; import org.eclipse.cdt.core.parser.ast.IASTExpression.IASTNewExpressionDescriptor; import org.eclipse.cdt.core.parser.ast.IASTExpression.Kind; import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; +import org.eclipse.cdt.internal.core.parser.BacktrackException; import org.eclipse.cdt.internal.core.parser.DeclarationWrapper; import org.eclipse.cdt.internal.core.parser.Declarator; import org.eclipse.cdt.internal.core.parser.ast.GCCASTExtension; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java index fa3045cb780..1304aa476c4 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java @@ -2111,21 +2111,11 @@ abstract class BaseScanner implements IScanner { return newToken(tokenType, image ); } - protected static final ScannerProblemFactory spf = new ScannerProblemFactory(); + /** * @param scanner_bad_character */ - protected void handleProblem(int id, int startOffset, char [] arg ) { - if( parserMode == ParserMode.COMPLETION_PARSE ) return; - IProblem p = spf.createProblem( id, startOffset, bufferPos[bufferStackPos], getLineNumber( bufferPos[bufferStackPos] ), getCurrentFilename(), arg != null ? arg : EMPTY_CHAR_ARRAY, false, true ); - pushProblem(p); - } - - - /** - * @param p - */ - protected abstract void pushProblem(IProblem p); + protected abstract void handleProblem(int id, int startOffset, char [] arg ); /** * @param i diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java index c3c2e37cd71..87f8b433285 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java @@ -12,15 +12,16 @@ package org.eclipse.cdt.internal.core.parser.scanner2; import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IMacro; import org.eclipse.cdt.core.parser.IParserLogService; -import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserMode; import org.eclipse.cdt.core.parser.ast.IASTFactory; +import org.eclipse.cdt.internal.core.dom.parser.ASTProblem; import org.eclipse.cdt.internal.core.parser.token.ImagedExpansionToken; import org.eclipse.cdt.internal.core.parser.token.ImagedToken; import org.eclipse.cdt.internal.core.parser.token.SimpleExpansionToken; @@ -59,7 +60,7 @@ public class DOMScanner extends BaseScanner { */ public DOMScanner(CodeReader reader, IScannerInfo info, ParserMode parserMode, ParserLanguage language, IParserLogService log, IScannerConfiguration configuration, ICodeReaderFactory readerFactory) { super(reader, info, parserMode, language, log, configuration); - this.expressionEvaluator = new ExpressionEvaluator(null, spf); + this.expressionEvaluator = new ExpressionEvaluator(null, null); this.codeReaderFactory = readerFactory; postConstructorSetup(reader, info); } @@ -144,13 +145,6 @@ public class DOMScanner extends BaseScanner { return i; } - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushProblem(org.eclipse.cdt.core.parser.IProblem) - */ - protected void pushProblem(IProblem p) { - locationMap.encounterProblem(p); - } - /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object) */ @@ -182,4 +176,12 @@ public class DOMScanner extends BaseScanner { } } + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[]) + */ + protected void handleProblem(int id, int startOffset, char[] arg) { + IASTProblem problem = new ASTProblem(id, arg, true, false ); + locationMap.encounterProblem(problem); + } + } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java index 3c538cafa16..55a90d83853 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java @@ -15,7 +15,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; -import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblem; /** * @author jcamelon @@ -28,7 +28,7 @@ public interface ILocationResolver { public IASTNodeLocation [] getLocations( int offset, int length ); public IASTNodeLocation getLocation( int offset ); - public IProblem [] getScannerProblems(); + public IASTProblem[] getScannerProblems(); public String getTranslationUnitPath(); public String [] getInclusionsPaths(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java index 4d37e71fd79..917b86b0810 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java @@ -10,7 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner2; -import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblem; /** * @author jcamelon @@ -57,5 +57,5 @@ public interface IScannerPreprocessorLog { public void encounterPoundEndIf(int startOffset, int endOffset); - public void encounterProblem( IProblem problem ); + public void encounterProblem( IASTProblem problem ); } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index cd9d0f8d956..7176fbb42ff 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; -import org.eclipse.cdt.core.parser.IProblem; +import org.eclipse.cdt.core.dom.ast.IASTProblem; /** * @author jcamelon @@ -242,14 +242,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems() */ - public IProblem[] getScannerProblems() { - return (IProblem[]) problems.toArray( new IProblem[ problems.size() ]); + public IASTProblem[] getScannerProblems() { + return (IASTProblem[]) problems.toArray( new IASTProblem[ problems.size() ]); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterIProblem(org.eclipse.cdt.core.parser.IProblem) */ - public void encounterProblem(IProblem problem) { + public void encounterProblem(IASTProblem problem) { if( problems == Collections.EMPTY_LIST ) problems = new ArrayList( 4 ); problems.add(problem); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java index 2c0b5dbdee6..bee50cbb9c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java @@ -50,7 +50,7 @@ public class Scanner2 extends BaseScanner { IScannerConfiguration configuration) { super(reader, info, parserMode, language, log, configuration); this.requestor = requestor; - this.callbackManager = new ScannerCallbackManager( requestor ); + this.callbackManager = new ScannerCallbackManager(requestor); this.expressionEvaluator = new ExpressionEvaluator(callbackManager, spf); this.workingCopies = workingCopies; postConstructorSetup(reader, info); @@ -68,11 +68,14 @@ public class Scanner2 extends BaseScanner { } protected IASTFactory astFactory; - //callbacks - protected ScannerCallbackManager callbackManager; - protected ISourceElementRequestor requestor; - protected List workingCopies; - + + // callbacks + protected ScannerCallbackManager callbackManager; + + protected ISourceElementRequestor requestor; + + protected List workingCopies; + public final void setASTFactory(IASTFactory f) { astFactory = f; } @@ -100,106 +103,153 @@ public class Scanner2 extends BaseScanner { */ protected void processMacro(char[] name, int startingOffset, int startingLineNumber, int idstart, int idend, int nameLine, - int textEnd, int endingLine, org.eclipse.cdt.core.parser.IMacro macro) { + int textEnd, int endingLine, + org.eclipse.cdt.core.parser.IMacro macro) { callbackManager.pushCallback(getASTFactory().createMacro(name, startingOffset, startingLineNumber, idstart, idend, nameLine, textEnd, endingLine, getCurrentFilename(), !isInitialized)); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushInclusion(java.lang.Object) */ protected void pushInclusion(Object data) { - callbackManager.pushCallback( data ); + callbackManager.pushCallback(data); super.pushInclusion(data); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popInclusion() */ protected void popInclusion(java.lang.Object data) { super.popInclusion(data); - callbackManager.pushCallback( ((InclusionData) bufferData[bufferStackPos]).inclusion ); + callbackManager + .pushCallback(((InclusionData) bufferData[bufferStackPos]).inclusion); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#beforeSecondFetchToken() */ protected void beforeSecondFetchToken() { - if( callbackManager.hasCallbacks() ) - callbackManager.popCallbacks(); + if (callbackManager.hasCallbacks()) + callbackManager.popCallbacks(); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushProblem(org.eclipse.cdt.core.parser.IProblem) */ protected void pushProblem(IProblem p) { - callbackManager.pushCallback( p ); + callbackManager.pushCallback(p); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object) */ protected void quickParsePushPopInclusion(Object inclusion) { - callbackManager.pushCallback( new InclusionData( null, inclusion ) ); - callbackManager.pushCallback( inclusion ); + callbackManager.pushCallback(new InclusionData(null, inclusion)); + callbackManager.pushCallback(inclusion); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String) */ protected CodeReader createReaderDuple(String finalPath) { - return ScannerUtility.createReaderDuple( finalPath, requestor, getWorkingCopies() ); + return ScannerUtility.createReaderDuple(finalPath, requestor, + getWorkingCopies()); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.core.parser.IScanner#getLocationResolver() */ public ILocationResolver getLocationResolver() { return null; } - - /* (non-Javadoc) - * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies() - */ - protected Iterator getWorkingCopies() { - if( workingCopies == null ) return EmptyIterator.EMPTY_ITERATOR; - return workingCopies.iterator(); - } - - /** - * @return - */ - protected IToken newToken( int signal ) { - if( bufferData[bufferStackPos] instanceof MacroData ) - { - int mostRelevant; - for( mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant ) - if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader ) - break; - MacroData data = (MacroData)bufferData[mostRelevant + 1]; - return new SimpleExpansionToken( signal, data.startOffset, data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1)); - } - return new SimpleToken(signal, bufferPos[bufferStackPos] + 1 , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1) ); - } - protected IToken newToken( int signal, char [] buffer ) - { - if( bufferData[bufferStackPos] instanceof MacroData ) - { - int mostRelevant; - for( mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant ) - if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader ) - break; - MacroData data = (MacroData)bufferData[mostRelevant + 1]; - return new ImagedExpansionToken( signal, buffer, data.startOffset, data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1)); - } - IToken i = new ImagedToken(signal, buffer, bufferPos[bufferStackPos] + 1 , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1)); - if( buffer != null && buffer.length == 0 && signal != IToken.tSTRING && signal != IToken.tLSTRING ) - bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some point - - return i; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser.scanner.IScannerData#getWorkingCopies() + */ + protected Iterator getWorkingCopies() { + if (workingCopies == null) + return EmptyIterator.EMPTY_ITERATOR; + return workingCopies.iterator(); + } + /** + * @return + */ + protected IToken newToken(int signal) { + if (bufferData[bufferStackPos] instanceof MacroData) { + int mostRelevant; + for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant) + if (bufferData[mostRelevant] instanceof InclusionData + || bufferData[mostRelevant] instanceof CodeReader) + break; + MacroData data = (MacroData) bufferData[mostRelevant + 1]; + return new SimpleExpansionToken(signal, data.startOffset, + data.endOffset - data.startOffset + 1, + getCurrentFilename(), + getLineNumber(bufferPos[mostRelevant] + 1)); + } + return new SimpleToken(signal, bufferPos[bufferStackPos] + 1, + getCurrentFilename(), + getLineNumber(bufferPos[bufferStackPos] + 1)); + } + + protected IToken newToken(int signal, char[] buffer) { + if (bufferData[bufferStackPos] instanceof MacroData) { + int mostRelevant; + for (mostRelevant = bufferStackPos; mostRelevant >= 0; --mostRelevant) + if (bufferData[mostRelevant] instanceof InclusionData + || bufferData[mostRelevant] instanceof CodeReader) + break; + MacroData data = (MacroData) bufferData[mostRelevant + 1]; + return new ImagedExpansionToken(signal, buffer, data.startOffset, + data.endOffset - data.startOffset + 1, + getCurrentFilename(), + getLineNumber(bufferPos[mostRelevant] + 1)); + } + IToken i = new ImagedToken(signal, buffer, + bufferPos[bufferStackPos] + 1, getCurrentFilename(), + getLineNumber(bufferPos[bufferStackPos] + 1)); + if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING + && signal != IToken.tLSTRING) + bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some + // point + + return i; + } + + protected static final ScannerProblemFactory spf = new ScannerProblemFactory(); + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, + * int, char[]) + */ + protected void handleProblem(int id, int startOffset, char[] arg) { + if (parserMode == ParserMode.COMPLETION_PARSE) + return; + IProblem p = spf.createProblem(id, startOffset, + bufferPos[bufferStackPos], + getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(), + arg != null ? arg : EMPTY_CHAR_ARRAY, false, true); + pushProblem(p); + } } \ No newline at end of file