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

Added better toString() implementations to Scanner. Added additional logging of unexpected exceptions throughout the Parser.

This commit is contained in:
John Camelon 2004-04-12 15:37:39 +00:00
parent 9e4f258b9a
commit 06cdcc0e39
5 changed files with 129 additions and 46 deletions

View file

@ -127,6 +127,8 @@
2004-03-26 Andrew Niefer
-report references to symbols used in a template-id.
2004-03-25 Andrew Niefer
-modify IASTFactory.createField & .createVariable to take ITokenDuple's for the name
-modify ITokenDuple to support manipulating TokenDuples that have template arguments in them

View file

@ -214,6 +214,7 @@ public class ExpressionParser implements IExpressionParser {
failed = true;
break;
}catch( Exception e ){
logException( "templateArgumentList::createExpression()", e ); //$NON-NLS-1$
failed = true;
break;
}
@ -464,6 +465,7 @@ public class ExpressionParser implements IExpressionParser {
}
catch (Exception e)
{
logException( "consumeArrayModifiers::createArrayModifier()", e ); //$NON-NLS-1$
throw backtrack;
}
d.addArrayModifier(arrayMod);
@ -618,6 +620,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "expression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -730,6 +733,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "throwExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -763,6 +767,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "conditionalExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -798,6 +803,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "logicalOrExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -831,6 +837,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "logicalAndExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -865,6 +872,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "inclusiveOrExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -900,6 +908,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "exclusiveORExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -934,12 +943,32 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException("andExpression::createExpression()", e); //$NON-NLS-1$
throw backtrack;
}
}
return firstExpression;
}
/**
* @param methodName
* @param e
*/
protected void logException(String methodName, Exception e) {
if( !(e instanceof EndOfFileException ))
{
StringBuffer buffer = new StringBuffer();
buffer.append( "Parser: Unexpected exception in "); //$NON-NLS-1$
buffer.append( methodName );
buffer.append( ":"); //$NON-NLS-1$
buffer.append( e.getMessage() );
buffer.append( ". w/"); //$NON-NLS-1$
buffer.append( scanner.toString() );
log.traceLog( buffer.toString() );
log.errorLog( buffer.toString() );
}
}
/**
* @param expression
* @throws BacktrackException
@ -975,6 +1004,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "equalityExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -1055,6 +1085,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "relationalExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1099,6 +1130,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "shiftExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -1142,6 +1174,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "additiveExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -1196,6 +1229,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "multiplicativeExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -1239,6 +1273,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "pmExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -1285,6 +1320,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "castExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1491,6 +1527,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "typeId::createTypeId()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1535,6 +1572,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "deleteExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1678,6 +1716,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "newExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1739,6 +1778,7 @@ public class ExpressionParser implements IExpressionParser {
return null;
} catch (Exception e)
{
logException( "newExpression_2::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
@ -1829,6 +1869,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
else if (unaryExpression != null && d == null)
@ -1848,6 +1889,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "unaryExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
else
@ -1926,6 +1968,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2038,6 +2081,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_2::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2074,6 +2118,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_3::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2117,6 +2162,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_4::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2140,6 +2186,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_5::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2163,6 +2210,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_6::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2204,6 +2252,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_7::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2244,6 +2293,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "postfixExpression_8::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2303,6 +2353,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "simpleTypeConstructorExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -2334,6 +2385,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_1::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
case IToken.tFLOATINGPT :
@ -2354,6 +2406,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_2::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
case IToken.tSTRING :
@ -2368,6 +2421,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_3::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
@ -2390,6 +2444,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_4::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
@ -2413,6 +2468,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_5::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
@ -2434,6 +2490,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_6::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
case IToken.tLPAREN :
@ -2458,6 +2515,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_7::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
case IToken.tIDENTIFIER :
@ -2517,6 +2575,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "primaryExpression_8::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
default :
@ -2534,6 +2593,10 @@ public class ExpressionParser implements IExpressionParser {
// TODO Auto-generated catch block
e9.printStackTrace();
} catch( Exception e )
{
logException( "primaryExpression_9::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
return empty;
}
@ -2698,6 +2761,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "assignmentOperatorExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -2733,6 +2797,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "unaryOperatorCastExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -2761,6 +2826,7 @@ public class ExpressionParser implements IExpressionParser {
throw backtrack;
} catch (Exception e)
{
logException( "specialCastExpression::createExpression()", e ); //$NON-NLS-1$
throw backtrack;
}
}

View file

@ -131,6 +131,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e2)
{
logException( "translationUnit::createCompilationUnit()", e2 ); //$NON-NLS-1$
return;
}
@ -261,6 +262,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "usingClause:createUsingDirective", e1 ); //$NON-NLS-1$
throw backtrack;
}
astUD.acceptElement(requestor);
@ -310,6 +312,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "usingClause:createUsingDeclaration", e1 ); //$NON-NLS-1$
throw backtrack;
}
declaration.acceptElement( requestor );
@ -353,6 +356,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "linkageSpecification_1:createLinkageSpecification", e ); //$NON-NLS-1$
throw backtrack;
}
@ -398,6 +402,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "linkageSpecification_2:createLinkageSpecification", e ); //$NON-NLS-1$
throw backtrack;
}
linkage.enterScope( requestor );
@ -443,6 +448,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "templateDeclaration:createTemplateInstantiation", e ); //$NON-NLS-1$
throw backtrack;
}
templateInstantiation.enterScope( requestor );
@ -470,6 +476,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "templateDeclaration:createTemplateSpecialization", e ); //$NON-NLS-1$
throw backtrack;
}
templateSpecialization.enterScope(requestor);
@ -497,6 +504,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "templateDeclaration:createTemplateDeclaration", e ); //$NON-NLS-1$
throw backtrack;
}
templateDecl.enterScope( requestor );
@ -595,6 +603,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "templateParameterList_1:createTemplateParameter", e ); //$NON-NLS-1$
throw backtrack;
}
@ -634,6 +643,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "templateParameterList_2:createTemplateParameter", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -671,6 +681,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "templateParameterList:createParameterDeclaration", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -730,6 +741,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "declaration:createASMDefinition", e ); //$NON-NLS-1$
throw backtrack;
}
// if we made it this far, then we have all we need
@ -855,6 +867,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "namespaceDefinition:createNamespaceDefinition", e1 ); //$NON-NLS-1$
throw backtrack;
}
namespaceDefinition.enterScope( requestor );
@ -910,6 +923,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "namespaceDefinition:createNamespaceAlias", e1 ); //$NON-NLS-1$
throw backtrack;
}
}
@ -969,6 +983,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "simpleDeclaration:createSimpleTypeSpecifier", e1 ); //$NON-NLS-1$
throw backtrack;
}
@ -1089,6 +1104,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "simpleDeclaration:createTypeSpecDeclaration", e1 ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1157,6 +1173,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "ctorInitializer:addConstructorMemberInitializer", e1 ); //$NON-NLS-1$
throw backtrack;
}
if (LT(1) == IToken.tLBRACE)
@ -1211,6 +1228,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "parameterDeclaration:createSimpleTypeSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
@ -1702,6 +1720,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "elaboratedTypeSpecifier:createElaboratedTypeSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
sdw.setTypeSpecifier(elaboratedTypeSpec);
@ -1869,6 +1888,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "cInitializerClause:createInitializerClause", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1899,6 +1919,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "initializerClause_1:createInitializerClause", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1923,6 +1944,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "initializerClause_2:createInitializerClause", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -1944,6 +1966,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "initializerClause_3:createInitializerClause", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -2061,6 +2084,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "declarator:queryIsTypeName", e ); //$NON-NLS-1$
throw backtrack;
}
} catch( BacktrackException b )
@ -2174,6 +2198,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "declarator:createExceptionSpecification", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -2332,6 +2357,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "enumSpecifier:createEnumerationSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
consume(IToken.tLBRACE);
@ -2371,6 +2397,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "enumSpecifier:addEnumerator", e ); //$NON-NLS-1$
throw backtrack;
}
break;
@ -2394,6 +2421,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "enumSpecifier:addEnumerator", e ); //$NON-NLS-1$
throw backtrack;
}
consume(IToken.tCOMMA);
@ -2486,6 +2514,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "classSpecifier:createClassSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
sdw.setTypeSpecifier(astClassSpecifier);
@ -2548,6 +2577,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e1)
{
logException( "classSpecifier:signalEndOfClassSpecifier", e1 ); //$NON-NLS-1$
throw backtrack;
}
@ -2618,6 +2648,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "baseSpecifier_1::addBaseSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
isVirtual = false;
@ -2644,6 +2675,7 @@ public abstract class Parser extends ExpressionParser implements IParser
throw backtrack;
} catch (Exception e)
{
logException( "baseSpecifier_2::addBaseSpecifier", e ); //$NON-NLS-1$
throw backtrack;
}
}
@ -2842,6 +2874,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "singleStatementScope:createNewCodeBlock", e ); //$NON-NLS-1$
throw backtrack;
}
newScope.enterScope( requestor );
@ -2909,6 +2942,7 @@ public abstract class Parser extends ExpressionParser implements IParser
}
catch (Exception e)
{
logException( "compoundStatement:createNewCodeBlock", e ); //$NON-NLS-1$
throw backtrack;
}
newScope.enterScope( requestor );
@ -2942,52 +2976,6 @@ public abstract class Parser extends ExpressionParser implements IParser
newScope.exitScope( requestor );
}
/**
* @throws Exception
*/
protected void varName() throws Exception
{
if (LT(1) == IToken.tCOLONCOLON)
consume();
for (;;)
{
switch (LT(1))
{
case IToken.tIDENTIFIER :
consume();
//if (isTemplateArgs()) {
// rTemplateArgs();
//}
if (LT(1) == IToken.tCOLONCOLON)
{
switch (LT(2))
{
case IToken.tIDENTIFIER :
case IToken.tCOMPL :
case IToken.t_operator :
consume();
break;
default :
return;
}
}
else
return;
break;
case IToken.tCOMPL :
consume();
consume(IToken.tIDENTIFIER);
return;
case IToken.t_operator :
consume();
//rOperatorName();
return;
default :
throw backtrack;
}
}
}
protected IASTCompilationUnit compilationUnit;
/* (non-Javadoc)

View file

@ -3200,4 +3200,18 @@ public class Scanner implements IScanner {
return getCurrentFile().toCharArray();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append( "Scanner @"); //$NON-NLS-1$
if( scannerData.getContextStack().getCurrentContext() != null )
buffer.append( scannerData.getContextStack().getCurrentContext().toString());
else
buffer.append( "EOF"); //$NON-NLS-1$
return buffer.toString();
}
}

View file

@ -178,4 +178,17 @@ public class ScannerContext implements IScannerContext
private IASTInclusion inc = null;
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append( "file "); //$NON-NLS-1$
buffer.append( getFilename() );
buffer.append( ":"); //$NON-NLS-1$
buffer.append( getLine() );
return buffer.toString();
}
}