Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Applied [HEAD] Parsing function bodies

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().

JohnC

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/ChangeLog,v
retrieving revision 1.80
diff -u -r1.80 ChangeLog
--- ChangeLog	5 Sep 2003 18:31:44 -0000	1.80
+++ ChangeLog	5 Sep 2003 19:23:30 -0000
@@ -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
Index: parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java,v
retrieving revision 1.23
diff -u -r1.23 CompleteParseASTTest.java
--- parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	5 Sep 2003 15:23:17 -0000	1.23
+++ parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java	5 Sep 2003 19:23:30 -0000
@@ -653,4 +653,41 @@
 		 
 	}	
 	
+	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 );
+	}
 }
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.112
diff -u -r1.112 ChangeLog
--- parser/ChangeLog	5 Sep 2003 14:20:15 -0000	1.112
+++ parser/ChangeLog	5 Sep 2003 19:23:03 -0000
@@ -1,4 +1,8 @@
 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.  
 
 2003-09-04 John Camelon
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.101
diff -u -r1.101 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java	4 Sep 2003 20:46:57 -0000	1.101
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java	5 Sep 2003 19:23:05 -0000
@@ -934,7 +934,8 @@
                 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 @@
         }
         
     }
-    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

Back to the top