Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Niefer2004-10-20 12:51:54 -0400
committerAndrew Niefer2004-10-20 12:51:54 -0400
commita22cca2f6b980fcdd0df4c6a04b477dff544527f (patch)
tree1464c4d60338c3ed222cad25d45e5ecd8446e08c /core
parenta8fc039327a1cf1bc8be2b2fec849736b3b2d3e6 (diff)
downloadorg.eclipse.cdt-a22cca2f6b980fcdd0df4c6a04b477dff544527f.tar.gz
org.eclipse.cdt-a22cca2f6b980fcdd0df4c6a04b477dff544527f.tar.xz
org.eclipse.cdt-a22cca2f6b980fcdd0df4c6a04b477dff544527f.zip
39677, 74190 - fix problem with statements in expressions
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java27
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java25
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java9
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java4
4 files changed, 48 insertions, 17 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java
index b41848e8337..341edcf515b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteParseExtensionsTest.java
@@ -200,16 +200,23 @@ public class GCCCompleteParseExtensionsTest extends CompleteParseBaseTest {
writer.write( "else z = - y;\n" );//$NON-NLS-1$
writer.write( "z; }))\n" );//$NON-NLS-1$
parse( writer.toString() );
+
writer = new StringWriter();
writer.write( "int x = ({ int y = foo (); int z;\n" ); //$NON-NLS-1$
writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
writer.write( "else z = - y;\n" );//$NON-NLS-1$
writer.write( "z; });\n" );//$NON-NLS-1$
+ parse( writer.toString() );
+
writer = new StringWriter();
- writer.write( "typeof({ int y = foo (); int z;\n" ); //$NON-NLS-1$
- writer.write( "if (y > 0) z = y;\n" ); //$NON-NLS-1$
- writer.write( "else z = - y;\n" );//$NON-NLS-1$
- writer.write( "z; }) zoot;\n" );//$NON-NLS-1$
+ writer.write( "int foo(); \n" ); //$NON-NLS-1$
+ writer.write( "typeof({ int y = foo (); \n" ); //$NON-NLS-1$
+ writer.write( " int z; \n" ); //$NON-NLS-1$
+ writer.write( " if (y > 0) z = y; \n" ); //$NON-NLS-1$
+ writer.write( " else z = - y; \n" ); //$NON-NLS-1$
+ writer.write( " z; \n" ); //$NON-NLS-1$
+ writer.write( " }) zoot; \n" ); //$NON-NLS-1$
+ parse( writer.toString() );
}
public void testBug75401() throws Exception
@@ -247,4 +254,16 @@ public class GCCCompleteParseExtensionsTest extends CompleteParseBaseTest {
assertFalse(i.hasNext());
}
+ public void testBug74190_g_assert_1() throws Exception {
+ Writer writer = new StringWriter();
+ writer.write( "void log( int ); \n"); //$NON-NLS-1$
+ writer.write( "void f() { \n"); //$NON-NLS-1$
+ writer.write( " int a = 1; \n"); //$NON-NLS-1$
+ writer.write( " (void)({ if( a ){ } \n"); //$NON-NLS-1$
+ writer.write( " else{ log( a ); } \n"); //$NON-NLS-1$
+ writer.write( " }); \n"); //$NON-NLS-1$
+ writer.write( "} \n"); //$NON-NLS-1$
+
+ parse( writer.toString() );
+ }
}
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 5d620647641..62402330f06 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
@@ -803,15 +803,16 @@ public class Parser implements IParserData, IParser
int startingOffset = la.getOffset();
int ln = la.getLineNumber();
char [] fn = la.getFilename();
-
- IASTExpression resultExpression = null;
- if( la.getType() == IToken.tLPAREN && LT(2) == IToken.tLBRACE && extension.supportsStatementsInExpressions() )
- {
- resultExpression = compoundStatementExpression(scope, la, resultExpression);
- }
-
- if( resultExpression != null )
- return resultExpression;
+
+ //moved to primary expression
+// IASTExpression resultExpression = null;
+// if( la.getType() == IToken.tLPAREN && LT(2) == IToken.tLBRACE && extension.supportsStatementsInExpressions() )
+// {
+// resultExpression = compoundStatementExpression(scope, la, resultExpression);
+// }
+//
+// if( resultExpression != null )
+// return resultExpression;
IASTExpression assignmentExpression = assignmentExpression(scope, kind,
key);
@@ -2623,6 +2624,12 @@ public class Parser implements IParserData, IParser
throwBacktrack(t.getOffset(), t.getEndOffset(), t.getLineNumber(), t.getFilename());
}
case IToken.tLPAREN :
+ if( LT(2) == IToken.tLBRACE && extension.supportsStatementsInExpressions() )
+ {
+ IASTExpression resultExpression = compoundStatementExpression(scope, LA(1), null);
+ if( resultExpression != null )
+ return resultExpression;
+ }
t = consume();
if (templateIdScopes.size() > 0) {
templateIdScopes.push(IToken.tLPAREN);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java
index 840b6d3b6d9..866af2a379d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ast/GCCASTExtension.java
@@ -90,8 +90,13 @@ public abstract class GCCASTExtension implements IASTFactoryExtension {
}
else if ( kind == IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION )
{
- if( lhs instanceof ASTExpression )
- info = TypeInfoProvider.newTypeInfo( ((ASTExpression)lhs).getResultType().getResult() );
+ if( lhs instanceof ASTExpression ){
+ if( ((ASTExpression) lhs).getResultType() != null )
+ info = TypeInfoProvider.newTypeInfo( ((ASTExpression)lhs).getResultType().getResult() );
+ else {
+ info = TypeInfoProvider.newTypeInfo( ITypeInfo.t_void );
+ }
+ }
}
if( info != null )
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java
index e6caac27111..a36847a4725 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/BasicTokenDuple.java
@@ -224,8 +224,8 @@ public class BasicTokenDuple implements ITokenDuple {
int length = getCharArrayLength( f, l );
char[] buff = new char[ length ];
- int i = 0;
- for( ; ; )
+
+ for( int i = 0; i < length; )
{
if( prev != null &&
prev.getType() != IToken.tCOLONCOLON &&

Back to the top