mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixes semantics for functions with nested or nesting declarators, bug 216609.
This commit is contained in:
parent
e8b7f79fc4
commit
305143a8d0
23 changed files with 318 additions and 282 deletions
|
@ -1013,8 +1013,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
|
|
||||||
IASTFunctionDefinition def = (IASTFunctionDefinition) tu
|
IASTFunctionDefinition def = (IASTFunctionDefinition) tu
|
||||||
.getDeclarations()[0];
|
.getDeclarations()[0];
|
||||||
IFunction f = (IFunction) def.getDeclarator().getNestedDeclarator()
|
IFunction f = (IFunction) def.getDeclarator().getName().resolveBinding();
|
||||||
.getName().resolveBinding();
|
|
||||||
|
|
||||||
IFunctionType ft = f.getType();
|
IFunctionType ft = f.getType();
|
||||||
assertTrue(ft.getReturnType() instanceof IPointerType);
|
assertTrue(ft.getReturnType() instanceof IPointerType);
|
||||||
|
|
|
@ -2086,10 +2086,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
IASTTranslationUnit tu = parse(
|
IASTTranslationUnit tu = parse(
|
||||||
"void ( * f( int ) )(){}", ParserLanguage.C); //$NON-NLS-1$
|
"void ( * f( int ) )(){}", ParserLanguage.C); //$NON-NLS-1$
|
||||||
|
|
||||||
IASTFunctionDefinition def = (IASTFunctionDefinition) tu
|
IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||||
.getDeclarations()[0];
|
final IASTName fname = def.getDeclarator().getName();
|
||||||
IFunction f = (IFunction) def.getDeclarator().getNestedDeclarator()
|
IFunction f = (IFunction) fname.resolveBinding();
|
||||||
.getName().resolveBinding();
|
|
||||||
|
|
||||||
IFunctionType ft = f.getType();
|
IFunctionType ft = f.getType();
|
||||||
assertTrue(ft.getReturnType() instanceof IPointerType);
|
assertTrue(ft.getReturnType() instanceof IPointerType);
|
||||||
|
@ -2097,11 +2096,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals(ft.getParameterTypes().length, 1);
|
assertEquals(ft.getParameterTypes().length, 1);
|
||||||
|
|
||||||
// test tu.getDeclarationsInAST(IBinding)
|
// test tu.getDeclarationsInAST(IBinding)
|
||||||
IASTName[] decls = tu.getDeclarationsInAST(def.getDeclarator()
|
IASTName[] decls = tu.getDeclarationsInAST(f);
|
||||||
.getNestedDeclarator().getName().resolveBinding());
|
|
||||||
assertEquals(decls.length, 1);
|
assertEquals(decls.length, 1);
|
||||||
assertEquals(decls[0], def.getDeclarator().getNestedDeclarator()
|
assertEquals(decls[0], fname);
|
||||||
.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test C99: 6.7.5.3-7 A declaration of a parameter as ''array of type''
|
// test C99: 6.7.5.3-7 A declaration of a parameter as ''array of type''
|
||||||
|
@ -2173,11 +2170,9 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
assertEquals(decls.length, 1);
|
assertEquals(decls.length, 1);
|
||||||
assertEquals(decls[0], def2.getDeclarator().getName());
|
assertEquals(decls[0], def2.getDeclarator().getName());
|
||||||
|
|
||||||
decls = tu.getDeclarationsInAST(def3.getDeclarator().getNestedDeclarator()
|
decls = tu.getDeclarationsInAST(def3.getDeclarator().getName().resolveBinding());
|
||||||
.getName().resolveBinding());
|
|
||||||
assertEquals(decls.length, 1);
|
assertEquals(decls.length, 1);
|
||||||
assertEquals(decls[0], def3.getDeclarator().getNestedDeclarator()
|
assertEquals(decls[0], def3.getDeclarator().getName());
|
||||||
.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// any parameter to type function returning T is adjusted to be pointer to
|
// any parameter to type function returning T is adjusted to be pointer to
|
||||||
|
@ -4859,8 +4854,8 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// int (*f1(int par))[5] {};
|
// int (*f1(int par))[5] {};
|
||||||
public void _testFunctionReturningPtrToArray_Bug216609() throws Exception {
|
// int (*f1 (int par))[5];
|
||||||
// works for plain-c, see testcase below.
|
public void testFunctionReturningPtrToArray_Bug216609() throws Exception {
|
||||||
final String comment= getAboveComment();
|
final String comment= getAboveComment();
|
||||||
final boolean[] isCpps= {false, true};
|
final boolean[] isCpps= {false, true};
|
||||||
for (boolean isCpp : isCpps) {
|
for (boolean isCpp : isCpps) {
|
||||||
|
@ -4868,6 +4863,68 @@ public class AST2Tests extends AST2BaseTest {
|
||||||
|
|
||||||
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
||||||
isTypeEqual(f.getType(), "int [] * (int)");
|
isTypeEqual(f.getType(), "int [] * (int)");
|
||||||
|
|
||||||
|
f= ba.assertNonProblem("f1 ", 2, IFunction.class);
|
||||||
|
isTypeEqual(f.getType(), "int [] * (int)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// void f1(){}
|
||||||
|
// void (f2)(){}
|
||||||
|
// void (f3()){}
|
||||||
|
// void ((f4)()){}
|
||||||
|
// void f1();
|
||||||
|
// void (f2)();
|
||||||
|
// void (f3());
|
||||||
|
// void ((f4)());
|
||||||
|
public void testNestedFunctionDeclarators() throws Exception {
|
||||||
|
final String comment= getAboveComment();
|
||||||
|
final boolean[] isCpps= {false, true};
|
||||||
|
for (ParserLanguage lang: ParserLanguage.values()) {
|
||||||
|
IASTTranslationUnit tu= parseAndCheckBindings(comment, lang);
|
||||||
|
IASTFunctionDefinition fdef= getDeclaration(tu, 0);
|
||||||
|
IASTDeclarator dtor= fdef.getDeclarator();
|
||||||
|
assertNull(dtor.getNestedDeclarator());
|
||||||
|
assertInstance(dtor.getParent(), IASTFunctionDefinition.class);
|
||||||
|
assertInstance(dtor.getName().resolveBinding(), IFunction.class);
|
||||||
|
|
||||||
|
fdef= getDeclaration(tu, 1);
|
||||||
|
dtor= fdef.getDeclarator();
|
||||||
|
assertNotNull(dtor.getNestedDeclarator());
|
||||||
|
assertInstance(dtor.getParent(), IASTFunctionDefinition.class);
|
||||||
|
assertInstance(dtor.getNestedDeclarator().getName().resolveBinding(), IFunction.class);
|
||||||
|
|
||||||
|
fdef= getDeclaration(tu, 2);
|
||||||
|
dtor= fdef.getDeclarator();
|
||||||
|
assertNull(dtor.getNestedDeclarator());
|
||||||
|
assertInstance(dtor.getParent().getParent(), IASTFunctionDefinition.class);
|
||||||
|
assertInstance(dtor.getName().resolveBinding(), IFunction.class);
|
||||||
|
|
||||||
|
fdef= getDeclaration(tu, 3);
|
||||||
|
dtor= fdef.getDeclarator();
|
||||||
|
assertNotNull(dtor.getNestedDeclarator());
|
||||||
|
assertInstance(dtor.getParent().getParent(), IASTFunctionDefinition.class);
|
||||||
|
assertInstance(dtor.getNestedDeclarator().getName().resolveBinding(), IFunction.class);
|
||||||
|
|
||||||
|
IASTSimpleDeclaration sdef= getDeclaration(tu, 4);
|
||||||
|
IBinding binding= sdef.getDeclarators()[0].getName().resolveBinding();
|
||||||
|
assertInstance(binding, IFunction.class);
|
||||||
|
assertEquals(2, tu.getDeclarationsInAST(binding).length);
|
||||||
|
|
||||||
|
sdef= getDeclaration(tu, 5);
|
||||||
|
binding= sdef.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding();
|
||||||
|
assertInstance(binding, IFunction.class);
|
||||||
|
assertEquals(2, tu.getDeclarationsInAST(binding).length);
|
||||||
|
|
||||||
|
sdef= getDeclaration(tu, 6);
|
||||||
|
binding= sdef.getDeclarators()[0].getName().resolveBinding();
|
||||||
|
assertInstance(binding, IFunction.class);
|
||||||
|
assertEquals(2, tu.getDeclarationsInAST(binding).length);
|
||||||
|
|
||||||
|
sdef= getDeclaration(tu, 7);
|
||||||
|
binding= sdef.getDeclarators()[0].getNestedDeclarator().getName().resolveBinding();
|
||||||
|
assertInstance(binding, IFunction.class);
|
||||||
|
assertEquals(2, tu.getDeclarationsInAST(binding).length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,26 @@ public interface IASTFunctionDefinition extends IASTDeclaration {
|
||||||
public void setDeclSpecifier(IASTDeclSpecifier declSpec);
|
public void setDeclSpecifier(IASTDeclSpecifier declSpec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the declarator for the function.
|
* Get the function declarator of the function.
|
||||||
*
|
* Note, that the function declarator may contain nested declarators and may also nest within
|
||||||
|
* another declarator. In the latter case this function definition is always the parent of the
|
||||||
|
* outermost declarator.
|
||||||
|
* <pre>
|
||||||
|
* void (f)(int a); // has nested declarator
|
||||||
|
* void (f(int a)); // is nested in another declarator
|
||||||
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public IASTFunctionDeclarator getDeclarator();
|
public IASTFunctionDeclarator getDeclarator();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the declarator for the function.
|
* Set the declarator for the function.
|
||||||
*
|
* Note, that the function declarator may contain nested declarators and may also nest within
|
||||||
|
* another declarator. In the latter case this function definition is set to be the parent of the
|
||||||
|
* outermost declarator.
|
||||||
|
* <pre>
|
||||||
|
* void (f)(int a); // has nested declarator
|
||||||
|
* void (f(int a)); // is nested in another declarator
|
||||||
|
* </pre>
|
||||||
* @param declarator
|
* @param declarator
|
||||||
*/
|
*/
|
||||||
public void setDeclarator(IASTFunctionDeclarator declarator);
|
public void setDeclarator(IASTFunctionDeclarator declarator);
|
||||||
|
@ -86,5 +98,4 @@ public interface IASTFunctionDefinition extends IASTDeclaration {
|
||||||
* @return <code>IScope</code> representing function body.
|
* @return <code>IScope</code> representing function body.
|
||||||
*/
|
*/
|
||||||
public IScope getScope();
|
public IScope getScope();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
@ -61,8 +63,9 @@ public class CASTFunctionDefinition extends CASTNode implements
|
||||||
public void setDeclarator(IASTFunctionDeclarator declarator) {
|
public void setDeclarator(IASTFunctionDeclarator declarator) {
|
||||||
this.declarator = declarator;
|
this.declarator = declarator;
|
||||||
if (declarator != null) {
|
if (declarator != null) {
|
||||||
declarator.setParent(this);
|
IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(declarator);
|
||||||
declarator.setPropertyInParent(DECLARATOR);
|
outerDtor.setParent(this);
|
||||||
|
outerDtor.setPropertyInParent(DECLARATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +98,8 @@ public class CASTFunctionDefinition extends CASTNode implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false;
|
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false;
|
||||||
if( declarator != null ) if( !declarator.accept( action ) ) return false;
|
final IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(declarator);
|
||||||
|
if( outerDtor != null ) if( !outerDtor.accept( action ) ) return false;
|
||||||
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
|
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
|
||||||
|
|
||||||
if( action.shouldVisitDeclarations ){
|
if( action.shouldVisitDeclarations ){
|
||||||
|
@ -116,6 +120,4 @@ public class CASTFunctionDefinition extends CASTNode implements
|
||||||
bodyStatement = (IASTStatement) other;
|
bodyStatement = (IASTStatement) other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1040,7 +1040,7 @@ public class CVisitor {
|
||||||
if (node instanceof IASTFunctionDefinition) {
|
if (node instanceof IASTFunctionDefinition) {
|
||||||
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node;
|
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node;
|
||||||
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
|
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
|
||||||
IASTName name = functionDeclartor.getName();
|
IASTName name = findInnermostDeclarator(functionDeclartor).getName();
|
||||||
IASTNode blockItem = getContainingBlockItem(node);
|
IASTNode blockItem = getContainingBlockItem(node);
|
||||||
try {
|
try {
|
||||||
return (IBinding) findBinding(blockItem, name, bits);
|
return (IBinding) findBinding(blockItem, name, bits);
|
||||||
|
@ -1211,7 +1211,7 @@ public class CVisitor {
|
||||||
scope = getContainingScope((IASTStatement)parent);
|
scope = getContainingScope((IASTStatement)parent);
|
||||||
} else if (parent instanceof IASTFunctionDefinition) {
|
} else if (parent instanceof IASTFunctionDefinition) {
|
||||||
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
|
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
|
||||||
IBinding function = fnDeclarator.getName().resolveBinding();
|
IBinding function = CVisitor.findInnermostDeclarator(fnDeclarator).getName().resolveBinding();
|
||||||
try {
|
try {
|
||||||
if (function instanceof IFunction) {
|
if (function instanceof IFunction) {
|
||||||
scope = ((IFunction)function).getFunctionScope();
|
scope = ((IFunction)function).getFunctionScope();
|
||||||
|
@ -1611,9 +1611,7 @@ public class CVisitor {
|
||||||
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
|
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
|
||||||
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
||||||
for (IASTDeclarator declarator : declarators) {
|
for (IASTDeclarator declarator : declarators) {
|
||||||
while (declarator.getNestedDeclarator() != null) {
|
declarator= CVisitor.findInnermostDeclarator(declarator);
|
||||||
declarator = declarator.getNestedDeclarator();
|
|
||||||
}
|
|
||||||
tempName = declarator.getName();
|
tempName = declarator.getName();
|
||||||
if (scope != null)
|
if (scope != null)
|
||||||
ASTInternal.addName(scope, tempName);
|
ASTInternal.addName(scope, tempName);
|
||||||
|
@ -1633,7 +1631,7 @@ public class CVisitor {
|
||||||
} else if (!typesOnly && declaration instanceof IASTFunctionDefinition) {
|
} else if (!typesOnly && declaration instanceof IASTFunctionDefinition) {
|
||||||
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
|
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
|
||||||
|
|
||||||
IASTDeclarator dtor = functionDef.getDeclarator();
|
IASTDeclarator dtor = CVisitor.findInnermostDeclarator(functionDef.getDeclarator());
|
||||||
tempName = dtor.getName();
|
tempName = dtor.getName();
|
||||||
if (scope != null)
|
if (scope != null)
|
||||||
ASTInternal.addName(scope, tempName);
|
ASTInternal.addName(scope, tempName);
|
||||||
|
@ -1692,7 +1690,7 @@ public class CVisitor {
|
||||||
|
|
||||||
if (node instanceof IASTFunctionDefinition && decl instanceof IASTFunctionDeclarator) {
|
if (node instanceof IASTFunctionDefinition && decl instanceof IASTFunctionDeclarator) {
|
||||||
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) node).getDeclarator();
|
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) node).getDeclarator();
|
||||||
IASTName name = dtor.getName();
|
IASTName name = CVisitor.findInnermostDeclarator(dtor).getName();
|
||||||
if (name.toString().equals(declName)) {
|
if (name.toString().equals(declName)) {
|
||||||
return dtor;
|
return dtor;
|
||||||
}
|
}
|
||||||
|
@ -2179,14 +2177,13 @@ public class CVisitor {
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
|
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
|
||||||
while(true) {
|
IASTDeclarator outermost= null;
|
||||||
IASTNode parent= declarator.getParent();
|
IASTNode candidate= declarator;
|
||||||
if (parent instanceof IASTDeclarator) {
|
while(candidate instanceof IASTDeclarator) {
|
||||||
declarator= (IASTDeclarator) parent;
|
outermost= (IASTDeclarator) candidate;
|
||||||
} else {
|
candidate= outermost.getParent();
|
||||||
return declarator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return outermost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -432,15 +432,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (declarators.length != 1)
|
if (declarators.length != 1)
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset());
|
throwBacktrack(firstOffset, LA(1).getEndOffset());
|
||||||
|
|
||||||
// IASTDeclarator declarator= CVisitor.findTypeRelevantDeclarator(declarators[0]); // mstodo
|
final IASTDeclarator outerDtor= declarators[0];
|
||||||
|
final IASTDeclarator fdtor= CVisitor.findTypeRelevantDeclarator(outerDtor);
|
||||||
IASTDeclarator declarator = declarators[0];
|
if (fdtor instanceof IASTFunctionDeclarator == false)
|
||||||
if (!(declarator instanceof IASTFunctionDeclarator))
|
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset());
|
|
||||||
|
|
||||||
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
|
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
|
||||||
funcDefinition.setDeclSpecifier(declSpec);
|
funcDefinition.setDeclSpecifier(declSpec);
|
||||||
funcDefinition.setDeclarator((IASTFunctionDeclarator) declarator);
|
funcDefinition.setDeclarator((IASTFunctionDeclarator) fdtor);
|
||||||
|
|
||||||
IASTStatement s= handleFunctionBody();
|
IASTStatement s= handleFunctionBody();
|
||||||
funcDefinition.setBody(s);
|
funcDefinition.setBody(s);
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
@ -19,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jcamelon
|
* @author jcamelon
|
||||||
|
@ -59,8 +62,9 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
|
||||||
public void setDeclarator(IASTFunctionDeclarator declarator) {
|
public void setDeclarator(IASTFunctionDeclarator declarator) {
|
||||||
this.declarator = declarator;
|
this.declarator = declarator;
|
||||||
if (declarator != null) {
|
if (declarator != null) {
|
||||||
declarator.setParent(this);
|
IASTDeclarator outerDtor= CPPVisitor.findOutermostDeclarator(declarator);
|
||||||
declarator.setPropertyInParent(DECLARATOR);
|
outerDtor.setParent(this);
|
||||||
|
outerDtor.setPropertyInParent(DECLARATOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +95,8 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false;
|
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false;
|
||||||
if( declarator != null ) if( !declarator.accept( action ) ) return false;
|
final IASTDeclarator outerDtor= CPPVisitor.findOutermostDeclarator(declarator);
|
||||||
|
if( outerDtor != null ) if( !outerDtor.accept( action ) ) return false;
|
||||||
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
|
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
|
||||||
|
|
||||||
if( action.shouldVisitDeclarations ){
|
if( action.shouldVisitDeclarations ){
|
||||||
|
@ -112,5 +117,4 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
|
||||||
bodyStatement = (IASTStatement) other;
|
bodyStatement = (IASTStatement) other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,11 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.IName;
|
import org.eclipse.cdt.core.dom.IName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -32,8 +34,13 @@ public class CPPBlockScope extends CPPNamespaceScope implements ICPPBlockScope {
|
||||||
@Override
|
@Override
|
||||||
public IName getScopeName(){
|
public IName getScopeName(){
|
||||||
IASTNode node = getPhysicalNode();
|
IASTNode node = getPhysicalNode();
|
||||||
if( node instanceof IASTCompoundStatement && node.getParent() instanceof IASTFunctionDefinition ){
|
if (node instanceof IASTCompoundStatement) {
|
||||||
return ((IASTFunctionDefinition)node.getParent()).getDeclarator().getName();
|
final IASTNode parent= node.getParent();
|
||||||
|
if (parent instanceof IASTFunctionDefinition) {
|
||||||
|
IASTDeclarator dtor= ((IASTFunctionDefinition)parent).getDeclarator();
|
||||||
|
dtor = CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
|
return dtor.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,12 +463,12 @@ class ImplicitsAnalysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean nameEquals= false;
|
boolean nameEquals= false;
|
||||||
|
char[] dtorname= CPPVisitor.findInnermostDeclarator(dcltor).getName().toCharArray();
|
||||||
if (constructor) {
|
if (constructor) {
|
||||||
nameEquals= CharArrayUtils.equals(dcltor.getName().toCharArray(), name);
|
nameEquals= CharArrayUtils.equals(dtorname, name);
|
||||||
} else {
|
} else {
|
||||||
char[] cname= dcltor.getName().toCharArray();
|
if (dtorname.length > 0 && dtorname[0] == '~') {
|
||||||
if (cname.length > 0 && cname[0] == '~') {
|
nameEquals= CharArrayUtils.equals(dtorname, 1, name.length, name);
|
||||||
nameEquals= CharArrayUtils.equals(cname, 1, name.length, name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,10 +493,12 @@ class ImplicitsAnalysis {
|
||||||
} else if (member instanceof IASTFunctionDefinition) {
|
} else if (member instanceof IASTFunctionDefinition) {
|
||||||
dcltor = ((IASTFunctionDefinition)member).getDeclarator();
|
dcltor = ((IASTFunctionDefinition)member).getDeclarator();
|
||||||
}
|
}
|
||||||
if (!(dcltor instanceof ICPPASTFunctionDeclarator) ||
|
if (dcltor instanceof ICPPASTFunctionDeclarator == false)
|
||||||
!CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray())) {
|
continue;
|
||||||
|
|
||||||
|
final char[] nchars= CPPVisitor.findInnermostDeclarator(dcltor).getName().toCharArray();
|
||||||
|
if (!CharArrayUtils.equals(nchars, OverloadableOperator.ASSIGN.toCharArray()))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator)dcltor).getParameters();
|
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator)dcltor).getParameters();
|
||||||
if (ps.length != 1 || !paramHasTypeReferenceToTheAssociatedClassType(ps[0], null))
|
if (ps.length != 1 || !paramHasTypeReferenceToTheAssociatedClassType(ps[0], null))
|
||||||
|
|
|
@ -182,7 +182,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
||||||
}
|
}
|
||||||
} else if( decl instanceof IASTFunctionDefinition ){
|
} else if( decl instanceof IASTFunctionDefinition ){
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||||
dtor = CPPVisitor.getMostNestedDeclarator( dtor );
|
dtor = CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
binding = dtor.getName().resolveBinding();
|
binding = dtor.getName().resolveBinding();
|
||||||
if( binding instanceof ICPPMethod ){
|
if( binding instanceof ICPPMethod ){
|
||||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||||
|
@ -225,10 +225,12 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||||
for (IASTDeclarator dtor : dtors) {
|
for (IASTDeclarator dtor : dtors) {
|
||||||
if( dtor == null ) break;
|
if( dtor == null ) break;
|
||||||
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
ASTInternal.addName(scope, dtor.getName() );
|
ASTInternal.addName(scope, dtor.getName() );
|
||||||
}
|
}
|
||||||
} else if( decl instanceof IASTFunctionDefinition ){
|
} else if( decl instanceof IASTFunctionDefinition ){
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||||
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
ASTInternal.addName(scope, dtor.getName() );
|
ASTInternal.addName(scope, dtor.getName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
|
|
||||||
public CPPFunction(ICPPASTFunctionDeclarator declarator) {
|
public CPPFunction(ICPPASTFunctionDeclarator declarator) {
|
||||||
if (declarator != null) {
|
if (declarator != null) {
|
||||||
IASTNode parent = declarator.getParent();
|
IASTNode parent = CPPVisitor.findOutermostDeclarator(declarator).getParent();
|
||||||
if (parent instanceof IASTFunctionDefinition)
|
if (parent instanceof IASTFunctionDefinition)
|
||||||
definition = declarator;
|
definition = declarator;
|
||||||
else
|
else
|
||||||
|
@ -160,21 +160,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDefinition(IASTNode node) {
|
public void addDefinition(IASTNode node) {
|
||||||
if (node instanceof IASTName)
|
ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
|
||||||
node = node.getParent();
|
if (dtor != null) {
|
||||||
if (!(node instanceof ICPPASTFunctionDeclarator))
|
|
||||||
return;
|
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
|
||||||
updateParameterBindings(dtor);
|
updateParameterBindings(dtor);
|
||||||
definition = dtor;
|
definition = dtor;
|
||||||
}
|
}
|
||||||
public void addDeclaration(IASTNode node) {
|
}
|
||||||
if (node instanceof IASTName)
|
|
||||||
node = node.getParent();
|
|
||||||
if (!(node instanceof ICPPASTFunctionDeclarator))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
public void addDeclaration(IASTNode node) {
|
||||||
|
ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
|
||||||
|
if (dtor != null) {
|
||||||
updateParameterBindings(dtor);
|
updateParameterBindings(dtor);
|
||||||
|
|
||||||
if (declarations == null) {
|
if (declarations == null) {
|
||||||
|
@ -191,17 +186,28 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
declarations, dtor);
|
declarations, dtor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICPPASTFunctionDeclarator extractFunctionDtor(IASTNode node) {
|
||||||
|
if (node instanceof IASTName)
|
||||||
|
node = node.getParent();
|
||||||
|
if (node instanceof IASTDeclarator == false)
|
||||||
|
return null;
|
||||||
|
node= CPPVisitor.findTypeRelevantDeclarator((IASTDeclarator) node);
|
||||||
|
if (node instanceof ICPPASTFunctionDeclarator == false)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return (ICPPASTFunctionDeclarator) node;
|
||||||
|
}
|
||||||
|
|
||||||
public void removeDeclaration(IASTNode node) {
|
public void removeDeclaration(IASTNode node) {
|
||||||
while (node instanceof IASTName) {
|
ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
|
||||||
node = node.getParent();
|
if (definition == dtor) {
|
||||||
}
|
|
||||||
if (definition == node) {
|
|
||||||
definition = null;
|
definition = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (declarations != null) {
|
if (declarations != null) {
|
||||||
ArrayUtil.remove(declarations, node);
|
ArrayUtil.remove(declarations, dtor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,11 +256,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
|
|
||||||
protected IASTName getASTName() {
|
protected IASTName getASTName() {
|
||||||
IASTDeclarator dtor = (definition != null) ? definition : declarations[0];
|
IASTDeclarator dtor = (definition != null) ? definition : declarations[0];
|
||||||
IASTDeclarator nested= dtor.getNestedDeclarator();
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
while (nested != null) {
|
|
||||||
dtor= nested;
|
|
||||||
nested= nested.getNestedDeclarator();
|
|
||||||
}
|
|
||||||
IASTName name= dtor.getName();
|
IASTName name= dtor.getName();
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
|
@ -263,23 +265,17 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IScope getScope() {
|
public IScope getScope() {
|
||||||
IASTName n = getASTName();
|
IASTName n = getASTName();
|
||||||
IScope scope = CPPVisitor.getContainingScope(n);
|
IScope scope = CPPVisitor.getContainingScope(n);
|
||||||
if (scope instanceof ICPPClassScope) {
|
if (scope instanceof ICPPClassScope) {
|
||||||
ICPPASTDeclSpecifier declSpec = null;
|
ICPPASTDeclSpecifier declSpec = null;
|
||||||
if (definition != null) {
|
if (definition != null) {
|
||||||
IASTNode node = definition.getParent();
|
IASTNode node = CPPVisitor.findOutermostDeclarator(definition).getParent();
|
||||||
while (node instanceof IASTDeclarator)
|
|
||||||
node = node.getParent();
|
|
||||||
IASTFunctionDefinition def = (IASTFunctionDefinition) node;
|
IASTFunctionDefinition def = (IASTFunctionDefinition) node;
|
||||||
declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier();
|
declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier();
|
||||||
} else {
|
} else {
|
||||||
IASTNode node = declarations[0].getParent();
|
IASTNode node = CPPVisitor.findOutermostDeclarator(declarations[0]).getParent();
|
||||||
while (node instanceof IASTDeclarator)
|
|
||||||
node = node.getParent();
|
|
||||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node;
|
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node;
|
||||||
declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
|
declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,11 +74,11 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
|
||||||
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
||||||
//first check if we already know it
|
//first check if we already know it
|
||||||
if( declarations != null ){
|
if( declarations != null ){
|
||||||
for (ICPPASTFunctionDeclarator declaration : declarations) {
|
for (ICPPASTFunctionDeclarator dtor : declarations) {
|
||||||
if (declaration == null) {
|
if (dtor == null)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
IASTDeclaration decl = (IASTDeclaration) declaration.getParent();
|
IASTDeclaration decl= (IASTDeclaration) CPPVisitor.findOutermostDeclarator(dtor).getParent();
|
||||||
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
@ -108,8 +108,8 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
|
||||||
di = 0;
|
di = 0;
|
||||||
dtor = ds[0];
|
dtor = ds[0];
|
||||||
while( dtor != null ){
|
while( dtor != null ){
|
||||||
IASTName name = dtor.getName();
|
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
|
||||||
if( dtor instanceof ICPPASTFunctionDeclarator &&
|
if( CPPVisitor.findTypeRelevantDeclarator(dtor) instanceof ICPPASTFunctionDeclarator &&
|
||||||
CharArrayUtils.equals( name.toCharArray(), getNameCharArray() ) )
|
CharArrayUtils.equals( name.toCharArray(), getNameCharArray() ) )
|
||||||
{
|
{
|
||||||
IType t0= CPPVisitor.createType( dtor );
|
IType t0= CPPVisitor.createType( dtor );
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
@ -83,13 +84,11 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
||||||
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
||||||
//first check if we already know it
|
//first check if we already know it
|
||||||
if( declarations != null ){
|
if( declarations != null ){
|
||||||
for( int i = 0; i < declarations.length; i++ ){
|
for (IASTDeclarator dtor : declarations) {
|
||||||
IASTDeclarator dtor = declarations[i];
|
|
||||||
if (dtor == null) {
|
if (dtor == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while( dtor.getParent() instanceof IASTDeclarator )
|
dtor= CPPVisitor.findOutermostDeclarator(dtor);
|
||||||
dtor = (IASTDeclarator) dtor.getParent();
|
|
||||||
IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
|
IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
|
||||||
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||||
return decl;
|
return decl;
|
||||||
|
@ -102,23 +101,24 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
||||||
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
|
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
|
||||||
if (compSpec != null) {
|
if (compSpec != null) {
|
||||||
IASTDeclaration [] members = compSpec.getMembers();
|
IASTDeclaration [] members = compSpec.getMembers();
|
||||||
for( int i = 0; i < members.length; i++ ){
|
for (IASTDeclaration member : members) {
|
||||||
if( members[i] instanceof IASTSimpleDeclaration ){
|
if( member instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)member).getDeclarators();
|
||||||
for( int j = 0; j < dtors.length; j++ ){
|
for (IASTDeclarator dtor : dtors) {
|
||||||
IASTName name = dtors[j].getName();
|
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||||
name.resolveBinding() == this )
|
name.resolveBinding() == this )
|
||||||
{
|
{
|
||||||
return members[i];
|
return member;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( members[i] instanceof IASTFunctionDefinition ){
|
} else if( member instanceof IASTFunctionDefinition ){
|
||||||
IASTName name = ((IASTFunctionDefinition) members[i]).getDeclarator().getName();
|
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) member).getDeclarator();
|
||||||
|
IASTName name = CPPVisitor.findInnermostDeclarator(declarator).getName();
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||||
name.resolveBinding() == this )
|
name.resolveBinding() == this )
|
||||||
{
|
{
|
||||||
return members[i];
|
return member;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,10 +143,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
||||||
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
|
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
|
||||||
IASTDeclaration [] members = cls.getMembers();
|
IASTDeclaration [] members = cls.getMembers();
|
||||||
ICPPASTVisibilityLabel vis = null;
|
ICPPASTVisibilityLabel vis = null;
|
||||||
for( int i = 0; i < members.length; i++ ){
|
for (IASTDeclaration member : members) {
|
||||||
if( members[i] instanceof ICPPASTVisibilityLabel )
|
if( member instanceof ICPPASTVisibilityLabel )
|
||||||
vis = (ICPPASTVisibilityLabel) members[i];
|
vis = (ICPPASTVisibilityLabel) member;
|
||||||
else if( members[i] == decl )
|
else if( member == decl )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( vis != null ){
|
if( vis != null ){
|
||||||
|
@ -163,27 +163,20 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IScope getScope() {
|
protected IASTName getASTName() {
|
||||||
IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : definition;
|
IASTDeclarator dtor= (declarations != null && declarations.length > 0) ? declarations[0] : definition;
|
||||||
if( node instanceof IASTDeclarator ){
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
IASTName name = ((IASTDeclarator)node).getName();
|
IASTName name= dtor.getName();
|
||||||
if( name instanceof ICPPASTQualifiedName ){
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
name = ns[ ns.length - 1 ];
|
name = ns[ ns.length - 1 ];
|
||||||
}
|
}
|
||||||
return CPPVisitor.getContainingScope( name );
|
return name;
|
||||||
}
|
|
||||||
return CPPVisitor.getContainingScope( node );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IASTName getASTName() {
|
public IScope getScope() {
|
||||||
IASTName name= definition != null ? definition.getName() : declarations[0].getName();
|
return CPPVisitor.getContainingScope(getASTName());
|
||||||
if( name instanceof ICPPASTQualifiedName ){
|
|
||||||
final IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
|
||||||
return ns[ns.length - 1];
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
* IBM - Initial API and implementation
|
* IBM - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
/*
|
|
||||||
* Created on Mar 31, 2005
|
|
||||||
*/
|
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
|
@ -75,7 +72,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
if( decl instanceof IASTSimpleDeclaration ){
|
if( decl instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||||
for (IASTDeclarator dtor : dtors) {
|
for (IASTDeclarator dtor : dtors) {
|
||||||
IASTName name = CPPVisitor.getMostNestedDeclarator( dtor ).getName();
|
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||||
name.resolveBinding() == this )
|
name.resolveBinding() == this )
|
||||||
{
|
{
|
||||||
|
@ -83,7 +80,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( decl instanceof IASTFunctionDefinition ){
|
} else if( decl instanceof IASTFunctionDefinition ){
|
||||||
IASTName name = CPPVisitor.getMostNestedDeclarator( ((IASTFunctionDefinition) decl).getDeclarator() ).getName();
|
IASTName name = CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition) decl).getDeclarator()).getName();
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||||
name.resolveBinding() == this )
|
name.resolveBinding() == this )
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,8 +72,7 @@ class ClassTypeMixin {
|
||||||
}
|
}
|
||||||
ObjectSet<IBinding> resultSet = new ObjectSet<IBinding>(2);
|
ObjectSet<IBinding> resultSet = new ObjectSet<IBinding>(2);
|
||||||
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
|
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
|
||||||
for( int i = 0; i < members.length; i++ ){
|
for (IASTDeclaration decl : members) {
|
||||||
IASTDeclaration decl = members[i];
|
|
||||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||||
|
|
||||||
|
@ -84,9 +83,10 @@ class ClassTypeMixin {
|
||||||
if( declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0 ){
|
if( declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0 ){
|
||||||
resultSet.put( ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding() );
|
resultSet.put( ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding() );
|
||||||
} else {
|
} else {
|
||||||
for( int j = 0; j < dtors.length; j++ ){
|
for (IASTDeclarator dtor : dtors) {
|
||||||
if( dtors[j] == null ) break;
|
if( dtor == null ) break;
|
||||||
resultSet.put( dtors[j].getName().resolveBinding() );
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
|
resultSet.put( dtor.getName().resolveBinding() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,9 +94,9 @@ class ClassTypeMixin {
|
||||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
|
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
|
||||||
if( declSpec.isFriend() ){
|
if( declSpec.isFriend() ){
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||||
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
resultSet.put( dtor.getName().resolveBinding() );
|
resultSet.put( dtor.getName().resolveBinding() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,8 +130,8 @@ class ClassTypeMixin {
|
||||||
ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope();
|
ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope();
|
||||||
set.addAll( scope.getImplicitMethods() );
|
set.addAll( scope.getImplicitMethods() );
|
||||||
ICPPBase [] bases = getBases();
|
ICPPBase [] bases = getBases();
|
||||||
for ( int i = 0; i < bases.length; i++ ) {
|
for (ICPPBase base : bases) {
|
||||||
IBinding b = bases[i].getBaseClass();
|
IBinding b = base.getBaseClass();
|
||||||
if( b instanceof ICPPClassType )
|
if( b instanceof ICPPClassType )
|
||||||
set.addAll( ((ICPPClassType)b).getMethods() );
|
set.addAll( ((ICPPClassType)b).getMethods() );
|
||||||
}
|
}
|
||||||
|
@ -152,22 +152,22 @@ class ClassTypeMixin {
|
||||||
ICPPField [] result = null;
|
ICPPField [] result = null;
|
||||||
|
|
||||||
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
||||||
for ( int i = 0; i < decls.length; i++ ) {
|
for (IASTDeclaration decl : decls) {
|
||||||
if( decls[i] instanceof IASTSimpleDeclaration ){
|
if( decl instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decls[i]).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||||
for ( int j = 0; j < dtors.length; j++ ) {
|
for (IASTDeclarator dtor : dtors) {
|
||||||
binding = dtors[j].getName().resolveBinding();
|
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding();
|
||||||
if( binding instanceof ICPPField )
|
if( binding instanceof ICPPField )
|
||||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, binding );
|
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, binding );
|
||||||
}
|
}
|
||||||
} else if( decls[i] instanceof ICPPASTUsingDeclaration ){
|
} else if( decl instanceof ICPPASTUsingDeclaration ){
|
||||||
IASTName n = ((ICPPASTUsingDeclaration)decls[i]).getName();
|
IASTName n = ((ICPPASTUsingDeclaration)decl).getName();
|
||||||
binding = n.resolveBinding();
|
binding = n.resolveBinding();
|
||||||
if( binding instanceof ICPPUsingDeclaration ){
|
if( binding instanceof ICPPUsingDeclaration ){
|
||||||
IBinding [] bs = ((ICPPUsingDeclaration)binding).getDelegates();
|
IBinding [] bs = ((ICPPUsingDeclaration)binding).getDelegates();
|
||||||
for ( int j = 0; j < bs.length; j++ ) {
|
for (IBinding element : bs) {
|
||||||
if( bs[j] instanceof ICPPField )
|
if( element instanceof ICPPField )
|
||||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, bs[j] );
|
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, element );
|
||||||
}
|
}
|
||||||
} else if( binding instanceof ICPPField ) {
|
} else if( binding instanceof ICPPField ) {
|
||||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, binding );
|
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, binding );
|
||||||
|
@ -189,8 +189,8 @@ class ClassTypeMixin {
|
||||||
|
|
||||||
ICPPMethod[] methods = getDeclaredMethods();
|
ICPPMethod[] methods = getDeclaredMethods();
|
||||||
ICPPBase [] bases = getBases();
|
ICPPBase [] bases = getBases();
|
||||||
for ( int i = 0; i < bases.length; i++ ) {
|
for (ICPPBase base : bases) {
|
||||||
IBinding b = bases[i].getBaseClass();
|
IBinding b = base.getBaseClass();
|
||||||
if( b instanceof ICPPClassType )
|
if( b instanceof ICPPClassType )
|
||||||
methods = (ICPPMethod[]) ArrayUtil.addAll( ICPPMethod.class, methods, ((ICPPClassType)b).getAllDeclaredMethods() );
|
methods = (ICPPMethod[]) ArrayUtil.addAll( ICPPMethod.class, methods, ((ICPPClassType)b).getAllDeclaredMethods() );
|
||||||
}
|
}
|
||||||
|
@ -210,20 +210,19 @@ class ClassTypeMixin {
|
||||||
ICPPMethod [] result = null;
|
ICPPMethod [] result = null;
|
||||||
|
|
||||||
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
||||||
for ( int i = 0; i < decls.length; i++ ) {
|
for (IASTDeclaration decl : decls) {
|
||||||
IASTDeclaration decl = decls[i];
|
|
||||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||||
if( decl instanceof IASTSimpleDeclaration ){
|
if( decl instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||||
for ( int j = 0; j < dtors.length; j++ ) {
|
for (IASTDeclarator dtor : dtors) {
|
||||||
binding = dtors[j].getName().resolveBinding();
|
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding();
|
||||||
if( binding instanceof ICPPMethod)
|
if( binding instanceof ICPPMethod)
|
||||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||||
}
|
}
|
||||||
} else if( decl instanceof IASTFunctionDefinition ){
|
} else if( decl instanceof IASTFunctionDefinition ){
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||||
dtor = CPPVisitor.getMostNestedDeclarator( dtor );
|
dtor = CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
binding = dtor.getName().resolveBinding();
|
binding = dtor.getName().resolveBinding();
|
||||||
if( binding instanceof ICPPMethod ){
|
if( binding instanceof ICPPMethod ){
|
||||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||||
|
@ -233,9 +232,9 @@ class ClassTypeMixin {
|
||||||
binding = n.resolveBinding();
|
binding = n.resolveBinding();
|
||||||
if( binding instanceof ICPPUsingDeclaration ){
|
if( binding instanceof ICPPUsingDeclaration ){
|
||||||
IBinding [] bs = ((ICPPUsingDeclaration)binding).getDelegates();
|
IBinding [] bs = ((ICPPUsingDeclaration)binding).getDelegates();
|
||||||
for ( int j = 0; j < bs.length; j++ ) {
|
for (IBinding element : bs) {
|
||||||
if( bs[j] instanceof ICPPMethod )
|
if( element instanceof ICPPMethod )
|
||||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, bs[j] );
|
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, element );
|
||||||
}
|
}
|
||||||
} else if( binding instanceof ICPPMethod ) {
|
} else if( binding instanceof ICPPMethod ) {
|
||||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||||
|
@ -263,18 +262,19 @@ class ClassTypeMixin {
|
||||||
return ((CPPClassScope)scope).getConstructors( true );
|
return ((CPPClassScope)scope).getConstructors( true );
|
||||||
|
|
||||||
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
|
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
|
||||||
for( int i = 0; i < members.length; i++ ){
|
for (IASTDeclaration decl : members) {
|
||||||
IASTDeclaration decl = members[i];
|
|
||||||
if( decl instanceof ICPPASTTemplateDeclaration )
|
if( decl instanceof ICPPASTTemplateDeclaration )
|
||||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||||
if( decl instanceof IASTSimpleDeclaration ){
|
if( decl instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||||
for( int j = 0; j < dtors.length; j++ ){
|
for (IASTDeclarator dtor : dtors) {
|
||||||
if( dtors[j] == null ) break;
|
if( dtor == null ) break;
|
||||||
ASTInternal.addName(scope, dtors[j].getName() );
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
|
ASTInternal.addName(scope, dtor.getName() );
|
||||||
}
|
}
|
||||||
} else if( decl instanceof IASTFunctionDefinition ){
|
} else if( decl instanceof IASTFunctionDefinition ){
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||||
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
ASTInternal.addName(scope, dtor.getName() );
|
ASTInternal.addName(scope, dtor.getName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,8 +295,7 @@ class ClassTypeMixin {
|
||||||
ICPPClassType [] result = null;
|
ICPPClassType [] result = null;
|
||||||
|
|
||||||
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
||||||
for ( int i = 0; i < decls.length; i++ ) {
|
for (IASTDeclaration decl : decls) {
|
||||||
IASTDeclaration decl = decls[i];
|
|
||||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||||
if( decl instanceof IASTSimpleDeclaration ){
|
if( decl instanceof IASTSimpleDeclaration ){
|
||||||
|
@ -328,8 +327,8 @@ class ClassTypeMixin {
|
||||||
|
|
||||||
IField[] fields = getDeclaredFields();
|
IField[] fields = getDeclaredFields();
|
||||||
ICPPBase [] bases = getBases();
|
ICPPBase [] bases = getBases();
|
||||||
for ( int i = 0; i < bases.length; i++ ) {
|
for (ICPPBase base : bases) {
|
||||||
IBinding b = bases[i].getBaseClass();
|
IBinding b = base.getBaseClass();
|
||||||
if( b instanceof ICPPClassType )
|
if( b instanceof ICPPClassType )
|
||||||
fields = (IField[]) ArrayUtil.addAll( IField.class, fields, ((ICPPClassType)b).getFields() );
|
fields = (IField[]) ArrayUtil.addAll( IField.class, fields, ((ICPPClassType)b).getFields() );
|
||||||
}
|
}
|
||||||
|
@ -339,10 +338,10 @@ class ClassTypeMixin {
|
||||||
public IField findField(String name) throws DOMException {
|
public IField findField(String name) throws DOMException {
|
||||||
IBinding [] bindings = CPPSemantics.findBindings( host.getCompositeScope(), name, true );
|
IBinding [] bindings = CPPSemantics.findBindings( host.getCompositeScope(), name, true );
|
||||||
IField field = null;
|
IField field = null;
|
||||||
for ( int i = 0; i < bindings.length; i++ ) {
|
for (IBinding binding : bindings) {
|
||||||
if( bindings[i] instanceof IField ){
|
if( binding instanceof IField ){
|
||||||
if( field == null )
|
if( field == null )
|
||||||
field = (IField) bindings[i];
|
field = (IField) binding;
|
||||||
else {
|
else {
|
||||||
IASTNode[] declarations= host.getDeclarations();
|
IASTNode[] declarations= host.getDeclarations();
|
||||||
IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : null;
|
IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : null;
|
||||||
|
|
|
@ -68,7 +68,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
|
@ -2508,15 +2507,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needFunctionBody) {
|
if (needFunctionBody) {
|
||||||
if (declarators.length != 1)
|
return functionDefinition(firstOffset, declSpec, declarators, hasFunctionTryBlock);
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
|
||||||
|
|
||||||
// mstodo
|
|
||||||
final IASTDeclarator fdtor= declarators[0];
|
|
||||||
if (fdtor instanceof ICPPASTFunctionDeclarator == false)
|
|
||||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
|
||||||
|
|
||||||
return functionDefinition(firstOffset, declSpec, fdtor, hasFunctionTryBlock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// no function body
|
// no function body
|
||||||
|
@ -2542,18 +2533,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
|
private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
|
||||||
IASTDeclarator declarator, boolean hasFunctionTryBlock)
|
IASTDeclarator[] dtors, boolean hasFunctionTryBlock) throws EndOfFileException, BacktrackException {
|
||||||
throws EndOfFileException, BacktrackException {
|
|
||||||
|
if (dtors.length != 1)
|
||||||
|
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||||
|
|
||||||
|
final IASTDeclarator outerDtor= dtors[0];
|
||||||
|
final IASTDeclarator dtor= CPPVisitor.findTypeRelevantDeclarator(outerDtor);
|
||||||
|
if (dtor instanceof ICPPASTFunctionDeclarator == false)
|
||||||
|
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||||
|
|
||||||
|
final ICPPASTFunctionDeclarator fdtor= (ICPPASTFunctionDeclarator) dtor;
|
||||||
|
|
||||||
if (LT(1) == IToken.tCOLON) {
|
if (LT(1) == IToken.tCOLON) {
|
||||||
List<ICPPASTConstructorChainInitializer> constructorChain= new ArrayList<ICPPASTConstructorChainInitializer>(DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE);
|
List<ICPPASTConstructorChainInitializer> constructorChain= new ArrayList<ICPPASTConstructorChainInitializer>(DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE);
|
||||||
ctorInitializer(constructorChain);
|
ctorInitializer(constructorChain);
|
||||||
if (!constructorChain.isEmpty() && declarator instanceof ICPPASTFunctionDeclarator) {
|
if (!constructorChain.isEmpty()) {
|
||||||
ICPPASTFunctionDeclarator fd = (ICPPASTFunctionDeclarator) declarator;
|
|
||||||
for (ICPPASTConstructorChainInitializer initializer : constructorChain) {
|
for (ICPPASTConstructorChainInitializer initializer : constructorChain) {
|
||||||
fd.addConstructorToChain(initializer);
|
fdtor.addConstructorToChain(initializer);
|
||||||
}
|
}
|
||||||
// fix for 86698, update the declarator's length
|
// fix for 86698, update the declarator's length
|
||||||
adjustLength(fd, constructorChain.get(constructorChain.size()-1));
|
adjustLength(outerDtor, constructorChain.get(constructorChain.size()-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2564,8 +2564,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (hasFunctionTryBlock) {
|
if (hasFunctionTryBlock) {
|
||||||
List<ICPPASTCatchHandler> handlers = new ArrayList<ICPPASTCatchHandler>(DEFAULT_CATCH_HANDLER_LIST_SIZE);
|
List<ICPPASTCatchHandler> handlers = new ArrayList<ICPPASTCatchHandler>(DEFAULT_CATCH_HANDLER_LIST_SIZE);
|
||||||
catchHandlerSequence(handlers);
|
catchHandlerSequence(handlers);
|
||||||
if (!handlers.isEmpty() && declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
|
if (!handlers.isEmpty() && fdtor instanceof ICPPASTFunctionTryBlockDeclarator) {
|
||||||
ICPPASTFunctionTryBlockDeclarator tbd= (ICPPASTFunctionTryBlockDeclarator) declarator;
|
ICPPASTFunctionTryBlockDeclarator tbd= (ICPPASTFunctionTryBlockDeclarator) fdtor;
|
||||||
for (ICPPASTCatchHandler catchHandler : handlers) {
|
for (ICPPASTCatchHandler catchHandler : handlers) {
|
||||||
tbd.addCatchHandler(catchHandler);
|
tbd.addCatchHandler(catchHandler);
|
||||||
}
|
}
|
||||||
|
@ -2575,7 +2575,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
|
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
|
||||||
funcDefinition.setDeclSpecifier(declSpec);
|
funcDefinition.setDeclSpecifier(declSpec);
|
||||||
funcDefinition.setDeclarator((IASTStandardFunctionDeclarator) declarator);
|
funcDefinition.setDeclarator(fdtor);
|
||||||
funcDefinition.setBody(body);
|
funcDefinition.setBody(body);
|
||||||
|
|
||||||
((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, endOffset-firstOffset);
|
((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, endOffset-firstOffset);
|
||||||
|
|
|
@ -1335,8 +1335,7 @@ public class CPPSemantics {
|
||||||
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
||||||
if (!declSpec.isFriend()) {
|
if (!declSpec.isFriend()) {
|
||||||
for (IASTDeclarator declarator : declarators) {
|
for (IASTDeclarator declarator : declarators) {
|
||||||
while (declarator.getNestedDeclarator() != null)
|
declarator= CPPVisitor.findInnermostDeclarator(declarator);
|
||||||
declarator = declarator.getNestedDeclarator();
|
|
||||||
IASTName declaratorName = declarator.getName();
|
IASTName declaratorName = declarator.getName();
|
||||||
ASTInternal.addName(scope, declaratorName);
|
ASTInternal.addName(scope, declaratorName);
|
||||||
if (!data.typesOnly || simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) {
|
if (!data.typesOnly || simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) {
|
||||||
|
@ -1452,7 +1451,7 @@ public class CPPSemantics {
|
||||||
IASTFunctionDeclarator declarator = functionDef.getDeclarator();
|
IASTFunctionDeclarator declarator = functionDef.getDeclarator();
|
||||||
|
|
||||||
//check the function itself
|
//check the function itself
|
||||||
IASTName declName = declarator.getName();
|
IASTName declName = CPPVisitor.findInnermostDeclarator(declarator).getName();
|
||||||
ASTInternal.addName(scope, declName);
|
ASTInternal.addName(scope, declName);
|
||||||
|
|
||||||
if (!data.typesOnly && nameMatches(data, declName, scope)) {
|
if (!data.typesOnly && nameMatches(data, declName, scope)) {
|
||||||
|
@ -2301,8 +2300,7 @@ public class CPPSemantics {
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition)node).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition)node).getDeclarator();
|
||||||
while (dtor.getNestedDeclarator() != null)
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
dtor = dtor.getNestedDeclarator();
|
|
||||||
IBinding binding = dtor.getName().resolveBinding();
|
IBinding binding = dtor.getName().resolveBinding();
|
||||||
if (binding instanceof IFunction) {
|
if (binding instanceof IFunction) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -177,14 +177,12 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IASTDeclarator dtor = dtors[0];
|
IASTDeclarator dtor = dtors[0];
|
||||||
while (dtor.getNestedDeclarator() != null)
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
dtor = dtor.getNestedDeclarator();
|
|
||||||
name = dtor.getName();
|
name = dtor.getName();
|
||||||
}
|
}
|
||||||
} else if (decl instanceof IASTFunctionDefinition) {
|
} else if (decl instanceof IASTFunctionDefinition) {
|
||||||
IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
|
IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
|
||||||
while (dtor.getNestedDeclarator() != null)
|
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||||
dtor = dtor.getNestedDeclarator();
|
|
||||||
name = dtor.getName();
|
name = dtor.getName();
|
||||||
}
|
}
|
||||||
if (name == null)
|
if (name == null)
|
||||||
|
@ -940,9 +938,7 @@ public class CPPTemplates {
|
||||||
}
|
}
|
||||||
} else if (nestedDecl instanceof IASTFunctionDefinition) {
|
} else if (nestedDecl instanceof IASTFunctionDefinition) {
|
||||||
IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator();
|
IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator();
|
||||||
while (declarator.getNestedDeclarator() != null) {
|
declarator= CPPVisitor.findInnermostDeclarator(declarator);
|
||||||
declarator= declarator.getNestedDeclarator();
|
|
||||||
}
|
|
||||||
name = declarator.getName();
|
name = declarator.getName();
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
|
|
@ -515,28 +515,14 @@ public class CPPVisitor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private static IBinding createBinding(IASTDeclarator declarator) {
|
private static IBinding createBinding(IASTDeclarator declarator) {
|
||||||
IASTNode parent = declarator.getParent();
|
IASTNode parent = findOutermostDeclarator(declarator).getParent();
|
||||||
while (parent instanceof IASTDeclarator) {
|
declarator= findInnermostDeclarator(declarator);
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (declarator.getNestedDeclarator() != null)
|
|
||||||
declarator = declarator.getNestedDeclarator();
|
|
||||||
|
|
||||||
IASTFunctionDeclarator funcDeclarator= null;
|
IASTFunctionDeclarator funcDeclarator= null;
|
||||||
IASTNode tmpNode= declarator;
|
final IASTDeclarator typeRelevantDtor= findTypeRelevantDeclarator(declarator);
|
||||||
do {
|
if (typeRelevantDtor instanceof IASTFunctionDeclarator) {
|
||||||
if (tmpNode instanceof IASTFunctionDeclarator) {
|
funcDeclarator= (IASTFunctionDeclarator) typeRelevantDtor;
|
||||||
funcDeclarator= (IASTFunctionDeclarator) tmpNode;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (((IASTDeclarator) tmpNode).getPointerOperators().length > 0 ||
|
|
||||||
tmpNode.getPropertyInParent() != IASTDeclarator.NESTED_DECLARATOR) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
tmpNode= tmpNode.getParent();
|
|
||||||
}
|
|
||||||
while (tmpNode instanceof IASTDeclarator);
|
|
||||||
|
|
||||||
IASTName name= declarator.getName();
|
IASTName name= declarator.getName();
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
|
@ -587,10 +573,10 @@ public class CPPVisitor {
|
||||||
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent;
|
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent;
|
||||||
parent = param.getParent();
|
parent = param.getParent();
|
||||||
if (parent instanceof IASTStandardFunctionDeclarator) {
|
if (parent instanceof IASTStandardFunctionDeclarator) {
|
||||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||||
if (hasNestedPointerOperator(fDtor))
|
if (hasNestedPointerOperator(fdtor))
|
||||||
return null;
|
return null;
|
||||||
IBinding temp = fDtor.getName().resolveBinding();
|
IBinding temp = fdtor.getName().resolveBinding();
|
||||||
if (temp instanceof ICPPInternalFunction) {
|
if (temp instanceof ICPPInternalFunction) {
|
||||||
binding = ((ICPPInternalFunction) temp).resolveParameter(param);
|
binding = ((ICPPInternalFunction) temp).resolveParameter(param);
|
||||||
} else if (temp instanceof IProblemBinding) {
|
} else if (temp instanceof IProblemBinding) {
|
||||||
|
@ -621,7 +607,7 @@ public class CPPVisitor {
|
||||||
// if we don't resolve the target type first, we get a problem binding in case the typedef
|
// if we don't resolve the target type first, we get a problem binding in case the typedef
|
||||||
// redeclares the target type:
|
// redeclares the target type:
|
||||||
// typedef struct S S;
|
// typedef struct S S;
|
||||||
IType targetType= CPPVisitor.createType(declarator);
|
IType targetType= createType(declarator);
|
||||||
CPPTypedef td= new CPPTypedef(name);
|
CPPTypedef td= new CPPTypedef(name);
|
||||||
td.setType(targetType);
|
td.setType(targetType);
|
||||||
binding = td;
|
binding = td;
|
||||||
|
@ -743,7 +729,7 @@ public class CPPVisitor {
|
||||||
if (declarator == null || !(declarator instanceof IASTFunctionDeclarator))
|
if (declarator == null || !(declarator instanceof IASTFunctionDeclarator))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IASTName name = declarator.getName();
|
IASTName name = findInnermostDeclarator(declarator).getName();
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
|
IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
|
||||||
name = names[names.length - 1];
|
name = names[names.length - 1];
|
||||||
|
@ -752,7 +738,7 @@ public class CPPVisitor {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IASTDeclSpecifier declSpec = null;
|
IASTDeclSpecifier declSpec = null;
|
||||||
IASTNode parent = declarator.getParent();
|
IASTNode parent = findOutermostDeclarator(declarator).getParent();
|
||||||
if (parent instanceof IASTSimpleDeclaration) {
|
if (parent instanceof IASTSimpleDeclaration) {
|
||||||
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||||
} else if (parent instanceof IASTFunctionDefinition) {
|
} else if (parent instanceof IASTFunctionDefinition) {
|
||||||
|
@ -874,7 +860,7 @@ public class CPPVisitor {
|
||||||
n = ns[ns.length - 1];
|
n = ns[ns.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return CPPVisitor.getContainingScope(n);
|
return getContainingScope(n);
|
||||||
}
|
}
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
|
@ -1011,7 +997,7 @@ public class CPPVisitor {
|
||||||
scope = getContainingScope((IASTStatement)parent);
|
scope = getContainingScope((IASTStatement)parent);
|
||||||
} else if (parent instanceof IASTFunctionDefinition) {
|
} else if (parent instanceof IASTFunctionDefinition) {
|
||||||
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
|
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
|
||||||
IASTName name = fnDeclarator.getName();
|
IASTName name = findInnermostDeclarator(fnDeclarator).getName();
|
||||||
if (name instanceof ICPPASTQualifiedName) {
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||||
name = ns[ns.length -1];
|
name = ns[ns.length -1];
|
||||||
|
@ -1779,7 +1765,7 @@ public class CPPVisitor {
|
||||||
}
|
}
|
||||||
if (node instanceof IASTFunctionDeclarator) {
|
if (node instanceof IASTFunctionDeclarator) {
|
||||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
||||||
IASTName fName = dtor.getName();
|
IASTName fName = findInnermostDeclarator(dtor).getName();
|
||||||
if (fName instanceof ICPPASTQualifiedName) {
|
if (fName instanceof ICPPASTQualifiedName) {
|
||||||
IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames();
|
IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames();
|
||||||
fName = ns[ns.length - 1];
|
fName = ns[ns.length - 1];
|
||||||
|
@ -2180,15 +2166,6 @@ public class CPPVisitor {
|
||||||
return new CPPBasicType(IBasicType.t_int, flags, expression);
|
return new CPPBasicType(IBasicType.t_int, flags, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IASTDeclarator getMostNestedDeclarator(IASTDeclarator dtor) {
|
|
||||||
if (dtor == null) return null;
|
|
||||||
IASTDeclarator nested = null;
|
|
||||||
while ((nested = dtor.getNestedDeclarator()) != null) {
|
|
||||||
dtor = nested;
|
|
||||||
}
|
|
||||||
return dtor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IASTProblem[] getProblems(IASTTranslationUnit tu) {
|
public static IASTProblem[] getProblems(IASTTranslationUnit tu) {
|
||||||
CollectProblemsAction action = new CollectProblemsAction();
|
CollectProblemsAction action = new CollectProblemsAction();
|
||||||
tu.accept(action);
|
tu.accept(action);
|
||||||
|
@ -2444,23 +2421,20 @@ public class CPPVisitor {
|
||||||
/**
|
/**
|
||||||
* Returns the outermost declarator the given <code>declarator</code> nests within, or
|
* Returns the outermost declarator the given <code>declarator</code> nests within, or
|
||||||
* <code>declarator</code> itself.
|
* <code>declarator</code> itself.
|
||||||
* @since 5.0
|
|
||||||
*/
|
*/
|
||||||
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
|
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
|
||||||
while(true) {
|
IASTDeclarator outermost= null;
|
||||||
IASTNode parent= declarator.getParent();
|
IASTNode candidate= declarator;
|
||||||
if (parent instanceof IASTDeclarator) {
|
while(candidate instanceof IASTDeclarator) {
|
||||||
declarator= (IASTDeclarator) parent;
|
outermost= (IASTDeclarator) candidate;
|
||||||
} else {
|
candidate= outermost.getParent();
|
||||||
return declarator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return outermost;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the innermost declarator nested within the given <code>declarator</code>, or
|
* Returns the innermost declarator nested within the given <code>declarator</code>, or
|
||||||
* <code>declarator</code> itself.
|
* <code>declarator</code> itself.
|
||||||
* @since 5.1
|
|
||||||
*/
|
*/
|
||||||
public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
|
public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
|
||||||
IASTDeclarator innermost= null;
|
IASTDeclarator innermost= null;
|
||||||
|
@ -2473,7 +2447,6 @@ public class CPPVisitor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for the innermost declarator that contributes the the type declared.
|
* Searches for the innermost declarator that contributes the the type declared.
|
||||||
* @since 5.1
|
|
||||||
*/
|
*/
|
||||||
public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
|
public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
|
||||||
IASTDeclarator result= findInnermostDeclarator(declarator);
|
IASTDeclarator result= findInnermostDeclarator(declarator);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
|
||||||
|
@ -15,7 +16,6 @@ import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
|
|
||||||
|
|
||||||
|
@ -278,7 +279,7 @@ public class DeclarationWriter extends NodeWriter{
|
||||||
}else {
|
}else {
|
||||||
scribe.printSpace();
|
scribe.printSpace();
|
||||||
}
|
}
|
||||||
IASTFunctionDeclarator declarator = funcDef.getDeclarator();
|
IASTDeclarator declarator = CPPVisitor.findOutermostDeclarator(funcDef.getDeclarator());
|
||||||
declarator.accept(visitor);
|
declarator.accept(visitor);
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
funcDef.getBody().accept(visitor);
|
funcDef.getBody().accept(visitor);
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||||
|
@ -109,7 +110,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
||||||
sm.worked(1);
|
sm.worked(1);
|
||||||
if(methodToHideDecl instanceof IASTFunctionDefinition) {
|
if(methodToHideDecl instanceof IASTFunctionDefinition) {
|
||||||
IASTDeclarator declarator = ((IASTFunctionDefinition)methodToHideDecl).getDeclarator();
|
IASTDeclarator declarator = ((IASTFunctionDefinition)methodToHideDecl).getDeclarator();
|
||||||
if(declarator.getName().getRawSignature().equals(name.getRawSignature())) {
|
if(CPPVisitor.findInnermostDeclarator(declarator).getName().getRawSignature().equals(name.getRawSignature())) {
|
||||||
if (!(declarator instanceof IASTFunctionDeclarator)) {
|
if (!(declarator instanceof IASTFunctionDeclarator)) {
|
||||||
initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods);
|
initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods);
|
||||||
return initStatus;
|
return initStatus;
|
||||||
|
@ -215,7 +216,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
||||||
IASTNode parent = compStat.getParent();
|
IASTNode parent = compStat.getParent();
|
||||||
if(parent instanceof IASTFunctionDefinition) {
|
if(parent instanceof IASTFunctionDefinition) {
|
||||||
IASTDeclarator declarator = ((IASTFunctionDefinition)parent).getDeclarator();
|
IASTDeclarator declarator = ((IASTFunctionDefinition)parent).getDeclarator();
|
||||||
IASTName declaratorName = getLastName(declarator);
|
IASTName declaratorName = getLastName(CPPVisitor.findInnermostDeclarator(declarator));
|
||||||
|
|
||||||
DeclarationFinderDO data = DeclarationFinder.getDeclaration(declaratorName, getIndex());
|
DeclarationFinderDO data = DeclarationFinder.getDeclaration(declaratorName, getIndex());
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ public class NodeHelper {
|
||||||
found = true;
|
found = true;
|
||||||
context.setType(MethodContext.ContextType.FUNCTION);
|
context.setType(MethodContext.ContextType.FUNCTION);
|
||||||
} else if (node instanceof IASTFunctionDefinition){
|
} else if (node instanceof IASTFunctionDefinition){
|
||||||
name=((IASTFunctionDefinition)node).getDeclarator().getName();
|
name=CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition)node).getDeclarator()).getName();
|
||||||
found = true;
|
found = true;
|
||||||
context.setType(MethodContext.ContextType.FUNCTION);
|
context.setType(MethodContext.ContextType.FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,7 @@ import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||||
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.model.ASTCache;
|
import org.eclipse.cdt.internal.core.model.ASTCache;
|
||||||
|
|
||||||
|
@ -230,7 +231,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
if (declaration instanceof IASTFunctionDefinition) {
|
if (declaration instanceof IASTFunctionDefinition) {
|
||||||
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator();
|
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator();
|
||||||
if (declarator != null) {
|
if (declarator != null) {
|
||||||
fFunction= new String(declarator.getName().toCharArray());
|
fFunction= new String(CVisitor.findInnermostDeclarator(declarator).getName().toCharArray());
|
||||||
fLevel= 0;
|
fLevel= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue