1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Updated Parser.translationUnit() to catch all Throwable rather than Exception

This commit is contained in:
John Camelon 2004-06-03 18:23:56 +00:00
parent a718c3de62
commit c3338eda94
6 changed files with 50 additions and 23 deletions

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.parser; package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.parser.BacktrackException; import org.eclipse.cdt.core.parser.BacktrackException;
@ -210,9 +209,10 @@ public abstract class Parser extends ExpressionParser implements IParser
break; 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(); failParse();
} }
} }
@ -1112,19 +1112,19 @@ public abstract class Parser extends ExpressionParser implements IParser
logException( "simpleDecl", e ); //$NON-NLS-1$ logException( "simpleDecl", e ); //$NON-NLS-1$
throw backtrack; throw backtrack;
} }
Iterator i = l.iterator();
if (hasFunctionBody && l.size() != 1) if (hasFunctionBody && l.size() != 1)
{ {
throw backtrack; //TODO Should be an IProblem 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) if (!hasFunctionBody || fromCatchHandler)
{ {
IASTDeclaration declaration = null; 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( ((IASTOffsetableElement)declaration).setEndingOffsetAndLineNumber(
lastToken.getEndOffset(), lastToken.getLineNumber()); lastToken.getEndOffset(), lastToken.getLineNumber());
declaration.acceptElement( requestor, astFactory.getReferenceManager() ); declaration.acceptElement( requestor, astFactory.getReferenceManager() );
@ -1134,7 +1134,7 @@ public abstract class Parser extends ExpressionParser implements IParser
} }
return declaration; return declaration;
} }
IASTDeclaration declaration = (IASTDeclaration)i.next(); IASTDeclaration declaration = (IASTDeclaration)l.get(0);
endDeclaration( declaration ); endDeclaration( declaration );
declaration.enterScope( requestor, astFactory.getReferenceManager() ); declaration.enterScope( requestor, astFactory.getReferenceManager() );
if( sdw.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier ) if( sdw.getTypeSpecifier() instanceof IASTSimpleTypeSpecifier )

View file

@ -41,6 +41,8 @@ ScannerProblemFactory.error.scanner.badHexFormat=Invalid hexidecimal format enco
ScannerProblemFactory.error.scanner.unexpectedEOF=Unexpected End Of File encountered ScannerProblemFactory.error.scanner.unexpectedEOF=Unexpected End Of File encountered
ScannerProblemFactory.error.scanner.badCharacter=Bad character sequence encountered : {0} 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.uniqueNamePredefined=Attempt to introduce unique symbol failed : {0}
ASTProblemFactory.error.semantic.nameNotFound=Attempt to use symbol failed : {0} ASTProblemFactory.error.semantic.nameNotFound=Attempt to use symbol failed : {0}
ASTProblemFactory.error.semantic.nameNotProvided=Name not provided. ASTProblemFactory.error.semantic.nameNotProvided=Name not provided.

View file

@ -10,6 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser; 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.BaseProblemFactory;
import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory; import org.eclipse.cdt.internal.core.parser.problem.IProblemFactory;
@ -21,6 +22,37 @@ public class ParserProblemFactory extends BaseProblemFactory
implements implements
IProblemFactory { 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) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int) * @see org.eclipse.cdt.internal.core.parser.problem.IProblemFactory#getRequiredAttributesForId(int)
*/ */

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.parser.ast.complete; package org.eclipse.cdt.internal.core.parser.ast.complete;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; 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) public void addEnumerator(IASTEnumerator enumerator)
{ {
if( enumerators == Collections.EMPTY_LIST )
enumerators = new ArrayList( ENUMERATOR_LIST_SIZE );
enumerators.add(enumerator); enumerators.add(enumerator);
} }

View file

@ -41,19 +41,5 @@ public abstract class BaseProblemFactory {
* @param file * @param file
* @return * @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;
// }
} }

View file

@ -196,6 +196,9 @@ public class Problem implements IProblem {
errorMessages.put( errorMessages.put(
new Integer(IProblem.SCANNER_BAD_CHARACTER), new Integer(IProblem.SCANNER_BAD_CHARACTER),
ParserMessages.getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$ 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$ protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$