mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed Bug 90641 [Parser] function decl vs ctor initializer ambiguity
Fixed Bug 81806 [Parser2] [Ambiguity] Constructor Initializer is mistaken as function prototype Fixed Bug 94779 [Ambiguity] declarator with initializer parsed as function declarator
This commit is contained in:
parent
c885f752da
commit
a5843c1e7e
21 changed files with 375 additions and 177 deletions
|
@ -224,27 +224,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 8.5-2):
|
||||
int f(int);
|
||||
int a = 2;
|
||||
int b = f(a);
|
||||
int c(b);
|
||||
--End Example]
|
||||
*/
|
||||
public void test8_5s2() { // TODO raised bug 90641
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int f(int);\n"); //$NON-NLS-1$
|
||||
buffer.append("int a = 2;\n"); //$NON-NLS-1$
|
||||
buffer.append("int b = f(a);\n"); //$NON-NLS-1$
|
||||
buffer.append("int c(b);\n"); //$NON-NLS-1$
|
||||
try {
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
assertTrue(false);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 8.5.2-1):
|
||||
char msg[] = "Syntax error on line %s\n";
|
||||
|
|
|
@ -12511,5 +12511,23 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
buffer.append("int ef(D&);\n"); //$NON-NLS-1$
|
||||
buffer.append("int ff(X&);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
[--Start Example(CPP 8.5-2):
|
||||
int f(int);
|
||||
int a = 2;
|
||||
int b = f(a);
|
||||
int c(b);
|
||||
--End Example]
|
||||
* @throws ParserException
|
||||
*/
|
||||
public void test8_5s2() throws ParserException { // 90641
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("int f(int);\n"); //$NON-NLS-1$
|
||||
buffer.append("int a = 2;\n"); //$NON-NLS-1$
|
||||
buffer.append("int b = f(a);\n"); //$NON-NLS-1$
|
||||
buffer.append("int c(b);\n"); //$NON-NLS-1$
|
||||
parse(buffer.toString(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3340,10 +3340,10 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
|
||||
public void testBug90498_1() throws Exception {
|
||||
IASTTranslationUnit tu = parse(
|
||||
"typedef INT ( FOO ) (INT);", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
"typedef int INT;\ntypedef INT ( FOO ) (INT);", ParserLanguage.CPP); //$NON-NLS-1$
|
||||
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu
|
||||
.getDeclarations()[0];
|
||||
.getDeclarations()[1];
|
||||
IASTDeclSpecifier declSpec = decl.getDeclSpecifier();
|
||||
assertTrue(declSpec instanceof ICPPASTNamedTypeSpecifier);
|
||||
assertEquals(((ICPPASTNamedTypeSpecifier) declSpec).getName()
|
||||
|
@ -4344,4 +4344,15 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertSame( str, col.getName(7).resolveBinding() );
|
||||
assertSame( str, col.getName(9).resolveBinding() );
|
||||
}
|
||||
|
||||
public void testBug94779() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "void f( int t ){\n" );
|
||||
buffer.append( "int s ( t );\n" );
|
||||
buffer.append( "}\n" );
|
||||
IASTTranslationUnit tu = parse( buffer.toString(), ParserLanguage.CPP );
|
||||
IASTDeclarationStatement ds = (IASTDeclarationStatement) ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[0]).getBody()).getStatements()[0];
|
||||
IASTDeclarator d = ((IASTSimpleDeclaration)ds.getDeclaration()).getDeclarators()[0];
|
||||
assertTrue( d.getName().resolveBinding() instanceof IVariable );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ import junit.framework.TestCase;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
|
@ -832,21 +834,21 @@ public class CompleteParser2Tests extends TestCase {
|
|||
|
||||
public void testBug41520() throws Exception
|
||||
{
|
||||
/*IASTTranslationUnit tu =*/ parse( "const int x = 666; const int y( x );"); //$NON-NLS-1$
|
||||
IASTTranslationUnit tu = parse( "const int x = 666; const int y( x );"); //$NON-NLS-1$
|
||||
|
||||
// IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
// IASTDeclarator dtor = decl.getDeclarators()[0];
|
||||
// assertFalse( dtor instanceof IASTFunctionDeclarator );
|
||||
// assertNotNull( dtor.getInitializer() );
|
||||
//
|
||||
// CPPNameCollector col = new CPPNameCollector();
|
||||
// tu.accept( col );
|
||||
//
|
||||
// assertEquals( col.size(), 3 );
|
||||
// IVariable x = (IVariable) col.getName(0).resolveBinding();
|
||||
// IVariable y = (IVariable) col.getName(1).resolveBinding();
|
||||
// assertNotNull(y);
|
||||
// assertInstances( col, x, 2 );
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) tu.getDeclarations()[1];
|
||||
IASTDeclarator dtor = decl.getDeclarators()[0];
|
||||
assertFalse( dtor instanceof IASTFunctionDeclarator );
|
||||
assertNotNull( dtor.getInitializer() );
|
||||
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept( col );
|
||||
|
||||
assertEquals( col.size(), 3 );
|
||||
IVariable x = (IVariable) col.getName(0).resolveBinding();
|
||||
IVariable y = (IVariable) col.getName(1).resolveBinding();
|
||||
assertNotNull(y);
|
||||
assertInstances( col, x, 2 );
|
||||
}
|
||||
|
||||
public void testNewXReferences() throws Exception
|
||||
|
|
|
@ -398,7 +398,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
throw backtrack;
|
||||
}
|
||||
|
||||
protected IToken simpleDeclarationMark;
|
||||
|
||||
private static final IASTNode[] EMPTY_NODE_ARRAY = new IASTNode[0];
|
||||
|
||||
|
@ -494,11 +493,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
errorHandling();
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
protected void throwAwayMarksForInitializerClause() {
|
||||
simpleDeclarationMark = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TODO
|
||||
|
@ -1590,6 +1584,32 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
return expressionStatement;
|
||||
}
|
||||
|
||||
if (ds.getDeclaration() instanceof IASTAmbiguousDeclaration )
|
||||
{
|
||||
IASTAmbiguousDeclaration amb = (IASTAmbiguousDeclaration) ds.getDeclaration();
|
||||
IASTDeclaration [] ambDs = amb.getDeclarations();
|
||||
int ambCount = 0;
|
||||
for( int i = 0; i < ambDs.length; ++i )
|
||||
{
|
||||
if (ambDs[i] instanceof IASTSimpleDeclaration
|
||||
&& ((IASTSimpleDeclaration) ambDs[i])
|
||||
.getDeclSpecifier() instanceof IASTSimpleDeclSpecifier
|
||||
&& ((IASTSimpleDeclSpecifier) ((IASTSimpleDeclaration) ambDs[i]).getDeclSpecifier()).getType() == IASTSimpleDeclSpecifier.t_unspecified) {
|
||||
++ambCount;
|
||||
}
|
||||
}
|
||||
if ( ambCount == ambDs.length )
|
||||
{
|
||||
backup(mark);
|
||||
while (true) {
|
||||
if (consume() == lastTokenOfExpression)
|
||||
break;
|
||||
}
|
||||
|
||||
return expressionStatement;
|
||||
}
|
||||
}
|
||||
|
||||
if (ds.getDeclaration() instanceof IASTSimpleDeclaration
|
||||
&& ((IASTSimpleDeclaration) ds.getDeclaration())
|
||||
.getDeclSpecifier() instanceof IASTNamedTypeSpecifier)
|
||||
|
|
|
@ -46,34 +46,6 @@ public abstract class CASTAmbiguity extends CASTNode {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param names
|
||||
* @param j
|
||||
* @throws DOMException
|
||||
*/
|
||||
protected void clearCache(IASTName[] names, int j) {
|
||||
IScope scope = CPPVisitor.getContainingScope( names[j] );
|
||||
try {
|
||||
scope.flushCache();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visitor
|
||||
* @param nodes
|
||||
* @param bestIndex
|
||||
* @return
|
||||
*/
|
||||
protected boolean reduceAmbiguity(ASTVisitor visitor, IASTNode[] nodes, int bestIndex) {
|
||||
IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent();
|
||||
IASTNode s = nodes[bestIndex];
|
||||
owner.replace(this, nodes[bestIndex]);
|
||||
if (!s.accept(visitor))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract IASTNode [] getNodes();
|
||||
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
|
@ -83,6 +55,7 @@ public abstract class CASTAmbiguity extends CASTNode {
|
|||
for( int i = 0; i < nodez.length; ++i )
|
||||
{
|
||||
IASTNode s = nodez[i];
|
||||
s.accept(visitor);
|
||||
CASTNameCollector resolver = new CASTNameCollector();
|
||||
s.accept( resolver );
|
||||
IASTName [] names = resolver.getNames();
|
||||
|
@ -93,7 +66,11 @@ public abstract class CASTAmbiguity extends CASTNode {
|
|||
IBinding b = names[j].resolveBinding();
|
||||
if( b == null || b instanceof IProblemBinding )
|
||||
++issues[i];
|
||||
clearCache(names, j);
|
||||
IScope scope = CPPVisitor.getContainingScope( names[j] );
|
||||
try {
|
||||
scope.flushCache();
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
|
@ -112,7 +89,9 @@ public abstract class CASTAmbiguity extends CASTNode {
|
|||
}
|
||||
}
|
||||
|
||||
return reduceAmbiguity(visitor, nodez, bestIndex);
|
||||
IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent();
|
||||
owner.replace(this, nodez[bestIndex]);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -139,18 +139,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
supportGCCStyleDesignators = config.supportGCCStyleDesignators();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param d
|
||||
*/
|
||||
protected void throwAwayMarksForInitializerClause() {
|
||||
simpleDeclarationMark = null;
|
||||
}
|
||||
|
||||
protected IASTInitializer optionalCInitializer() throws EndOfFileException,
|
||||
BacktrackException {
|
||||
if (LT(1) == IToken.tASSIGN) {
|
||||
consume(IToken.tASSIGN);
|
||||
throwAwayMarksForInitializerClause();
|
||||
return cInitializerClause(Collections.EMPTY_LIST);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -42,33 +42,6 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @throws DOMException
|
||||
*/
|
||||
protected void clearCache(IASTName name) {
|
||||
IScope scope = CPPVisitor.getContainingScope(name);
|
||||
try {
|
||||
scope.flushCache();
|
||||
} catch (DOMException de) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param visitor
|
||||
* @param nodes
|
||||
* @param bestIndex
|
||||
* @return
|
||||
*/
|
||||
protected boolean reduceAmbiguity(ASTVisitor visitor, IASTNode[] nodes,
|
||||
int bestIndex) {
|
||||
IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent();
|
||||
IASTNode s = nodes[bestIndex];
|
||||
owner.replace(this, nodes[bestIndex]);
|
||||
if (!s.accept(visitor))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract IASTNode[] getNodes();
|
||||
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
|
@ -77,6 +50,7 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
|
|||
Arrays.fill(issues, 0);
|
||||
for (int i = 0; i < nodez.length; ++i) {
|
||||
IASTNode s = nodez[i];
|
||||
s.accept( visitor );
|
||||
CPPASTNameCollector resolver = new CPPASTNameCollector();
|
||||
s.accept(resolver);
|
||||
IASTName[] names = resolver.getNames();
|
||||
|
@ -89,8 +63,12 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
|
|||
++issues[i];
|
||||
}
|
||||
}
|
||||
if (names.length > 0)
|
||||
clearCache(names[0]);
|
||||
if (names.length > 0) {
|
||||
IScope scope = CPPVisitor.getContainingScope(names[0]);
|
||||
try {
|
||||
scope.flushCache();
|
||||
} catch (DOMException de) {}
|
||||
}
|
||||
}
|
||||
int bestIndex = 0;
|
||||
int bestValue = issues[0];
|
||||
|
@ -101,7 +79,9 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
|
|||
}
|
||||
}
|
||||
|
||||
return reduceAmbiguity(visitor, nodez, bestIndex);
|
||||
IASTAmbiguityParent owner = (IASTAmbiguityParent) getParent();
|
||||
owner.replace(this, nodez[bestIndex]);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,5 +89,12 @@ public class CPPASTCatchHandler extends CPPASTNode implements
|
|||
other.setParent( child.getParent() );
|
||||
body = (IASTStatement) other;
|
||||
}
|
||||
if( declaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declaration = (IASTDeclaration) other;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,15 +13,17 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
||||
implements ICPPASTCompositeTypeSpecifier {
|
||||
implements ICPPASTCompositeTypeSpecifier, IASTAmbiguityParent {
|
||||
|
||||
private int k;
|
||||
private IASTName n;
|
||||
|
@ -139,4 +141,18 @@ public class CPPASTCompositeTypeSpecifier extends CPPASTBaseDeclSpecifier
|
|||
return r_definition;
|
||||
return r_unclear;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declarations == null ) return;
|
||||
for( int i = 0; i < declarations.length; ++i )
|
||||
{
|
||||
if( declarations[i] == null ) continue;
|
||||
if( declarations[i] == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declarations[i] = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,14 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTDeclarationStatement extends CPPASTNode implements
|
||||
IASTDeclarationStatement {
|
||||
IASTDeclarationStatement, IASTAmbiguityParent {
|
||||
|
||||
private IASTDeclaration declaration;
|
||||
|
||||
|
@ -47,4 +49,13 @@ public class CPPASTDeclarationStatement extends CPPASTNode implements
|
|||
if( declaration != null ) if( !declaration.accept( action ) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declaration = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,15 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTExplicitTemplateInstantiation extends CPPASTNode implements
|
||||
ICPPASTExplicitTemplateInstantiation {
|
||||
ICPPASTExplicitTemplateInstantiation, IASTAmbiguityParent {
|
||||
|
||||
private IASTDeclaration declaration;
|
||||
|
||||
|
@ -49,4 +51,13 @@ public class CPPASTExplicitTemplateInstantiation extends CPPASTNode implements
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declaration = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,5 +152,12 @@ public class CPPASTForStatement extends CPPASTNode implements IASTForStatement,
|
|||
other.setParent( child.getParent() );
|
||||
initialExpression = (IASTExpression) other;
|
||||
}
|
||||
if( initDeclaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
initDeclaration = (IASTDeclaration) other;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,12 @@ public class CPPASTIfStatement extends CPPASTNode implements ICPPASTIfStatement,
|
|||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
elseClause = (IASTStatement) other;
|
||||
}
|
||||
if( condDecl == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
condDecl = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
|
||||
public IASTDeclaration getConditionDeclaration() {
|
||||
|
|
|
@ -12,14 +12,16 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTLinkageSpecification extends CPPASTNode implements
|
||||
ICPPASTLinkageSpecification {
|
||||
ICPPASTLinkageSpecification, IASTAmbiguityParent {
|
||||
|
||||
private String literal;
|
||||
/* (non-Javadoc)
|
||||
|
@ -68,4 +70,17 @@ public class CPPASTLinkageSpecification extends CPPASTNode implements
|
|||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declarations == null ) return;
|
||||
for( int i = 0; i < declarations.length; ++i )
|
||||
{
|
||||
if( declarations[i] == null ) continue;
|
||||
if( declarations[i] == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declarations[i] = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,17 +14,19 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTNamespaceDefinition extends CPPASTNode implements
|
||||
ICPPASTNamespaceDefinition {
|
||||
ICPPASTNamespaceDefinition, IASTAmbiguityParent {
|
||||
|
||||
private IASTName name;
|
||||
|
||||
|
@ -95,4 +97,17 @@ public class CPPASTNamespaceDefinition extends CPPASTNode implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declarations == null ) return;
|
||||
for( int i = 0; i < declarations.length; ++i )
|
||||
{
|
||||
if( declarations[i] == null ) continue;
|
||||
if( declarations[i] == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declarations[i] = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,18 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTTemplateDeclaration extends CPPASTNode implements
|
||||
ICPPASTTemplateDeclaration {
|
||||
ICPPASTTemplateDeclaration, IASTAmbiguityParent {
|
||||
|
||||
private boolean exported;
|
||||
private IASTDeclaration declaration;
|
||||
|
@ -97,4 +99,13 @@ public class CPPASTTemplateDeclaration extends CPPASTNode implements
|
|||
templateScope = new CPPTemplateScope( this );
|
||||
return templateScope;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declaration = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,18 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTTemplateSpecialization extends CPPASTNode implements
|
||||
ICPPASTTemplateSpecialization, ICPPASTTemplateDeclaration {
|
||||
ICPPASTTemplateSpecialization, ICPPASTTemplateDeclaration, IASTAmbiguityParent {
|
||||
|
||||
private IASTDeclaration declaration;
|
||||
private ICPPTemplateScope templateScope;
|
||||
|
@ -87,4 +89,13 @@ public class CPPASTTemplateSpecialization extends CPPASTNode implements
|
|||
templateScope = new CPPTemplateScope( this );
|
||||
return templateScope;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( declaration == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
declaration = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
|||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
|
||||
|
@ -56,7 +57,7 @@ import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeExce
|
|||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTTranslationUnit extends CPPASTNode implements
|
||||
ICPPASTTranslationUnit, IRequiresLocationInformation {
|
||||
ICPPASTTranslationUnit, IRequiresLocationInformation, IASTAmbiguityParent {
|
||||
private IASTDeclaration[] decls = new IASTDeclaration[32];
|
||||
|
||||
private ICPPNamespace binding = null;
|
||||
|
@ -487,4 +488,17 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
|
|||
return resolver.getContainingFilename( offset );
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
if( decls == null ) return;
|
||||
for( int i = 0; i < decls.length; ++i )
|
||||
{
|
||||
if( decls[i] == null ) continue;
|
||||
if( decls[i] == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
decls[i] = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,6 +96,12 @@ public class CPPASTWhileStatement extends CPPASTNode implements
|
|||
other.setParent( child.getParent() );
|
||||
condition = (IASTExpression) other;
|
||||
}
|
||||
if( condition2 == child )
|
||||
{
|
||||
other.setParent( child.getParent() );
|
||||
other.setPropertyInParent( child.getPropertyInParent() );
|
||||
condition2 = (IASTDeclaration) other;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
||||
import org.eclipse.cdt.internal.core.parser.SimpleDeclarationStrategy;
|
||||
|
@ -171,6 +172,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
private ScopeStack templateIdScopes = new ScopeStack();
|
||||
|
||||
private int templateCount = 0;
|
||||
|
||||
protected CPPASTTranslationUnit translationUnit;
|
||||
|
||||
private static class ScopeStack {
|
||||
|
@ -943,8 +946,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
try {
|
||||
declSpecifier = declSpecifierSeq(true, true);
|
||||
if (LT(1) != IToken.tEOC)
|
||||
declarator = declarator(
|
||||
SimpleDeclarationStrategy.TRY_FUNCTION,
|
||||
declarator = declarator(SimpleDeclarationStrategy.TRY_FUNCTION,
|
||||
forNewExpression);
|
||||
} catch (BacktrackException bt) {
|
||||
backup(mark);
|
||||
|
@ -2123,6 +2125,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IToken firstToken = null;
|
||||
boolean exported = false;
|
||||
boolean encounteredExtraMod = false;
|
||||
++templateCount;
|
||||
if (LT(1) == IToken.t_export) {
|
||||
exported = true;
|
||||
firstToken = consume(IToken.t_export);
|
||||
|
@ -2166,14 +2169,18 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
templateInstantiation = temp;
|
||||
} else
|
||||
templateInstantiation = createTemplateInstantiation();
|
||||
IASTDeclaration d = declaration();
|
||||
((ASTNode) templateInstantiation).setOffsetAndLength(firstToken
|
||||
.getOffset(), calculateEndOffset(d)
|
||||
- firstToken.getOffset());
|
||||
templateInstantiation.setDeclaration(d);
|
||||
d.setParent(templateInstantiation);
|
||||
d
|
||||
.setPropertyInParent(ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION);
|
||||
try {
|
||||
IASTDeclaration d = declaration();
|
||||
((ASTNode) templateInstantiation).setOffsetAndLength(firstToken
|
||||
.getOffset(), calculateEndOffset(d)
|
||||
- firstToken.getOffset());
|
||||
templateInstantiation.setDeclaration(d);
|
||||
d.setParent(templateInstantiation);
|
||||
d
|
||||
.setPropertyInParent(ICPPASTExplicitTemplateInstantiation.OWNED_DECLARATION);
|
||||
} finally {
|
||||
--templateCount;
|
||||
}
|
||||
return templateInstantiation;
|
||||
}
|
||||
consume(IToken.tLT);
|
||||
|
@ -2182,34 +2189,46 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
consume(IToken.tGT);
|
||||
|
||||
ICPPASTTemplateSpecialization templateSpecialization = createTemplateSpecialization();
|
||||
IASTDeclaration d = declaration();
|
||||
((ASTNode) templateSpecialization).setOffsetAndLength(firstToken
|
||||
.getOffset(), calculateEndOffset(d)
|
||||
- firstToken.getOffset());
|
||||
templateSpecialization.setDeclaration(d);
|
||||
d.setParent(templateSpecialization);
|
||||
d
|
||||
.setPropertyInParent(ICPPASTTemplateSpecialization.OWNED_DECLARATION);
|
||||
try {
|
||||
IASTDeclaration d = declaration();
|
||||
((ASTNode) templateSpecialization).setOffsetAndLength(
|
||||
firstToken.getOffset(), calculateEndOffset(d)
|
||||
- firstToken.getOffset());
|
||||
templateSpecialization.setDeclaration(d);
|
||||
d.setParent(templateSpecialization);
|
||||
d
|
||||
.setPropertyInParent(ICPPASTTemplateSpecialization.OWNED_DECLARATION);
|
||||
} finally {
|
||||
--templateCount;
|
||||
}
|
||||
|
||||
return templateSpecialization;
|
||||
}
|
||||
|
||||
try {
|
||||
List parms = templateParameterList();
|
||||
consume(IToken.tGT);
|
||||
IASTDeclaration d = declaration();
|
||||
ICPPASTTemplateDeclaration templateDecl = createTemplateDeclaration();
|
||||
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(),
|
||||
calculateEndOffset(d) - firstToken.getOffset());
|
||||
templateDecl.setExported(exported);
|
||||
templateDecl.setDeclaration(d);
|
||||
d.setParent(templateDecl);
|
||||
d.setPropertyInParent(ICPPASTTemplateDeclaration.OWNED_DECLARATION);
|
||||
for (int i = 0; i < parms.size(); ++i) {
|
||||
ICPPASTTemplateParameter parm = (ICPPASTTemplateParameter) parms
|
||||
.get(i);
|
||||
templateDecl.addTemplateParamter(parm);
|
||||
parm.setParent(templateDecl);
|
||||
parm.setPropertyInParent(ICPPASTTemplateDeclaration.PARAMETER);
|
||||
try
|
||||
{
|
||||
IASTDeclaration d = declaration();
|
||||
((ASTNode) templateDecl).setOffsetAndLength(firstToken.getOffset(),
|
||||
calculateEndOffset(d) - firstToken.getOffset());
|
||||
templateDecl.setExported(exported);
|
||||
templateDecl.setDeclaration(d);
|
||||
d.setParent(templateDecl);
|
||||
d.setPropertyInParent(ICPPASTTemplateDeclaration.OWNED_DECLARATION);
|
||||
for (int i = 0; i < parms.size(); ++i) {
|
||||
ICPPASTTemplateParameter parm = (ICPPASTTemplateParameter) parms
|
||||
.get(i);
|
||||
templateDecl.addTemplateParamter(parm);
|
||||
parm.setParent(templateDecl);
|
||||
parm.setPropertyInParent(ICPPASTTemplateDeclaration.PARAMETER);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
--templateCount;
|
||||
}
|
||||
|
||||
return templateDecl;
|
||||
|
@ -2426,24 +2445,93 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
protected IASTDeclaration simpleDeclarationStrategyUnion()
|
||||
throws EndOfFileException, BacktrackException {
|
||||
simpleDeclarationMark = mark();
|
||||
IToken simpleDeclarationMark = mark();
|
||||
IASTDeclaration d1 = null, d2 = null;
|
||||
IToken after = null;
|
||||
try {
|
||||
IASTDeclaration d = simpleDeclaration(
|
||||
SimpleDeclarationStrategy.TRY_FUNCTION, false);
|
||||
throwAwayMarksForInitializerClause();
|
||||
return d;
|
||||
d1 = simpleDeclaration(SimpleDeclarationStrategy.TRY_FUNCTION,
|
||||
false);
|
||||
try {
|
||||
after = LA(1);
|
||||
} catch (EndOfFileException eof) {
|
||||
after = null;
|
||||
}
|
||||
} catch (BacktrackException bt) {
|
||||
if (simpleDeclarationMark == null)
|
||||
throwBacktrack(bt);
|
||||
// did not work
|
||||
backup(simpleDeclarationMark);
|
||||
|
||||
IASTDeclaration d = simpleDeclaration(
|
||||
SimpleDeclarationStrategy.TRY_VARIABLE, false);
|
||||
throwAwayMarksForInitializerClause();
|
||||
return d;
|
||||
|
||||
d1 = null;
|
||||
}
|
||||
if (d1 != null) {
|
||||
if( templateCount != 0 )
|
||||
return d1;
|
||||
if (d1 instanceof IASTFunctionDefinition)
|
||||
return d1;
|
||||
if (d1 instanceof IASTSimpleDeclaration) {
|
||||
IASTSimpleDeclaration sd = (IASTSimpleDeclaration) d1;
|
||||
if( sd.getDeclSpecifier() instanceof ICPPASTDeclSpecifier &&
|
||||
((ICPPASTDeclSpecifier)sd.getDeclSpecifier()).isFriend() )
|
||||
return d1;
|
||||
if (sd.getDeclarators().length != 1)
|
||||
return d1;
|
||||
if (sd.getDeclarators()[0] instanceof IASTStandardFunctionDeclarator) {
|
||||
IASTStandardFunctionDeclarator fd = (IASTStandardFunctionDeclarator) sd
|
||||
.getDeclarators()[0];
|
||||
if (sd.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef)
|
||||
return d1;
|
||||
IASTParameterDeclaration[] parms = fd.getParameters();
|
||||
for (int i = 0; i < parms.length; ++i) {
|
||||
if (!(parms[i].getDeclSpecifier() instanceof IASTNamedTypeSpecifier))
|
||||
return d1;
|
||||
if (((ASTNode) parms[i].getDeclarator().getName())
|
||||
.getLength() > 0)
|
||||
return d1;
|
||||
IASTDeclarator d = parms[i].getDeclarator();
|
||||
while (d.getNestedDeclarator() != null)
|
||||
d = d.getNestedDeclarator();
|
||||
if (((ASTNode) d.getName()).getLength() > 0)
|
||||
return d1;
|
||||
}
|
||||
} else
|
||||
return d1;
|
||||
}
|
||||
}
|
||||
|
||||
// did not work
|
||||
backup(simpleDeclarationMark);
|
||||
|
||||
try {
|
||||
d2 = simpleDeclaration(SimpleDeclarationStrategy.TRY_VARIABLE,
|
||||
false);
|
||||
if (after != null && after != LA(1)) {
|
||||
backup(after);
|
||||
return d1;
|
||||
}
|
||||
} catch (BacktrackException be) {
|
||||
d2 = null;
|
||||
if (d1 == null)
|
||||
throwBacktrack(be);
|
||||
}
|
||||
|
||||
if (d2 == null && d1 != null) {
|
||||
backup(after);
|
||||
return d1;
|
||||
}
|
||||
|
||||
if (d1 == null && d2 != null)
|
||||
return d2;
|
||||
|
||||
IASTAmbiguousDeclaration result = createAmbiguousDeclaration();
|
||||
((CPPASTNode) result).setOffsetAndLength((ASTNode) d1);
|
||||
result.addDeclaration(d1);
|
||||
d1.setParent(result);
|
||||
d1.setPropertyInParent(IASTAmbiguousDeclaration.SUBDECLARATION);
|
||||
result.addDeclaration(d2);
|
||||
d2.setParent(result);
|
||||
d2.setPropertyInParent(IASTAmbiguousDeclaration.SUBDECLARATION);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
protected IASTAmbiguousDeclaration createAmbiguousDeclaration() {
|
||||
return new CPPASTAmbiguousDeclaration();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3475,7 +3563,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
if (LT(1) == IToken.tASSIGN) {
|
||||
consume(IToken.tASSIGN);
|
||||
throwAwayMarksForInitializerClause();
|
||||
try {
|
||||
return initializerClause();
|
||||
} catch (EndOfFileException eof) {
|
||||
|
@ -4996,7 +5083,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
IASTNode condition = null;
|
||||
try {
|
||||
condition = cppStyleCondition(); // TODO should be while
|
||||
// condition
|
||||
// condition
|
||||
if (LT(1) == IToken.tEOC) {
|
||||
// Completing in the condition
|
||||
ICPPASTIfStatement new_if = createIfStatement();
|
||||
|
@ -5040,15 +5127,15 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
ICPPASTIfStatement new_if_statement = createIfStatement();
|
||||
((ASTNode) new_if_statement).setOffset(so);
|
||||
if (condition != null && condition instanceof IASTExpression) // shouldn't
|
||||
// be
|
||||
// possible
|
||||
// but
|
||||
// failure
|
||||
// in
|
||||
// condition()
|
||||
// makes
|
||||
// it
|
||||
// so
|
||||
// be
|
||||
// possible
|
||||
// but
|
||||
// failure
|
||||
// in
|
||||
// condition()
|
||||
// makes
|
||||
// it
|
||||
// so
|
||||
{
|
||||
new_if_statement
|
||||
.setConditionExpression((IASTExpression) condition);
|
||||
|
|
Loading…
Add table
Reference in a new issue