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 a0ed5f8f097..5d5f21f7af0 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 @@ -11,7 +11,6 @@ package org.eclipse.cdt.internal.core.parser; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.eclipse.cdt.core.parser.BacktrackException; @@ -210,9 +209,10 @@ public abstract class Parser extends ExpressionParser implements IParser break; } } - catch (Exception e) + catch (Throwable e) { - logException( "translationUnit", e ); //$NON-NLS-1$ + if( e instanceof Exception ) + logException( "translationUnit", (Exception) e ); //$NON-NLS-1$ failParse(); } } @@ -1112,19 +1112,19 @@ public abstract class Parser extends ExpressionParser implements IParser logException( "simpleDecl", e ); //$NON-NLS-1$ throw backtrack; } - Iterator i = l.iterator(); + if (hasFunctionBody && l.size() != 1) { throw backtrack; //TODO Should be an IProblem } - if (i.hasNext()) // no need to do this unless we have a declarator + if (!l.isEmpty()) // no need to do this unless we have a declarator { if (!hasFunctionBody || fromCatchHandler) { IASTDeclaration declaration = null; - while (i.hasNext()) + for( int i = 0; i < l.size(); ++i ) { - declaration = (IASTDeclaration)i.next(); + declaration = (IASTDeclaration)l.get(i); ((IASTOffsetableElement)declaration).setEndingOffsetAndLineNumber( lastToken.getEndOffset(), lastToken.getLineNumber()); declaration.acceptElement( requestor, astFactory.getReferenceManager() ); @@ -1134,7 +1134,7 @@ public abstract class Parser extends ExpressionParser implements IParser } return declaration; } - IASTDeclaration declaration = (IASTDeclaration)i.next(); + IASTDeclaration declaration = (IASTDeclaration)l.get(0); endDeclaration( declaration ); declaration.enterScope( requestor, astFactory.getReferenceManager() ); if( sdw.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) 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 8b01389108e..86881b870c4 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 @@ -41,6 +41,8 @@ ScannerProblemFactory.error.scanner.badHexFormat=Invalid hexidecimal format enco 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 + ASTProblemFactory.error.semantic.uniqueNamePredefined=Attempt to introduce unique symbol failed : {0} ASTProblemFactory.error.semantic.nameNotFound=Attempt to use symbol failed : {0} ASTProblemFactory.error.semantic.nameNotProvided=Name not provided. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java index 59107c7de2a..6c76ef79c39 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserProblemFactory.java @@ -10,6 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.internal.core.parser; +import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; @@ -21,6 +22,37 @@ public class ParserProblemFactory extends BaseProblemFactory implements IProblemFactory { + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.parser.IProblemFactory#createProblem(int, int, int, int, char[], java.lang.String, boolean, boolean) + */ + public IProblem createProblem( + int id, + int start, + int end, + int line, + char[] file, + String arg, + boolean warn, + boolean error) + { + if( checkBitmask( id, IProblem.INTERNAL_RELATED ) ) + return createInternalProblem( id, start, end, line, file, arg, warn, error ); + + if ( checkBitmask( id, IProblem.SYNTAX_RELATED ) ) + return super.createProblem( + id, + start, + end, + line, + file, + arg, + warn, + error); + + return null; + } + /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int) */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java index 429a12562a7..50e018b7ed6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/complete/ASTEnumerationSpecifier.java @@ -11,6 +11,7 @@ package org.eclipse.cdt.internal.core.parser.ast.complete; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -45,9 +46,12 @@ public class ASTEnumerationSpecifier } - private List enumerators = new ArrayList(); + private List enumerators = Collections.EMPTY_LIST; + private static final int ENUMERATOR_LIST_SIZE = 4; public void addEnumerator(IASTEnumerator enumerator) { + if( enumerators == Collections.EMPTY_LIST ) + enumerators = new ArrayList( ENUMERATOR_LIST_SIZE ); enumerators.add(enumerator); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java index 3b12c1e8a6f..1f42de6ee02 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/BaseProblemFactory.java @@ -41,19 +41,5 @@ public abstract class BaseProblemFactory { * @param file * @return */ -// private String createInternalMessage(int id, String arg, int line, char[] file) -// { -// if( checkBitmask( id, IProblem.INTERNAL_RELATED )) -// { -// StringBuffer buffer = new StringBuffer(); -// -// switch( id ) -// { -// } -// -// return buffer.toString(); -// } -// return null; -// } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java index f7986df3384..559e5006aa6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/problem/Problem.java @@ -196,6 +196,9 @@ public class Problem implements IProblem { 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$