Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2003-08-25 08:19:43 -0400
committerJohn Camelon2003-08-25 08:19:43 -0400
commit2f398f309b737924c3804bfdf892ef64c06c4e31 (patch)
treeed7b6bcb5164316f08bf52877bf858f5df9ba3c8
parent94b8758d5cea9afa245433bff83ae627dd9bc604 (diff)
downloadorg.eclipse.cdt-2f398f309b737924c3804bfdf892ef64c06c4e31.tar.gz
org.eclipse.cdt-2f398f309b737924c3804bfdf892ef64c06c4e31.tar.xz
org.eclipse.cdt-2f398f309b737924c3804bfdf892ef64c06c4e31.zip
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().
-rw-r--r--core/org.eclipse.cdt.core.tests/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java6
-rw-r--r--core/org.eclipse.cdt.core/.options1
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/ChangeLog6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java170
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java5
10 files changed, 143 insertions, 81 deletions
diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog
index 493c9783be4..ac5d66215c6 100644
--- a/core/org.eclipse.cdt.core.tests/ChangeLog
+++ b/core/org.eclipse.cdt.core.tests/ChangeLog
@@ -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(),
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
index 7bfa0e7e345..39afa82a699 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java
@@ -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)");
+ }
+
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/.options b/core/org.eclipse.cdt.core/.options
new file mode 100644
index 00000000000..9eea7f17093
--- /dev/null
+++ b/core/org.eclipse.cdt.core/.options
@@ -0,0 +1 @@
+org.eclipse.cdt.core/debug=true \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
index 5ba15056ebb..5697a154f48 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java
@@ -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) {
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog
index 2dd0bfbc5c1..72fd45b0d55 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog
@@ -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).
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
index 71faa54a4c7..83c690cf22a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
@@ -32,4 +32,9 @@ public interface IScanner {
public void setTokenizingMacroReplacementList(boolean b);
public void onParseEnd();
+ /**
+ * @param i
+ * @return
+ */
+ public int getLineNumberForOffset(int i);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java
index b57507109f7..d108e3e418d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ContextStack.java
@@ -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 )
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 a9413c4f8b0..c1996e50013 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
@@ -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,8 +1871,11 @@ 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())
+ if (!LA(2).looksLikeExpression() )
{
// parameterDeclarationClause
d.setIsFunction(true);
@@ -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,8 +2117,9 @@ public class Parser implements IParser
{
// this ptrOp doesn't belong to the declarator,
// it's just a part of the name
- ptrOperator(d);
- toSend = lastToken;
+ consumePointerOperators(d, true);
+ if( lastToken != null )
+ toSend = lastToken;
}
catch (Backtrack b)
{
@@ -2149,50 +2145,59 @@ 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
{
- int t = LT(1);
- if (t == IToken.tAMPER)
- {
- consume( IToken.tAMPER );
- d.addPtrOp(ASTPointerOperator.REFERENCE);
- return;
- }
- IToken mark = mark();
- IToken tokenType = LA(1);
- ITokenDuple nameDuple = null;
- if (t == IToken.tIDENTIFIER || t == IToken.tCOLONCOLON)
- {
- nameDuple = name();
- t = LT(1);
- }
- if (t == IToken.tSTAR)
- {
- tokenType = consume(Token.tSTAR); // tokenType = "*"
-
- d.setPointerOperatorName(nameDuple);
-
- boolean successful = false;
- for (;;)
- {
- try
- {
- cvQualifier(d);
- successful = true;
- }
- catch (Backtrack b)
- {
- // expected at some point
- break;
- }
- }
- if( !successful )
- d.addPtrOp( ASTPointerOperator.POINTER );
-
- return;
- }
- backup(mark);
- throw backtrack;
+ for( ; ; )
+ {
+ int t = LT(1);
+ if (t == IToken.tAMPER)
+ {
+ consume( IToken.tAMPER );
+ d.addPtrOp(ASTPointerOperator.REFERENCE);
+ 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)
+ {
+ tokenType = consume(Token.tSTAR); // tokenType = "*"
+
+ d.setPointerOperatorName(nameDuple);
+
+ boolean successful = false;
+ for (;;)
+ {
+ boolean newSuccess = cvQualifier(d);
+ if( newSuccess ) successful = true;
+ else break;
+
+ }
+
+ if( !successful )
+ {
+ d.addPtrOp( ASTPointerOperator.POINTER );
+ }
+ if( consumeOnlyOne ) return;
+ continue;
+ }
+ backup(mark);
+ 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();
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java
index 004cd6640a7..0be9a560ea1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java
@@ -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 {
- public Scanner(Reader reader, String filename, IScannerInfo info, IProblemReporter problemReporter, ITranslationResult unitResult, ISourceElementRequestor requestor, ParserMode parserMode ) {
+ 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);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java
index 640307935f5..b8a4fffdd64 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java
@@ -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;

Back to the top