From 8b12ea5492acd6e5207db851ac718339a9a290b3 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Fri, 5 Sep 2003 19:24:11 +0000 Subject: [PATCH] CORE Continue to add support for parsing within function bodies. Add workaround for 1.2 for inline function declaration-before-use chicken-and-egg. TESTS Added CompleteParseASTTest::testSimpleIfStatement(), testSimpleWhileStatement(). testSimpleSwitchStatement(), testSimpleDoStatement(). --- core/org.eclipse.cdt.core.tests/ChangeLog | 4 ++ .../parser/tests/CompleteParseASTTest.java | 37 +++++++++++++++++++ core/org.eclipse.cdt.core/parser/ChangeLog | 4 ++ .../cdt/internal/core/parser/Parser.java | 7 ++-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index 99c3e2d3473..83da20c763a 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,7 @@ +2003-09-05 John Camelon + Added CompleteParseASTTest::testSimpleIfStatement(), testSimpleWhileStatement(). + testSimpleSwitchStatement(), testSimpleDoStatement(). + 2003-09-05 Andrew Niefer Added testEnumerators to OtherPatternTests.java Modified resources/search/classDecl.cpp to include some enumerators diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 567260f0b4b..175d59aa6d9 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -653,4 +653,41 @@ public class CompleteParseASTTest extends CompleteParseBaseTest } + public void testSimpleIfStatement() throws Exception + { + Iterator i = parse( "const bool T = true; int foo() { if( T ) { return 5; } else if( ! T ) return 20; else { return 10; } }").getDeclarations(); + IASTVariable t = (IASTVariable)i.next(); + IASTFunction foo = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + } + + public void testSimpleWhileStatement() throws Exception + { + Iterator i = parse( "const bool T = true; void foo() { int x = 0; while( T ) { ++x; if( x == 100 ) break; } }").getDeclarations(); + IASTVariable t = (IASTVariable)i.next(); + IASTFunction foo = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + } + + public void testSimpleSwitchStatement() throws Exception + { + Iterator i = parse( "const int x = 5; const int y = 10; void foo() { switch( x ) { case 1: break; case 2: goto blah; case y: continue; default: break;} }").getDeclarations(); + IASTVariable x = (IASTVariable)i.next(); + IASTVariable y = (IASTVariable)i.next(); + IASTFunction foo = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 2 ); + } + + public void testSimpleDoStatement() throws Exception + { + Iterator i = parse( "const int x = 3; int counter = 0; void foo() { do { ++counter; } while( counter != x ); } ").getDeclarations(); + IASTVariable x = (IASTVariable)i.next(); + IASTVariable counter = (IASTVariable)i.next(); + IASTFunction foo = (IASTFunction)i.next(); + assertFalse( i.hasNext() ); + assertEquals( callback.getReferences().size(), 3 ); + } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 7130028edd7..fafba355b1b 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,7 @@ +2003-09-05 John Camelon + Continue to add support for parsing within function bodies. + Add workaround for 1.2 for inline function declaration-before-use chicken-and-egg. + 2003-09-05 John Camelon Fixed NPE on nested declarations in code blocks. 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 279ae344f10..17b2b9528c3 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 @@ -934,7 +934,8 @@ public class Parser implements IParser IASTDeclaration declaration = (IASTDeclaration)i.next(); declaration.enterScope( requestor ); - handleFunctionBody((IASTScope)declaration); + handleFunctionBody((IASTScope)declaration, + sdw.isInline() ); ((IASTOffsetableElement)declaration).setEndingOffset( lastToken.getEndOffset()); @@ -954,9 +955,9 @@ public class Parser implements IParser } } - protected void handleFunctionBody(IASTScope scope) throws Backtrack, EndOfFile + protected void handleFunctionBody(IASTScope scope, boolean isInlineFunction) throws Backtrack, EndOfFile { - if ( mode == ParserMode.QUICK_PARSE ) // TODO - Enable parsing within function bodies i.e. mode == ParserMode.QUICK_PARSE) + if ( mode == ParserMode.QUICK_PARSE || isInlineFunction ) { // speed up the parser by skiping the body // simply look for matching brace and return