diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java index 7f998f7931a..9974dfa0674 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/parser2/QuickParser2Tests.java @@ -407,6 +407,7 @@ public class QuickParser2Tests extends TestCase { } public void testBug36766and36769C() throws Exception { + //TODO - requires CPPVisitor Writer code = new StringWriter(); code.write("template \n"); //$NON-NLS-1$ code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n"); //$NON-NLS-1$ @@ -417,6 +418,7 @@ public class QuickParser2Tests extends TestCase { } public void testBug36766and36769D() throws Exception { + //TODO - requires CPPVisitor Writer code = new StringWriter(); code.write("template \n"); //$NON-NLS-1$ code.write("rope<_CharT, _Alloc>::~rope()\n"); //$NON-NLS-1$ @@ -750,6 +752,7 @@ public class QuickParser2Tests extends TestCase { } public void testConstructorChain() throws Exception { + //TODO - requires CPPVisitor in order to reduce ambiguities parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}"); //$NON-NLS-1$ } @@ -809,8 +812,7 @@ public class QuickParser2Tests extends TestCase { code.write("#define CMD_GET \"g\"\n"); //$NON-NLS-1$ code.write("#define CMD_ACTION \"a\"\n"); //$NON-NLS-1$ code.write("#define CMD_QUIT \"q\"\n"); //$NON-NLS-1$ - code - .write("static const memevent_cmd_func memevent_cmd_funcs[sizeof memevent_cmds - 1] = {\n"); //$NON-NLS-1$ + code.write("static const memevent_cmd_func memevent_cmd_funcs[sizeof memevent_cmds - 1] = {\n"); //$NON-NLS-1$ code.write("memevent_get,\n"); //$NON-NLS-1$ code.write("memevent_action,\n"); //$NON-NLS-1$ code.write("memevent_quit,\n"); //$NON-NLS-1$ @@ -835,6 +837,7 @@ public class QuickParser2Tests extends TestCase { } public void testOrder() throws Exception { + //TODO - requires CPPVisitor Writer code = new StringWriter(); code.write("#define __SGI_STL_INTERNAL_ALGOBASE_H\n"); //$NON-NLS-1$ code.write("#include \n"); //$NON-NLS-1$ @@ -1343,6 +1346,7 @@ public class QuickParser2Tests extends TestCase { // } public void testBug47752() throws Exception { + //TODO requires CPPVisitor parse("void func( cFoo bar ) try { } catch ( const char * error ){ }"); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTSimpleDeclSpecifier.java index 1268eaaf547..61a3e3a383c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/IGPPASTSimpleDeclSpecifier.java @@ -10,6 +10,8 @@ **********************************************************************/ package org.eclipse.cdt.core.dom.ast.gnu.cpp; +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier; /** @@ -20,9 +22,17 @@ public interface IGPPASTSimpleDeclSpecifier extends IGPPASTDeclSpecifier, public static final int t_Complex = ICPPASTSimpleDeclSpecifier.t_last + 1; public static final int t_Imaginary = ICPPASTSimpleDeclSpecifier.t_last + 2; - public static final int t_last = t_Imaginary; + public static final int t_typeof = ICPPASTSimpleDeclSpecifier.t_last + 3; + public static final int t_last = t_typeof; + + public static final ASTNodeProperty TYPEOF_EXPRESSION = new ASTNodeProperty( "Typeof Expression"); //$NON-NLS-1$ public boolean isLongLong(); public void setLongLong( boolean value ); + /** + * @param typeofExpression + */ + public void setTypeofExpression(IASTExpression typeofExpression); + public IASTExpression getTypeofExpression(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java index a2bad2a4295..7234892bc12 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/AbstractGNUSourceCodeParser.java @@ -516,15 +516,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected abstract IASTCompoundStatement createCompoundStatement(); /** - * @param la * @return @throws * EndOfFileException * @throws BacktrackException */ - protected IASTExpression compoundStatementExpression(IToken la) + protected IASTExpression compoundStatementExpression() throws EndOfFileException, BacktrackException { - int startingOffset = la.getOffset(); - consume(IToken.tLPAREN); + int startingOffset =consume(IToken.tLPAREN).getOffset(); IASTCompoundStatement compoundStatement = null; if (mode == ParserMode.QUICK_PARSE || mode == ParserMode.STRUCTURAL_PARSE) @@ -564,7 +562,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { if (la.getType() == IToken.tLPAREN && LT(2) == IToken.tLBRACE && supportStatementsInExpressions) { - IASTExpression resultExpression = compoundStatementExpression(la); + IASTExpression resultExpression = compoundStatementExpression(); if (resultExpression != null) return resultExpression; } @@ -918,15 +916,20 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { IToken m = mark(); if (LT(1) == IToken.tLPAREN) { - try { - consume(IToken.tLPAREN); - d = typeId(false); - consume(IToken.tRPAREN); - } catch (BacktrackException bt) { - backup(m); - d = null; - unaryExpression = unaryExpression(); + if( LT(2) == IToken.tLBRACE ) + { + unaryExpression = compoundStatementExpression(); } + else + try { + consume(IToken.tLPAREN); + d = typeId(false); + consume(IToken.tRPAREN); + } catch (BacktrackException bt) { + backup(m); + d = null; + unaryExpression = unaryExpression(); + } } else { unaryExpression = unaryExpression(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java index 2589f4d9b74..57374a2cde6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GNUCPPSourceParser.java @@ -621,6 +621,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.t_throw) { return throwExpression(); } + + if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tLBRACE + && supportStatementsInExpressions) { + IASTExpression resultExpression = compoundStatementExpression(); + if (resultExpression != null) + return resultExpression; + } + IASTExpression conditionalExpression = conditionalExpression(); // if the condition not taken, try assignment operators @@ -2707,6 +2715,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { backup(mark); return true; } + char [] destructorName = CharArrayUtils.concat( "~".toCharArray(), otherName ); //$NON-NLS-1$ + if( CharArrayUtils.equals( destructorName, className )) + { + backup( mark ); + return true; + } backup(mark); return false; @@ -2752,6 +2766,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { ICPPASTCompositeTypeSpecifier classSpec = null; ICPPASTElaboratedTypeSpecifier elabSpec = null; IASTEnumerationSpecifier enumSpec = null; + IASTExpression typeofExpression = null; declSpecifiers: for (;;) { switch (LT(1)) { case IToken.t_inline: @@ -2939,8 +2954,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } default: if (supportTypeOfUnaries && LT(1) == IGCCToken.t_typeof) { - Object expression = unaryTypeofExpression(); - if (expression != null) { + typeofExpression = unaryTypeofExpression(); + if (typeofExpression != null) { flags.setEncounteredTypename(true); } } @@ -3008,10 +3023,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return nameSpec; } ICPPASTSimpleDeclSpecifier simpleDeclSpec = null; - if( isLongLong ) + if( isLongLong || typeofExpression != null ) { simpleDeclSpec = createGPPSimpleDeclSpecifier(); ((IGPPASTSimpleDeclSpecifier)simpleDeclSpec).setLongLong( isLongLong ); + if( typeofExpression != null ) + { + ((IGPPASTSimpleDeclSpecifier)simpleDeclSpec).setTypeofExpression( typeofExpression ); + typeofExpression.setParent( simpleDeclSpec ); + typeofExpression.setPropertyInParent( IGPPASTSimpleDeclSpecifier.TYPEOF_EXPRESSION ); + } } else simpleDeclSpec = createSimpleDeclSpecifier(); @@ -3192,6 +3213,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { for (;;) { + if (LT(1) == IToken.tRBRACE) + break; + IASTInitializer clause = initializerClause( ); if (clause != null) { result.addInitializer( clause ); @@ -3321,7 +3345,11 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { try { try { queryName = name(); - failed = true; + //TODO - when the Visitor is available + //find the IASTName relating to this in the AST + //if this is a type, failed = false + //if this is a value, failed = true + failed = false; } catch (Exception e) { int endOffset = (lastToken != null) ? lastToken .getEndOffset() diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GPPASTSimpleDeclSpecifier.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GPPASTSimpleDeclSpecifier.java index 80186482c7e..e0275cd3f4d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GPPASTSimpleDeclSpecifier.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser2/cpp/GPPASTSimpleDeclSpecifier.java @@ -10,6 +10,7 @@ **********************************************************************/ package org.eclipse.cdt.internal.core.parser2.cpp; +import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier; /** @@ -19,6 +20,8 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier implements IGPPASTSimpleDeclSpecifier { private boolean longLong; + private boolean restrict; + private IASTExpression typeOfExpression; /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier#isLongLong() @@ -38,16 +41,28 @@ public class GPPASTSimpleDeclSpecifier extends CPPASTSimpleDeclSpecifier * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTDeclSpecifier#isRestrict() */ public boolean isRestrict() { - // TODO Auto-generated method stub - return false; + return restrict; } /* (non-Javadoc) * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTDeclSpecifier#setRestrict(boolean) */ public void setRestrict(boolean value) { - // TODO Auto-generated method stub - + restrict = value; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier#setTypeofExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) + */ + public void setTypeofExpression(IASTExpression typeofExpression) { + typeOfExpression = typeofExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier#getTypeofExpression() + */ + public IASTExpression getTypeofExpression() { + return typeOfExpression; } }