mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
CORE
Fixed Bug 39530 - More problems with initializers. Fixed Bug 37424 - Crash when opening big files Refactored pointerOperators & cvQualifiers to not throw backtracks in optional case. Added tracing support to cdt.core plugin via .options file. TESTS Added QuickParseASTTests::testBug39530().
This commit is contained in:
parent
94b8758d5c
commit
2f398f309b
10 changed files with 143 additions and 81 deletions
|
@ -1,3 +1,6 @@
|
|||
2003-08-25 John Camelon
|
||||
Added QuickParseASTTests::testBug39530().
|
||||
|
||||
2003-08-21 Hoda Amer
|
||||
Enabled some tests in the IStructureTests, namely:
|
||||
testGetFields(), testGetField(), testGetMethods(), testGetMethod(),
|
||||
|
|
|
@ -1763,4 +1763,10 @@ public class QuickParseASTTests extends BaseASTTest
|
|||
parse("class {} const null;");
|
||||
assertTrue( quickParseCallback.getCompilationUnit().getDeclarations().hasNext() );
|
||||
}
|
||||
|
||||
public void testBug39530() throws Exception
|
||||
{
|
||||
parse( "X sPassed(-1)");
|
||||
}
|
||||
|
||||
}
|
1
core/org.eclipse.cdt.core/.options
Normal file
1
core/org.eclipse.cdt.core/.options
Normal file
|
@ -0,0 +1 @@
|
|||
org.eclipse.cdt.core/debug=true
|
|
@ -174,7 +174,8 @@ public class Util {
|
|||
}
|
||||
|
||||
public static void debugLog(String message) {
|
||||
if (CCorePlugin.getDefault() != null && CCorePlugin.getDefault().isDebugging()) {
|
||||
if( CCorePlugin.getDefault() == null ) return;
|
||||
if ( CCorePlugin.getDefault().isDebugging()) {
|
||||
// Time stamp
|
||||
message = MessageFormat.format( "[{0}] {1}", new Object[] { new Long( System.currentTimeMillis() ), message } );
|
||||
while (message.length() > 100) {
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2003-08-25 John Camelon
|
||||
Fixed Bug 39530 - More problems with initializers.
|
||||
Fixed Bug 37424 - Crash when opening big files
|
||||
Refactored pointerOperators & cvQualifiers to not throw backtracks in optional case.
|
||||
Added tracing support to cdt.core plugin via .options file.
|
||||
|
||||
2003-08-14 John Camelon
|
||||
Removed warnings from SymbolTable & QuickParseCallback (removing implicit accessor generation).
|
||||
Made IASTElaboratedTypeSpecifier derive from IASTOffsetableNamedElement (as it should).
|
||||
|
|
|
@ -32,4 +32,9 @@ public interface IScanner {
|
|||
public void setTokenizingMacroReplacementList(boolean b);
|
||||
|
||||
public void onParseEnd();
|
||||
/**
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int getLineNumberForOffset(int i);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Stack;
|
|||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -85,7 +86,7 @@ public class ContextStack {
|
|||
try {
|
||||
currentContext.getReader().close();
|
||||
} catch (IOException ie) {
|
||||
System.out.println("Error closing reader");
|
||||
Util.debugLog("ContextStack : Error closing reader ");
|
||||
}
|
||||
|
||||
if( currentContext.getKind() == IScannerContext.INCLUSION )
|
||||
|
|
|
@ -793,7 +793,7 @@ public class Parser implements IParser
|
|||
DeclarationWrapper sdw =
|
||||
new DeclarationWrapper(scope, LA(1).getOffset(), ownerTemplate);
|
||||
|
||||
declSpecifierSeq(false, tryConstructor, sdw);
|
||||
declSpecifierSeq(false, tryConstructor, sdw, forKR );
|
||||
try
|
||||
{
|
||||
if (sdw.getTypeSpecifier() == null && sdw.getSimpleType() != IASTSimpleTypeSpecifier.Type.UNSPECIFIED )
|
||||
|
@ -816,14 +816,14 @@ public class Parser implements IParser
|
|||
if (LT(1) != IToken.tSEMI)
|
||||
try
|
||||
{
|
||||
declarator = initDeclarator(sdw);
|
||||
declarator = initDeclarator(sdw, forKR);
|
||||
|
||||
while (LT(1) == IToken.tCOMMA)
|
||||
{
|
||||
consume();
|
||||
try
|
||||
{
|
||||
initDeclarator(sdw);
|
||||
initDeclarator(sdw, forKR);
|
||||
}
|
||||
catch (Backtrack b)
|
||||
{
|
||||
|
@ -1010,7 +1010,7 @@ public class Parser implements IParser
|
|||
|
||||
DeclarationWrapper sdw =
|
||||
new DeclarationWrapper(scope, current.getOffset(), null);
|
||||
declSpecifierSeq(true, false, sdw);
|
||||
declSpecifierSeq(true, false, sdw, false);
|
||||
try
|
||||
{
|
||||
if (sdw.getTypeSpecifier() == null
|
||||
|
@ -1034,7 +1034,7 @@ public class Parser implements IParser
|
|||
if (LT(1) != IToken.tSEMI)
|
||||
try
|
||||
{
|
||||
initDeclarator(sdw);
|
||||
initDeclarator(sdw, false);
|
||||
}
|
||||
catch (Backtrack b)
|
||||
{
|
||||
|
@ -1219,7 +1219,8 @@ public class Parser implements IParser
|
|||
protected void declSpecifierSeq(
|
||||
boolean parm,
|
||||
boolean tryConstructor,
|
||||
DeclarationWrapper sdw)
|
||||
DeclarationWrapper sdw,
|
||||
boolean forKR )
|
||||
throws Backtrack
|
||||
{
|
||||
Flags flags = new Flags(parm, tryConstructor);
|
||||
|
@ -1418,7 +1419,7 @@ public class Parser implements IParser
|
|||
case IToken.t_class :
|
||||
case IToken.t_struct :
|
||||
case IToken.t_union :
|
||||
if (!parm)
|
||||
if (!parm && !forKR )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1440,7 +1441,7 @@ public class Parser implements IParser
|
|||
break;
|
||||
}
|
||||
case IToken.t_enum :
|
||||
if (!parm)
|
||||
if (!parm || !forKR )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1684,7 +1685,7 @@ public class Parser implements IParser
|
|||
* @return Returns the same object sent in.
|
||||
* @throws Backtrack
|
||||
*/
|
||||
protected void cvQualifier(
|
||||
protected boolean cvQualifier(
|
||||
Declarator declarator)
|
||||
throws Backtrack
|
||||
{
|
||||
|
@ -1693,13 +1694,13 @@ public class Parser implements IParser
|
|||
case IToken.t_const :
|
||||
consume( IToken.t_const );
|
||||
declarator.addPtrOp(ASTPointerOperator.CONST_POINTER);
|
||||
return;
|
||||
return true;
|
||||
case IToken.t_volatile :
|
||||
consume( IToken.t_volatile );
|
||||
declarator.addPtrOp(ASTPointerOperator.VOLATILE_POINTER);
|
||||
return;
|
||||
return true;
|
||||
default :
|
||||
throw backtrack;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -1712,10 +1713,10 @@ public class Parser implements IParser
|
|||
* @throws Backtrack request a backtrack
|
||||
*/
|
||||
protected Declarator initDeclarator(
|
||||
DeclarationWrapper sdw)
|
||||
DeclarationWrapper sdw, boolean forKR )
|
||||
throws Backtrack
|
||||
{
|
||||
Declarator d = declarator(sdw, sdw.getScope());
|
||||
Declarator d = declarator(sdw, sdw.getScope(), forKR );
|
||||
// handle = initializerClause
|
||||
if (LT(1) == IToken.tASSIGN)
|
||||
{
|
||||
|
@ -1810,7 +1811,7 @@ public class Parser implements IParser
|
|||
* @throws Backtrack request a backtrack
|
||||
*/
|
||||
protected Declarator declarator(
|
||||
IDeclaratorOwner owner, IASTScope scope)
|
||||
IDeclaratorOwner owner, IASTScope scope, boolean forKR )
|
||||
throws Backtrack
|
||||
{
|
||||
Declarator d = null;
|
||||
|
@ -1819,21 +1820,12 @@ public class Parser implements IParser
|
|||
{
|
||||
d = new Declarator(owner);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
try
|
||||
{
|
||||
ptrOperator(d);
|
||||
}
|
||||
catch (Backtrack b)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
consumePointerOperators(d, false);
|
||||
|
||||
if (LT(1) == IToken.tLPAREN)
|
||||
{
|
||||
consume();
|
||||
declarator(d, scope);
|
||||
declarator(d, scope, forKR);
|
||||
consume(IToken.tRPAREN);
|
||||
}
|
||||
else if (LT(1) == IToken.t_operator)
|
||||
|
@ -1879,6 +1871,9 @@ public class Parser implements IParser
|
|||
switch (LT(1))
|
||||
{
|
||||
case IToken.tLPAREN :
|
||||
if( forKR )
|
||||
throw backtrack;
|
||||
|
||||
// temporary fix for initializer/function declaration ambiguity
|
||||
if (!LA(2).looksLikeExpression() )
|
||||
{
|
||||
|
@ -2030,7 +2025,7 @@ public class Parser implements IParser
|
|||
}
|
||||
while (LT(1) != IToken.tLBRACE);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Backtrack bt)
|
||||
{
|
||||
// Something is wrong,
|
||||
// this is not a proper K&R declaration clause
|
||||
|
@ -2122,7 +2117,8 @@ public class Parser implements IParser
|
|||
{
|
||||
// this ptrOp doesn't belong to the declarator,
|
||||
// it's just a part of the name
|
||||
ptrOperator(d);
|
||||
consumePointerOperators(d, true);
|
||||
if( lastToken != null )
|
||||
toSend = lastToken;
|
||||
}
|
||||
catch (Backtrack b)
|
||||
|
@ -2149,21 +2145,32 @@ public class Parser implements IParser
|
|||
* @param owner Declarator that this pointer operator corresponds to.
|
||||
* @throws Backtrack request a backtrack
|
||||
*/
|
||||
protected void ptrOperator(Declarator d) throws Backtrack
|
||||
protected void consumePointerOperators(Declarator d, boolean consumeOnlyOne) throws Backtrack
|
||||
{
|
||||
for( ; ; )
|
||||
{
|
||||
int t = LT(1);
|
||||
if (t == IToken.tAMPER)
|
||||
{
|
||||
consume( IToken.tAMPER );
|
||||
d.addPtrOp(ASTPointerOperator.REFERENCE);
|
||||
return;
|
||||
if( consumeOnlyOne ) return;
|
||||
continue;
|
||||
}
|
||||
IToken mark = mark();
|
||||
IToken tokenType = LA(1);
|
||||
ITokenDuple nameDuple = null;
|
||||
if (t == IToken.tIDENTIFIER || t == IToken.tCOLONCOLON)
|
||||
{
|
||||
try
|
||||
{
|
||||
nameDuple = name();
|
||||
}
|
||||
catch( Backtrack bt )
|
||||
{
|
||||
backup( mark );
|
||||
return;
|
||||
}
|
||||
t = LT(1);
|
||||
}
|
||||
if (t == IToken.tSTAR)
|
||||
|
@ -2175,24 +2182,22 @@ public class Parser implements IParser
|
|||
boolean successful = false;
|
||||
for (;;)
|
||||
{
|
||||
try
|
||||
{
|
||||
cvQualifier(d);
|
||||
successful = true;
|
||||
}
|
||||
catch (Backtrack b)
|
||||
{
|
||||
// expected at some point
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !successful )
|
||||
d.addPtrOp( ASTPointerOperator.POINTER );
|
||||
boolean newSuccess = cvQualifier(d);
|
||||
if( newSuccess ) successful = true;
|
||||
else break;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( !successful )
|
||||
{
|
||||
d.addPtrOp( ASTPointerOperator.POINTER );
|
||||
}
|
||||
if( consumeOnlyOne ) return;
|
||||
continue;
|
||||
}
|
||||
backup(mark);
|
||||
throw backtrack;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parse an enumeration specifier, as according to the ANSI specs in C & C++.
|
||||
|
@ -4401,6 +4406,9 @@ public class Parser implements IParser
|
|||
private IScanner scanner;
|
||||
private IToken currToken, // current token we plan to consume next
|
||||
lastToken; // last token we consumed
|
||||
|
||||
private int highWaterOffset = 0;
|
||||
|
||||
/**
|
||||
* Fetches a token from the scanner.
|
||||
*
|
||||
|
@ -4411,7 +4419,17 @@ public class Parser implements IParser
|
|||
{
|
||||
try
|
||||
{
|
||||
return scanner.nextToken();
|
||||
IToken t = scanner.nextToken();
|
||||
if( t.getEndOffset() > highWaterOffset )
|
||||
highWaterOffset = t.getEndOffset();
|
||||
if( t.getOffset() == 872556 )
|
||||
{
|
||||
Util.debugLog( "This is the point of failure.");
|
||||
Util.debugLog( "Token is of image =" + t.getImage() );
|
||||
Util.debugLog( "Token is on line " + scanner.getLineNumberForOffset( t.getOffset() ) );
|
||||
}
|
||||
Util.debugLog( "FetchToken retrieved token w/offset=" + t.getOffset() );
|
||||
return t;
|
||||
}
|
||||
catch (EndOfFile e)
|
||||
{
|
||||
|
@ -4419,7 +4437,7 @@ public class Parser implements IParser
|
|||
}
|
||||
catch (ScannerException e)
|
||||
{
|
||||
// e.printStackTrace();
|
||||
Util.debugLog( "ScannerException thrown : " + e.getMessage() );
|
||||
return fetchToken();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Vector;
|
|||
|
||||
import org.eclipse.cdt.core.parser.Backtrack;
|
||||
import org.eclipse.cdt.core.parser.EndOfFile;
|
||||
import org.eclipse.cdt.core.parser.ILineOffsetReconciler;
|
||||
import org.eclipse.cdt.core.parser.IMacroDescriptor;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.IProblemReporter;
|
||||
|
@ -42,6 +43,7 @@ import org.eclipse.cdt.core.parser.ast.ExpressionEvaluationException;
|
|||
import org.eclipse.cdt.core.parser.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFactory;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
||||
import org.eclipse.cdt.internal.core.model.Util;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -51,10 +53,13 @@ import org.eclipse.cdt.core.parser.ast.IASTInclusion;
|
|||
|
||||
public class Scanner implements IScanner {
|
||||
|
||||
private Reader backupReader;
|
||||
|
||||
public Scanner(Reader reader, String filename, IScannerInfo info, IProblemReporter problemReporter, ITranslationResult unitResult, ISourceElementRequestor requestor, ParserMode parserMode ) {
|
||||
this.requestor = requestor;
|
||||
this.mode = parserMode;
|
||||
astFactory = ParserFactory.createASTFactory( mode );
|
||||
this.backupReader = reader;
|
||||
|
||||
try {
|
||||
//this is a hack to get around a sudden EOF experience
|
||||
|
@ -2133,7 +2138,7 @@ public class Scanner implements IScanner {
|
|||
BAD_PP + contextStack.getCurrentContext().getOffset());
|
||||
}
|
||||
} else {
|
||||
System.out.println("Unexpected character " + ((char) c));
|
||||
Util.debugLog("Scanner : Encountered unexpected character " + ((char) c));
|
||||
if (throwExceptionOnBadPreprocessorSyntax)
|
||||
throw new ScannerException(BAD_PP + contextStack.getCurrentContext().getOffset());
|
||||
}
|
||||
|
@ -2325,7 +2330,7 @@ public class Scanner implements IScanner {
|
|||
"Improper use of macro " + symbol);
|
||||
|
||||
} else {
|
||||
System.out.println(
|
||||
Util.debugLog(
|
||||
"Unexpected class stored in definitions table. "
|
||||
+ expansion.getClass().getName());
|
||||
}
|
||||
|
@ -2546,4 +2551,15 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScanner#getLineNumberForOffset(int)
|
||||
*/
|
||||
public int getLineNumberForOffset(int i)
|
||||
{
|
||||
ILineOffsetReconciler reconciler = ParserFactory.createLineOffsetReconciler( backupReader );
|
||||
return reconciler.getLineNumberForOffset(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,6 +78,11 @@ public class Token implements IToken {
|
|||
case tAMPER:
|
||||
case tDOT:
|
||||
case tLPAREN:
|
||||
case tMINUS:
|
||||
case tSTAR:
|
||||
case tPLUS:
|
||||
case tNOT:
|
||||
case tCOMPL:
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue