mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
39677, 74190 - fix problem with statements in expressions
This commit is contained in:
parent
a8fc039327
commit
a22cca2f6b
4 changed files with 48 additions and 17 deletions
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -804,14 +804,15 @@ public class Parser implements IParserData, IParser
|
|||
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);
|
||||
|
|
|
@ -90,8 +90,13 @@ public abstract class GCCASTExtension implements IASTFactoryExtension {
|
|||
}
|
||||
else if ( kind == IASTGCCExpression.Kind.UNARY_TYPEOF_UNARYEXPRESSION )
|
||||
{
|
||||
if( lhs instanceof ASTExpression )
|
||||
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 )
|
||||
|
|
|
@ -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 &&
|
||||
|
|
Loading…
Add table
Reference in a new issue