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
|
||||
.getDeclarations()[0];
|
||||
IFunction f = (IFunction) def.getDeclarator().getNestedDeclarator()
|
||||
.getName().resolveBinding();
|
||||
IFunction f = (IFunction) def.getDeclarator().getName().resolveBinding();
|
||||
|
||||
IFunctionType ft = f.getType();
|
||||
assertTrue(ft.getReturnType() instanceof IPointerType);
|
||||
|
|
|
@ -2086,10 +2086,9 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTTranslationUnit tu = parse(
|
||||
"void ( * f( int ) )(){}", ParserLanguage.C); //$NON-NLS-1$
|
||||
|
||||
IASTFunctionDefinition def = (IASTFunctionDefinition) tu
|
||||
.getDeclarations()[0];
|
||||
IFunction f = (IFunction) def.getDeclarator().getNestedDeclarator()
|
||||
.getName().resolveBinding();
|
||||
IASTFunctionDefinition def = (IASTFunctionDefinition) tu.getDeclarations()[0];
|
||||
final IASTName fname = def.getDeclarator().getName();
|
||||
IFunction f = (IFunction) fname.resolveBinding();
|
||||
|
||||
IFunctionType ft = f.getType();
|
||||
assertTrue(ft.getReturnType() instanceof IPointerType);
|
||||
|
@ -2097,11 +2096,9 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(ft.getParameterTypes().length, 1);
|
||||
|
||||
// test tu.getDeclarationsInAST(IBinding)
|
||||
IASTName[] decls = tu.getDeclarationsInAST(def.getDeclarator()
|
||||
.getNestedDeclarator().getName().resolveBinding());
|
||||
IASTName[] decls = tu.getDeclarationsInAST(f);
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], def.getDeclarator().getNestedDeclarator()
|
||||
.getName());
|
||||
assertEquals(decls[0], fname);
|
||||
}
|
||||
|
||||
// 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[0], def2.getDeclarator().getName());
|
||||
|
||||
decls = tu.getDeclarationsInAST(def3.getDeclarator().getNestedDeclarator()
|
||||
.getName().resolveBinding());
|
||||
decls = tu.getDeclarationsInAST(def3.getDeclarator().getName().resolveBinding());
|
||||
assertEquals(decls.length, 1);
|
||||
assertEquals(decls[0], def3.getDeclarator().getNestedDeclarator()
|
||||
.getName());
|
||||
assertEquals(decls[0], def3.getDeclarator().getName());
|
||||
}
|
||||
|
||||
// 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] {};
|
||||
public void _testFunctionReturningPtrToArray_Bug216609() throws Exception {
|
||||
// works for plain-c, see testcase below.
|
||||
// int (*f1 (int par))[5];
|
||||
public void testFunctionReturningPtrToArray_Bug216609() throws Exception {
|
||||
final String comment= getAboveComment();
|
||||
final boolean[] isCpps= {false, true};
|
||||
for (boolean isCpp : isCpps) {
|
||||
|
@ -4868,6 +4863,68 @@ public class AST2Tests extends AST2BaseTest {
|
|||
|
||||
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void setDeclarator(IASTFunctionDeclarator declarator);
|
||||
|
@ -86,5 +98,4 @@ public interface IASTFunctionDefinition extends IASTDeclaration {
|
|||
* @return <code>IScope</code> representing function body.
|
||||
*/
|
||||
public IScope getScope();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
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.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -61,8 +63,9 @@ public class CASTFunctionDefinition extends CASTNode implements
|
|||
public void setDeclarator(IASTFunctionDeclarator declarator) {
|
||||
this.declarator = declarator;
|
||||
if (declarator != null) {
|
||||
declarator.setParent(this);
|
||||
declarator.setPropertyInParent(DECLARATOR);
|
||||
IASTDeclarator outerDtor= CVisitor.findOutermostDeclarator(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( 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( action.shouldVisitDeclarations ){
|
||||
|
@ -116,6 +120,4 @@ public class CASTFunctionDefinition extends CASTNode implements
|
|||
bodyStatement = (IASTStatement) other;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1040,7 +1040,7 @@ public class CVisitor {
|
|||
if (node instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) node;
|
||||
IASTFunctionDeclarator functionDeclartor = functionDef.getDeclarator();
|
||||
IASTName name = functionDeclartor.getName();
|
||||
IASTName name = findInnermostDeclarator(functionDeclartor).getName();
|
||||
IASTNode blockItem = getContainingBlockItem(node);
|
||||
try {
|
||||
return (IBinding) findBinding(blockItem, name, bits);
|
||||
|
@ -1211,7 +1211,7 @@ public class CVisitor {
|
|||
scope = getContainingScope((IASTStatement)parent);
|
||||
} else if (parent instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
|
||||
IBinding function = fnDeclarator.getName().resolveBinding();
|
||||
IBinding function = CVisitor.findInnermostDeclarator(fnDeclarator).getName().resolveBinding();
|
||||
try {
|
||||
if (function instanceof IFunction) {
|
||||
scope = ((IFunction)function).getFunctionScope();
|
||||
|
@ -1611,9 +1611,7 @@ public class CVisitor {
|
|||
IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration;
|
||||
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
||||
for (IASTDeclarator declarator : declarators) {
|
||||
while (declarator.getNestedDeclarator() != null) {
|
||||
declarator = declarator.getNestedDeclarator();
|
||||
}
|
||||
declarator= CVisitor.findInnermostDeclarator(declarator);
|
||||
tempName = declarator.getName();
|
||||
if (scope != null)
|
||||
ASTInternal.addName(scope, tempName);
|
||||
|
@ -1633,7 +1631,7 @@ public class CVisitor {
|
|||
} else if (!typesOnly && declaration instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration;
|
||||
|
||||
IASTDeclarator dtor = functionDef.getDeclarator();
|
||||
IASTDeclarator dtor = CVisitor.findInnermostDeclarator(functionDef.getDeclarator());
|
||||
tempName = dtor.getName();
|
||||
if (scope != null)
|
||||
ASTInternal.addName(scope, tempName);
|
||||
|
@ -1692,7 +1690,7 @@ public class CVisitor {
|
|||
|
||||
if (node instanceof IASTFunctionDefinition && decl instanceof IASTFunctionDeclarator) {
|
||||
IASTFunctionDeclarator dtor = ((IASTFunctionDefinition) node).getDeclarator();
|
||||
IASTName name = dtor.getName();
|
||||
IASTName name = CVisitor.findInnermostDeclarator(dtor).getName();
|
||||
if (name.toString().equals(declName)) {
|
||||
return dtor;
|
||||
}
|
||||
|
@ -2179,14 +2177,13 @@ public class CVisitor {
|
|||
* @since 5.0
|
||||
*/
|
||||
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
|
||||
while(true) {
|
||||
IASTNode parent= declarator.getParent();
|
||||
if (parent instanceof IASTDeclarator) {
|
||||
declarator= (IASTDeclarator) parent;
|
||||
} else {
|
||||
return declarator;
|
||||
}
|
||||
IASTDeclarator outermost= null;
|
||||
IASTNode candidate= declarator;
|
||||
while(candidate instanceof IASTDeclarator) {
|
||||
outermost= (IASTDeclarator) candidate;
|
||||
candidate= outermost.getParent();
|
||||
}
|
||||
return outermost;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -432,15 +432,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
if (declarators.length != 1)
|
||||
throwBacktrack(firstOffset, LA(1).getEndOffset());
|
||||
|
||||
// IASTDeclarator declarator= CVisitor.findTypeRelevantDeclarator(declarators[0]); // mstodo
|
||||
|
||||
IASTDeclarator declarator = declarators[0];
|
||||
if (!(declarator instanceof IASTFunctionDeclarator))
|
||||
throwBacktrack(firstOffset, LA(1).getEndOffset());
|
||||
final IASTDeclarator outerDtor= declarators[0];
|
||||
final IASTDeclarator fdtor= CVisitor.findTypeRelevantDeclarator(outerDtor);
|
||||
if (fdtor instanceof IASTFunctionDeclarator == false)
|
||||
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
|
||||
|
||||
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
|
||||
funcDefinition.setDeclSpecifier(declSpec);
|
||||
funcDefinition.setDeclarator((IASTFunctionDeclarator) declarator);
|
||||
funcDefinition.setDeclarator((IASTFunctionDeclarator) fdtor);
|
||||
|
||||
IASTStatement s= handleFunctionBody();
|
||||
funcDefinition.setBody(s);
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* 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;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
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.IASTFunctionDefinition;
|
||||
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.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -59,8 +62,9 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
|
|||
public void setDeclarator(IASTFunctionDeclarator declarator) {
|
||||
this.declarator = declarator;
|
||||
if (declarator != null) {
|
||||
declarator.setParent(this);
|
||||
declarator.setPropertyInParent(DECLARATOR);
|
||||
IASTDeclarator outerDtor= CPPVisitor.findOutermostDeclarator(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( 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( action.shouldVisitDeclarations ){
|
||||
|
@ -112,5 +117,4 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
|
|||
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.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.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
|
@ -32,8 +34,13 @@ public class CPPBlockScope extends CPPNamespaceScope implements ICPPBlockScope {
|
|||
@Override
|
||||
public IName getScopeName(){
|
||||
IASTNode node = getPhysicalNode();
|
||||
if( node instanceof IASTCompoundStatement && node.getParent() instanceof IASTFunctionDefinition ){
|
||||
return ((IASTFunctionDefinition)node.getParent()).getDeclarator().getName();
|
||||
if (node instanceof IASTCompoundStatement) {
|
||||
final IASTNode parent= node.getParent();
|
||||
if (parent instanceof IASTFunctionDefinition) {
|
||||
IASTDeclarator dtor= ((IASTFunctionDefinition)parent).getDeclarator();
|
||||
dtor = CPPVisitor.findInnermostDeclarator(dtor);
|
||||
return dtor.getName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -463,12 +463,12 @@ class ImplicitsAnalysis {
|
|||
}
|
||||
|
||||
boolean nameEquals= false;
|
||||
char[] dtorname= CPPVisitor.findInnermostDeclarator(dcltor).getName().toCharArray();
|
||||
if (constructor) {
|
||||
nameEquals= CharArrayUtils.equals(dcltor.getName().toCharArray(), name);
|
||||
nameEquals= CharArrayUtils.equals(dtorname, name);
|
||||
} else {
|
||||
char[] cname= dcltor.getName().toCharArray();
|
||||
if (cname.length > 0 && cname[0] == '~') {
|
||||
nameEquals= CharArrayUtils.equals(cname, 1, name.length, name);
|
||||
if (dtorname.length > 0 && dtorname[0] == '~') {
|
||||
nameEquals= CharArrayUtils.equals(dtorname, 1, name.length, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,11 +493,13 @@ class ImplicitsAnalysis {
|
|||
} else if (member instanceof IASTFunctionDefinition) {
|
||||
dcltor = ((IASTFunctionDefinition)member).getDeclarator();
|
||||
}
|
||||
if (!(dcltor instanceof ICPPASTFunctionDeclarator) ||
|
||||
!CharArrayUtils.equals(dcltor.getName().toCharArray(), OverloadableOperator.ASSIGN.toCharArray())) {
|
||||
if (dcltor instanceof ICPPASTFunctionDeclarator == false)
|
||||
continue;
|
||||
|
||||
final char[] nchars= CPPVisitor.findInnermostDeclarator(dcltor).getName().toCharArray();
|
||||
if (!CharArrayUtils.equals(nchars, OverloadableOperator.ASSIGN.toCharArray()))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
IASTParameterDeclaration[] ps = ((ICPPASTFunctionDeclarator)dcltor).getParameters();
|
||||
if (ps.length != 1 || !paramHasTypeReferenceToTheAssociatedClassType(ps[0], null))
|
||||
continue;
|
||||
|
|
|
@ -182,7 +182,7 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
|||
}
|
||||
} else if( decl instanceof IASTFunctionDefinition ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
dtor = CPPVisitor.getMostNestedDeclarator( dtor );
|
||||
dtor = CPPVisitor.findInnermostDeclarator(dtor);
|
||||
binding = dtor.getName().resolveBinding();
|
||||
if( binding instanceof ICPPMethod ){
|
||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||
|
@ -225,10 +225,12 @@ public class CPPClassSpecialization extends CPPSpecialization implements
|
|||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
if( dtor == null ) break;
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
ASTInternal.addName(scope, dtor.getName() );
|
||||
}
|
||||
} else if( decl instanceof IASTFunctionDefinition ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
ASTInternal.addName(scope, dtor.getName() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
|
||||
public CPPFunction(ICPPASTFunctionDeclarator declarator) {
|
||||
if (declarator != null) {
|
||||
IASTNode parent = declarator.getParent();
|
||||
IASTNode parent = CPPVisitor.findOutermostDeclarator(declarator).getParent();
|
||||
if (parent instanceof IASTFunctionDefinition)
|
||||
definition = declarator;
|
||||
else
|
||||
|
@ -160,48 +160,54 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
}
|
||||
|
||||
public void addDefinition(IASTNode node) {
|
||||
if (node instanceof IASTName)
|
||||
node = node.getParent();
|
||||
if (!(node instanceof ICPPASTFunctionDeclarator))
|
||||
return;
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
||||
updateParameterBindings(dtor);
|
||||
definition = dtor;
|
||||
}
|
||||
public void addDeclaration(IASTNode node) {
|
||||
if (node instanceof IASTName)
|
||||
node = node.getParent();
|
||||
if (!(node instanceof ICPPASTFunctionDeclarator))
|
||||
return;
|
||||
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
||||
updateParameterBindings(dtor);
|
||||
|
||||
if (declarations == null) {
|
||||
declarations = new ICPPASTFunctionDeclarator[] { dtor };
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep the lowest offset declaration in [0]
|
||||
if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset()) {
|
||||
declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.prepend(ICPPASTFunctionDeclarator.class,
|
||||
declarations, dtor);
|
||||
} else {
|
||||
declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append(ICPPASTFunctionDeclarator.class,
|
||||
declarations, dtor);
|
||||
ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
|
||||
if (dtor != null) {
|
||||
updateParameterBindings(dtor);
|
||||
definition = dtor;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeDeclaration(IASTNode node) {
|
||||
while (node instanceof IASTName) {
|
||||
node = node.getParent();
|
||||
public void addDeclaration(IASTNode node) {
|
||||
ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
|
||||
if (dtor != null) {
|
||||
updateParameterBindings(dtor);
|
||||
|
||||
if (declarations == null) {
|
||||
declarations = new ICPPASTFunctionDeclarator[] { dtor };
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep the lowest offset declaration in [0]
|
||||
if (declarations.length > 0 && ((ASTNode)node).getOffset() < ((ASTNode)declarations[0]).getOffset()) {
|
||||
declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.prepend(ICPPASTFunctionDeclarator.class,
|
||||
declarations, dtor);
|
||||
} else {
|
||||
declarations = (ICPPASTFunctionDeclarator[]) ArrayUtil.append(ICPPASTFunctionDeclarator.class,
|
||||
declarations, dtor);
|
||||
}
|
||||
}
|
||||
if (definition == node) {
|
||||
}
|
||||
|
||||
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) {
|
||||
ICPPASTFunctionDeclarator dtor = extractFunctionDtor(node);
|
||||
if (definition == dtor) {
|
||||
definition = null;
|
||||
return;
|
||||
}
|
||||
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() {
|
||||
IASTDeclarator dtor = (definition != null) ? definition : declarations[0];
|
||||
IASTDeclarator nested= dtor.getNestedDeclarator();
|
||||
while (nested != null) {
|
||||
dtor= nested;
|
||||
nested= nested.getNestedDeclarator();
|
||||
}
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
IASTName name= dtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
|
@ -263,23 +265,17 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
|||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IScope getScope() {
|
||||
IASTName n = getASTName();
|
||||
IScope scope = CPPVisitor.getContainingScope(n);
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
ICPPASTDeclSpecifier declSpec = null;
|
||||
if (definition != null) {
|
||||
IASTNode node = definition.getParent();
|
||||
while (node instanceof IASTDeclarator)
|
||||
node = node.getParent();
|
||||
IASTNode node = CPPVisitor.findOutermostDeclarator(definition).getParent();
|
||||
IASTFunctionDefinition def = (IASTFunctionDefinition) node;
|
||||
declSpec = (ICPPASTDeclSpecifier) def.getDeclSpecifier();
|
||||
} else {
|
||||
IASTNode node = declarations[0].getParent();
|
||||
while (node instanceof IASTDeclarator)
|
||||
node = node.getParent();
|
||||
IASTNode node = CPPVisitor.findOutermostDeclarator(declarations[0]).getParent();
|
||||
IASTSimpleDeclaration decl = (IASTSimpleDeclaration)node;
|
||||
declSpec = (ICPPASTDeclSpecifier) decl.getDeclSpecifier();
|
||||
}
|
||||
|
|
|
@ -74,11 +74,11 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
|
|||
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
||||
//first check if we already know it
|
||||
if( declarations != null ){
|
||||
for (ICPPASTFunctionDeclarator declaration : declarations) {
|
||||
if (declaration == null) {
|
||||
for (ICPPASTFunctionDeclarator dtor : declarations) {
|
||||
if (dtor == null)
|
||||
break;
|
||||
}
|
||||
IASTDeclaration decl = (IASTDeclaration) declaration.getParent();
|
||||
|
||||
IASTDeclaration decl= (IASTDeclaration) CPPVisitor.findOutermostDeclarator(dtor).getParent();
|
||||
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||
return decl;
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ public class CPPImplicitMethod extends CPPImplicitFunction implements ICPPMethod
|
|||
di = 0;
|
||||
dtor = ds[0];
|
||||
while( dtor != null ){
|
||||
IASTName name = dtor.getName();
|
||||
if( dtor instanceof ICPPASTFunctionDeclarator &&
|
||||
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
|
||||
if( CPPVisitor.findTypeRelevantDeclarator(dtor) instanceof ICPPASTFunctionDeclarator &&
|
||||
CharArrayUtils.equals( name.toCharArray(), getNameCharArray() ) )
|
||||
{
|
||||
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.IASTDeclaration;
|
||||
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.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -83,13 +84,11 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
||||
//first check if we already know it
|
||||
if( declarations != null ){
|
||||
for( int i = 0; i < declarations.length; i++ ){
|
||||
IASTDeclarator dtor = declarations[i];
|
||||
for (IASTDeclarator dtor : declarations) {
|
||||
if (dtor == null) {
|
||||
break;
|
||||
}
|
||||
while( dtor.getParent() instanceof IASTDeclarator )
|
||||
dtor = (IASTDeclarator) dtor.getParent();
|
||||
dtor= CPPVisitor.findOutermostDeclarator(dtor);
|
||||
IASTDeclaration decl = (IASTDeclaration) dtor.getParent();
|
||||
if( decl.getParent() instanceof ICPPASTCompositeTypeSpecifier )
|
||||
return decl;
|
||||
|
@ -102,23 +101,24 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(scope);
|
||||
if (compSpec != null) {
|
||||
IASTDeclaration [] members = compSpec.getMembers();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
if( members[i] instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)members[i]).getDeclarators();
|
||||
for( int j = 0; j < dtors.length; j++ ){
|
||||
IASTName name = dtors[j].getName();
|
||||
for (IASTDeclaration member : members) {
|
||||
if( member instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)member).getDeclarators();
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
|
||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||
name.resolveBinding() == this )
|
||||
{
|
||||
return members[i];
|
||||
return member;
|
||||
}
|
||||
}
|
||||
} else if( members[i] instanceof IASTFunctionDefinition ){
|
||||
IASTName name = ((IASTFunctionDefinition) members[i]).getDeclarator().getName();
|
||||
} else if( member instanceof IASTFunctionDefinition ){
|
||||
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition) member).getDeclarator();
|
||||
IASTName name = CPPVisitor.findInnermostDeclarator(declarator).getName();
|
||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||
name.resolveBinding() == this )
|
||||
{
|
||||
return members[i];
|
||||
return member;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,10 +143,10 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
|
||||
IASTDeclaration [] members = cls.getMembers();
|
||||
ICPPASTVisibilityLabel vis = null;
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
if( members[i] instanceof ICPPASTVisibilityLabel )
|
||||
vis = (ICPPASTVisibilityLabel) members[i];
|
||||
else if( members[i] == decl )
|
||||
for (IASTDeclaration member : members) {
|
||||
if( member instanceof ICPPASTVisibilityLabel )
|
||||
vis = (ICPPASTVisibilityLabel) member;
|
||||
else if( member == decl )
|
||||
break;
|
||||
}
|
||||
if( vis != null ){
|
||||
|
@ -162,30 +162,23 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
return scope.getClassType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() {
|
||||
IASTNode node = (declarations != null && declarations.length > 0) ? declarations[0] : definition;
|
||||
if( node instanceof IASTDeclarator ){
|
||||
IASTName name = ((IASTDeclarator)node).getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
return CPPVisitor.getContainingScope( name );
|
||||
}
|
||||
return CPPVisitor.getContainingScope( node );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IASTName getASTName() {
|
||||
IASTName name= definition != null ? definition.getName() : declarations[0].getName();
|
||||
if( name instanceof ICPPASTQualifiedName ){
|
||||
final IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
return ns[ns.length - 1];
|
||||
IASTDeclarator dtor= (declarations != null && declarations.length > 0) ? declarations[0] : definition;
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
IASTName name= dtor.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ ns.length - 1 ];
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScope getScope() {
|
||||
return CPPVisitor.getContainingScope(getASTName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isVirtual()
|
||||
*/
|
||||
|
|
|
@ -9,9 +9,6 @@
|
|||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 31, 2005
|
||||
*/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
|
@ -75,7 +72,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
|||
if( decl instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
IASTName name = CPPVisitor.getMostNestedDeclarator( dtor ).getName();
|
||||
IASTName name = CPPVisitor.findInnermostDeclarator(dtor).getName();
|
||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||
name.resolveBinding() == this )
|
||||
{
|
||||
|
@ -83,7 +80,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
|||
}
|
||||
}
|
||||
} 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 ) &&
|
||||
name.resolveBinding() == this )
|
||||
{
|
||||
|
|
|
@ -72,8 +72,7 @@ class ClassTypeMixin {
|
|||
}
|
||||
ObjectSet<IBinding> resultSet = new ObjectSet<IBinding>(2);
|
||||
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
IASTDeclaration decl = members[i];
|
||||
for (IASTDeclaration decl : members) {
|
||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||
|
||||
|
@ -84,9 +83,10 @@ class ClassTypeMixin {
|
|||
if( declSpec instanceof ICPPASTElaboratedTypeSpecifier && dtors.length == 0 ){
|
||||
resultSet.put( ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding() );
|
||||
} else {
|
||||
for( int j = 0; j < dtors.length; j++ ){
|
||||
if( dtors[j] == null ) break;
|
||||
resultSet.put( dtors[j].getName().resolveBinding() );
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
if( dtor == null ) break;
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
resultSet.put( dtor.getName().resolveBinding() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,9 +94,9 @@ class ClassTypeMixin {
|
|||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition)decl).getDeclSpecifier();
|
||||
if( declSpec.isFriend() ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
resultSet.put( dtor.getName().resolveBinding() );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,8 @@ class ClassTypeMixin {
|
|||
ICPPClassScope scope = (ICPPClassScope) host.getCompositeScope();
|
||||
set.addAll( scope.getImplicitMethods() );
|
||||
ICPPBase [] bases = getBases();
|
||||
for ( int i = 0; i < bases.length; i++ ) {
|
||||
IBinding b = bases[i].getBaseClass();
|
||||
for (ICPPBase base : bases) {
|
||||
IBinding b = base.getBaseClass();
|
||||
if( b instanceof ICPPClassType )
|
||||
set.addAll( ((ICPPClassType)b).getMethods() );
|
||||
}
|
||||
|
@ -152,22 +152,22 @@ class ClassTypeMixin {
|
|||
ICPPField [] result = null;
|
||||
|
||||
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
||||
for ( int i = 0; i < decls.length; i++ ) {
|
||||
if( decls[i] instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decls[i]).getDeclarators();
|
||||
for ( int j = 0; j < dtors.length; j++ ) {
|
||||
binding = dtors[j].getName().resolveBinding();
|
||||
for (IASTDeclaration decl : decls) {
|
||||
if( decl instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding();
|
||||
if( binding instanceof ICPPField )
|
||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, binding );
|
||||
}
|
||||
} else if( decls[i] instanceof ICPPASTUsingDeclaration ){
|
||||
IASTName n = ((ICPPASTUsingDeclaration)decls[i]).getName();
|
||||
} else if( decl instanceof ICPPASTUsingDeclaration ){
|
||||
IASTName n = ((ICPPASTUsingDeclaration)decl).getName();
|
||||
binding = n.resolveBinding();
|
||||
if( binding instanceof ICPPUsingDeclaration ){
|
||||
IBinding [] bs = ((ICPPUsingDeclaration)binding).getDelegates();
|
||||
for ( int j = 0; j < bs.length; j++ ) {
|
||||
if( bs[j] instanceof ICPPField )
|
||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, bs[j] );
|
||||
for (IBinding element : bs) {
|
||||
if( element instanceof ICPPField )
|
||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, element );
|
||||
}
|
||||
} else if( binding instanceof ICPPField ) {
|
||||
result = (ICPPField[]) ArrayUtil.append( ICPPField.class, result, binding );
|
||||
|
@ -189,8 +189,8 @@ class ClassTypeMixin {
|
|||
|
||||
ICPPMethod[] methods = getDeclaredMethods();
|
||||
ICPPBase [] bases = getBases();
|
||||
for ( int i = 0; i < bases.length; i++ ) {
|
||||
IBinding b = bases[i].getBaseClass();
|
||||
for (ICPPBase base : bases) {
|
||||
IBinding b = base.getBaseClass();
|
||||
if( b instanceof ICPPClassType )
|
||||
methods = (ICPPMethod[]) ArrayUtil.addAll( ICPPMethod.class, methods, ((ICPPClassType)b).getAllDeclaredMethods() );
|
||||
}
|
||||
|
@ -210,20 +210,19 @@ class ClassTypeMixin {
|
|||
ICPPMethod [] result = null;
|
||||
|
||||
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
||||
for ( int i = 0; i < decls.length; i++ ) {
|
||||
IASTDeclaration decl = decls[i];
|
||||
for (IASTDeclaration decl : decls) {
|
||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||
if( decl instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
for ( int j = 0; j < dtors.length; j++ ) {
|
||||
binding = dtors[j].getName().resolveBinding();
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
binding = CPPVisitor.findInnermostDeclarator(dtor).getName().resolveBinding();
|
||||
if( binding instanceof ICPPMethod)
|
||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||
}
|
||||
} else if( decl instanceof IASTFunctionDefinition ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
dtor = CPPVisitor.getMostNestedDeclarator( dtor );
|
||||
dtor = CPPVisitor.findInnermostDeclarator(dtor);
|
||||
binding = dtor.getName().resolveBinding();
|
||||
if( binding instanceof ICPPMethod ){
|
||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||
|
@ -233,9 +232,9 @@ class ClassTypeMixin {
|
|||
binding = n.resolveBinding();
|
||||
if( binding instanceof ICPPUsingDeclaration ){
|
||||
IBinding [] bs = ((ICPPUsingDeclaration)binding).getDelegates();
|
||||
for ( int j = 0; j < bs.length; j++ ) {
|
||||
if( bs[j] instanceof ICPPMethod )
|
||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, bs[j] );
|
||||
for (IBinding element : bs) {
|
||||
if( element instanceof ICPPMethod )
|
||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, element );
|
||||
}
|
||||
} else if( binding instanceof ICPPMethod ) {
|
||||
result = (ICPPMethod[]) ArrayUtil.append( ICPPMethod.class, result, binding );
|
||||
|
@ -263,18 +262,19 @@ class ClassTypeMixin {
|
|||
return ((CPPClassScope)scope).getConstructors( true );
|
||||
|
||||
IASTDeclaration [] members = host.getCompositeTypeSpecifier().getMembers();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
IASTDeclaration decl = members[i];
|
||||
for (IASTDeclaration decl : members) {
|
||||
if( decl instanceof ICPPASTTemplateDeclaration )
|
||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||
if( decl instanceof IASTSimpleDeclaration ){
|
||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||
for( int j = 0; j < dtors.length; j++ ){
|
||||
if( dtors[j] == null ) break;
|
||||
ASTInternal.addName(scope, dtors[j].getName() );
|
||||
for (IASTDeclarator dtor : dtors) {
|
||||
if( dtor == null ) break;
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
ASTInternal.addName(scope, dtor.getName() );
|
||||
}
|
||||
} else if( decl instanceof IASTFunctionDefinition ){
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)decl).getDeclarator();
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
ASTInternal.addName(scope, dtor.getName() );
|
||||
}
|
||||
}
|
||||
|
@ -295,8 +295,7 @@ class ClassTypeMixin {
|
|||
ICPPClassType [] result = null;
|
||||
|
||||
IASTDeclaration [] decls = host.getCompositeTypeSpecifier().getMembers();
|
||||
for ( int i = 0; i < decls.length; i++ ) {
|
||||
IASTDeclaration decl = decls[i];
|
||||
for (IASTDeclaration decl : decls) {
|
||||
while( decl instanceof ICPPASTTemplateDeclaration )
|
||||
decl = ((ICPPASTTemplateDeclaration)decl).getDeclaration();
|
||||
if( decl instanceof IASTSimpleDeclaration ){
|
||||
|
@ -328,8 +327,8 @@ class ClassTypeMixin {
|
|||
|
||||
IField[] fields = getDeclaredFields();
|
||||
ICPPBase [] bases = getBases();
|
||||
for ( int i = 0; i < bases.length; i++ ) {
|
||||
IBinding b = bases[i].getBaseClass();
|
||||
for (ICPPBase base : bases) {
|
||||
IBinding b = base.getBaseClass();
|
||||
if( b instanceof ICPPClassType )
|
||||
fields = (IField[]) ArrayUtil.addAll( IField.class, fields, ((ICPPClassType)b).getFields() );
|
||||
}
|
||||
|
@ -339,10 +338,10 @@ class ClassTypeMixin {
|
|||
public IField findField(String name) throws DOMException {
|
||||
IBinding [] bindings = CPPSemantics.findBindings( host.getCompositeScope(), name, true );
|
||||
IField field = null;
|
||||
for ( int i = 0; i < bindings.length; i++ ) {
|
||||
if( bindings[i] instanceof IField ){
|
||||
for (IBinding binding : bindings) {
|
||||
if( binding instanceof IField ){
|
||||
if( field == null )
|
||||
field = (IField) bindings[i];
|
||||
field = (IField) binding;
|
||||
else {
|
||||
IASTNode[] declarations= host.getDeclarations();
|
||||
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.IASTSimpleDeclSpecifier;
|
||||
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.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
|
@ -2508,15 +2507,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
if (needFunctionBody) {
|
||||
if (declarators.length != 1)
|
||||
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);
|
||||
return functionDefinition(firstOffset, declSpec, declarators, hasFunctionTryBlock);
|
||||
}
|
||||
|
||||
// no function body
|
||||
|
@ -2542,18 +2533,27 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
|
||||
IASTDeclarator declarator, boolean hasFunctionTryBlock)
|
||||
throws EndOfFileException, BacktrackException {
|
||||
IASTDeclarator[] dtors, boolean hasFunctionTryBlock) 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) {
|
||||
List<ICPPASTConstructorChainInitializer> constructorChain= new ArrayList<ICPPASTConstructorChainInitializer>(DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE);
|
||||
ctorInitializer(constructorChain);
|
||||
if (!constructorChain.isEmpty() && declarator instanceof ICPPASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator fd = (ICPPASTFunctionDeclarator) declarator;
|
||||
if (!constructorChain.isEmpty()) {
|
||||
for (ICPPASTConstructorChainInitializer initializer : constructorChain) {
|
||||
fd.addConstructorToChain(initializer);
|
||||
fdtor.addConstructorToChain(initializer);
|
||||
}
|
||||
// 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) {
|
||||
List<ICPPASTCatchHandler> handlers = new ArrayList<ICPPASTCatchHandler>(DEFAULT_CATCH_HANDLER_LIST_SIZE);
|
||||
catchHandlerSequence(handlers);
|
||||
if (!handlers.isEmpty() && declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
|
||||
ICPPASTFunctionTryBlockDeclarator tbd= (ICPPASTFunctionTryBlockDeclarator) declarator;
|
||||
if (!handlers.isEmpty() && fdtor instanceof ICPPASTFunctionTryBlockDeclarator) {
|
||||
ICPPASTFunctionTryBlockDeclarator tbd= (ICPPASTFunctionTryBlockDeclarator) fdtor;
|
||||
for (ICPPASTCatchHandler catchHandler : handlers) {
|
||||
tbd.addCatchHandler(catchHandler);
|
||||
}
|
||||
|
@ -2575,7 +2575,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
|
||||
funcDefinition.setDeclSpecifier(declSpec);
|
||||
funcDefinition.setDeclarator((IASTStandardFunctionDeclarator) declarator);
|
||||
funcDefinition.setDeclarator(fdtor);
|
||||
funcDefinition.setBody(body);
|
||||
|
||||
((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, endOffset-firstOffset);
|
||||
|
|
|
@ -1335,8 +1335,7 @@ public class CPPSemantics {
|
|||
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
||||
if (!declSpec.isFriend()) {
|
||||
for (IASTDeclarator declarator : declarators) {
|
||||
while (declarator.getNestedDeclarator() != null)
|
||||
declarator = declarator.getNestedDeclarator();
|
||||
declarator= CPPVisitor.findInnermostDeclarator(declarator);
|
||||
IASTName declaratorName = declarator.getName();
|
||||
ASTInternal.addName(scope, declaratorName);
|
||||
if (!data.typesOnly || simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) {
|
||||
|
@ -1452,7 +1451,7 @@ public class CPPSemantics {
|
|||
IASTFunctionDeclarator declarator = functionDef.getDeclarator();
|
||||
|
||||
//check the function itself
|
||||
IASTName declName = declarator.getName();
|
||||
IASTName declName = CPPVisitor.findInnermostDeclarator(declarator).getName();
|
||||
ASTInternal.addName(scope, declName);
|
||||
|
||||
if (!data.typesOnly && nameMatches(data, declName, scope)) {
|
||||
|
@ -2301,8 +2300,7 @@ public class CPPSemantics {
|
|||
node = node.getParent();
|
||||
}
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition)node).getDeclarator();
|
||||
while (dtor.getNestedDeclarator() != null)
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
IBinding binding = dtor.getName().resolveBinding();
|
||||
if (binding instanceof IFunction) {
|
||||
try {
|
||||
|
|
|
@ -177,14 +177,12 @@ public class CPPTemplates {
|
|||
}
|
||||
} else {
|
||||
IASTDeclarator dtor = dtors[0];
|
||||
while (dtor.getNestedDeclarator() != null)
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
name = dtor.getName();
|
||||
}
|
||||
} else if (decl instanceof IASTFunctionDefinition) {
|
||||
IASTDeclarator dtor = ((IASTFunctionDefinition) decl).getDeclarator();
|
||||
while (dtor.getNestedDeclarator() != null)
|
||||
dtor = dtor.getNestedDeclarator();
|
||||
dtor= CPPVisitor.findInnermostDeclarator(dtor);
|
||||
name = dtor.getName();
|
||||
}
|
||||
if (name == null)
|
||||
|
@ -940,9 +938,7 @@ public class CPPTemplates {
|
|||
}
|
||||
} else if (nestedDecl instanceof IASTFunctionDefinition) {
|
||||
IASTDeclarator declarator = ((IASTFunctionDefinition) nestedDecl).getDeclarator();
|
||||
while (declarator.getNestedDeclarator() != null) {
|
||||
declarator= declarator.getNestedDeclarator();
|
||||
}
|
||||
declarator= CPPVisitor.findInnermostDeclarator(declarator);
|
||||
name = declarator.getName();
|
||||
}
|
||||
if (name != null) {
|
||||
|
|
|
@ -515,28 +515,14 @@ public class CPPVisitor {
|
|||
return null;
|
||||
}
|
||||
private static IBinding createBinding(IASTDeclarator declarator) {
|
||||
IASTNode parent = declarator.getParent();
|
||||
while (parent instanceof IASTDeclarator) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
while (declarator.getNestedDeclarator() != null)
|
||||
declarator = declarator.getNestedDeclarator();
|
||||
IASTNode parent = findOutermostDeclarator(declarator).getParent();
|
||||
declarator= findInnermostDeclarator(declarator);
|
||||
|
||||
IASTFunctionDeclarator funcDeclarator= null;
|
||||
IASTNode tmpNode= declarator;
|
||||
do {
|
||||
if (tmpNode instanceof IASTFunctionDeclarator) {
|
||||
funcDeclarator= (IASTFunctionDeclarator) tmpNode;
|
||||
break;
|
||||
}
|
||||
if (((IASTDeclarator) tmpNode).getPointerOperators().length > 0 ||
|
||||
tmpNode.getPropertyInParent() != IASTDeclarator.NESTED_DECLARATOR) {
|
||||
break;
|
||||
}
|
||||
tmpNode= tmpNode.getParent();
|
||||
final IASTDeclarator typeRelevantDtor= findTypeRelevantDeclarator(declarator);
|
||||
if (typeRelevantDtor instanceof IASTFunctionDeclarator) {
|
||||
funcDeclarator= (IASTFunctionDeclarator) typeRelevantDtor;
|
||||
}
|
||||
while (tmpNode instanceof IASTDeclarator);
|
||||
|
||||
IASTName name= declarator.getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
|
@ -587,10 +573,10 @@ public class CPPVisitor {
|
|||
ICPPASTParameterDeclaration param = (ICPPASTParameterDeclaration) parent;
|
||||
parent = param.getParent();
|
||||
if (parent instanceof IASTStandardFunctionDeclarator) {
|
||||
IASTStandardFunctionDeclarator fDtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||
if (hasNestedPointerOperator(fDtor))
|
||||
IASTStandardFunctionDeclarator fdtor = (IASTStandardFunctionDeclarator) param.getParent();
|
||||
if (hasNestedPointerOperator(fdtor))
|
||||
return null;
|
||||
IBinding temp = fDtor.getName().resolveBinding();
|
||||
IBinding temp = fdtor.getName().resolveBinding();
|
||||
if (temp instanceof ICPPInternalFunction) {
|
||||
binding = ((ICPPInternalFunction) temp).resolveParameter(param);
|
||||
} 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
|
||||
// redeclares the target type:
|
||||
// typedef struct S S;
|
||||
IType targetType= CPPVisitor.createType(declarator);
|
||||
IType targetType= createType(declarator);
|
||||
CPPTypedef td= new CPPTypedef(name);
|
||||
td.setType(targetType);
|
||||
binding = td;
|
||||
|
@ -743,7 +729,7 @@ public class CPPVisitor {
|
|||
if (declarator == null || !(declarator instanceof IASTFunctionDeclarator))
|
||||
return false;
|
||||
|
||||
IASTName name = declarator.getName();
|
||||
IASTName name = findInnermostDeclarator(declarator).getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] names = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = names[names.length - 1];
|
||||
|
@ -752,7 +738,7 @@ public class CPPVisitor {
|
|||
return false;
|
||||
|
||||
IASTDeclSpecifier declSpec = null;
|
||||
IASTNode parent = declarator.getParent();
|
||||
IASTNode parent = findOutermostDeclarator(declarator).getParent();
|
||||
if (parent instanceof IASTSimpleDeclaration) {
|
||||
declSpec = ((IASTSimpleDeclaration)parent).getDeclSpecifier();
|
||||
} else if (parent instanceof IASTFunctionDefinition) {
|
||||
|
@ -874,7 +860,7 @@ public class CPPVisitor {
|
|||
n = ns[ns.length - 1];
|
||||
}
|
||||
|
||||
return CPPVisitor.getContainingScope(n);
|
||||
return getContainingScope(n);
|
||||
}
|
||||
node = node.getParent();
|
||||
}
|
||||
|
@ -1011,7 +997,7 @@ public class CPPVisitor {
|
|||
scope = getContainingScope((IASTStatement)parent);
|
||||
} else if (parent instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDeclarator fnDeclarator = ((IASTFunctionDefinition) parent).getDeclarator();
|
||||
IASTName name = fnDeclarator.getName();
|
||||
IASTName name = findInnermostDeclarator(fnDeclarator).getName();
|
||||
if (name instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)name).getNames();
|
||||
name = ns[ns.length -1];
|
||||
|
@ -1779,7 +1765,7 @@ public class CPPVisitor {
|
|||
}
|
||||
if (node instanceof IASTFunctionDeclarator) {
|
||||
ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node;
|
||||
IASTName fName = dtor.getName();
|
||||
IASTName fName = findInnermostDeclarator(dtor).getName();
|
||||
if (fName instanceof ICPPASTQualifiedName) {
|
||||
IASTName[] ns = ((ICPPASTQualifiedName)fName).getNames();
|
||||
fName = ns[ns.length - 1];
|
||||
|
@ -2180,15 +2166,6 @@ public class CPPVisitor {
|
|||
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) {
|
||||
CollectProblemsAction action = new CollectProblemsAction();
|
||||
tu.accept(action);
|
||||
|
@ -2444,23 +2421,20 @@ public class CPPVisitor {
|
|||
/**
|
||||
* Returns the outermost declarator the given <code>declarator</code> nests within, or
|
||||
* <code>declarator</code> itself.
|
||||
* @since 5.0
|
||||
*/
|
||||
public static IASTDeclarator findOutermostDeclarator(IASTDeclarator declarator) {
|
||||
while(true) {
|
||||
IASTNode parent= declarator.getParent();
|
||||
if (parent instanceof IASTDeclarator) {
|
||||
declarator= (IASTDeclarator) parent;
|
||||
} else {
|
||||
return declarator;
|
||||
}
|
||||
IASTDeclarator outermost= null;
|
||||
IASTNode candidate= declarator;
|
||||
while(candidate instanceof IASTDeclarator) {
|
||||
outermost= (IASTDeclarator) candidate;
|
||||
candidate= outermost.getParent();
|
||||
}
|
||||
return outermost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the innermost declarator nested within the given <code>declarator</code>, or
|
||||
* <code>declarator</code> itself.
|
||||
* @since 5.1
|
||||
*/
|
||||
public static IASTDeclarator findInnermostDeclarator(IASTDeclarator declarator) {
|
||||
IASTDeclarator innermost= null;
|
||||
|
@ -2473,7 +2447,6 @@ public class CPPVisitor {
|
|||
|
||||
/**
|
||||
* Searches for the innermost declarator that contributes the the type declared.
|
||||
* @since 5.1
|
||||
*/
|
||||
public static IASTDeclarator findTypeRelevantDeclarator(IASTDeclarator declarator) {
|
||||
IASTDeclarator result= findInnermostDeclarator(declarator);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@ -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.IASTDeclaration;
|
||||
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.IASTProblemDeclaration;
|
||||
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.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
|
||||
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;
|
||||
|
||||
|
||||
|
@ -278,7 +279,7 @@ public class DeclarationWriter extends NodeWriter{
|
|||
}else {
|
||||
scribe.printSpace();
|
||||
}
|
||||
IASTFunctionDeclarator declarator = funcDef.getDeclarator();
|
||||
IASTDeclarator declarator = CPPVisitor.findOutermostDeclarator(funcDef.getDeclarator());
|
||||
declarator.accept(visitor);
|
||||
scribe.newLine();
|
||||
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.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.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||
|
@ -109,7 +110,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
sm.worked(1);
|
||||
if(methodToHideDecl instanceof IASTFunctionDefinition) {
|
||||
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)) {
|
||||
initStatus.addFatalError(Messages.HideMethodRefactoring_CanOnlyHideMethods);
|
||||
return initStatus;
|
||||
|
@ -215,7 +216,7 @@ public class HideMethodRefactoring extends CRefactoring {
|
|||
IASTNode parent = compStat.getParent();
|
||||
if(parent instanceof IASTFunctionDefinition) {
|
||||
IASTDeclarator declarator = ((IASTFunctionDefinition)parent).getDeclarator();
|
||||
IASTName declaratorName = getLastName(declarator);
|
||||
IASTName declaratorName = getLastName(CPPVisitor.findInnermostDeclarator(declarator));
|
||||
|
||||
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.CPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.refactoring.MethodContext;
|
||||
|
||||
|
@ -108,7 +109,7 @@ public class NodeHelper {
|
|||
found = true;
|
||||
context.setType(MethodContext.ContextType.FUNCTION);
|
||||
} else if (node instanceof IASTFunctionDefinition){
|
||||
name=((IASTFunctionDefinition)node).getDeclarator().getName();
|
||||
name=CPPVisitor.findInnermostDeclarator(((IASTFunctionDefinition)node).getDeclarator()).getName();
|
||||
found = true;
|
||||
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.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.model.ASTCache;
|
||||
|
||||
|
@ -230,7 +231,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
if (declaration instanceof IASTFunctionDefinition) {
|
||||
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator();
|
||||
if (declarator != null) {
|
||||
fFunction= new String(declarator.getName().toCharArray());
|
||||
fFunction= new String(CVisitor.findInnermostDeclarator(declarator).getName().toCharArray());
|
||||
fLevel= 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue