mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Fixed Bug 84371 - AST problems with ICPPASTQualifiedName ::f
This commit is contained in:
parent
30277a9b62
commit
cc8d114f90
7 changed files with 1137 additions and 1055 deletions
File diff suppressed because it is too large
Load diff
|
@ -498,7 +498,7 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
CPPNameCollector col = new CPPNameCollector();
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
CPPVisitor.visitTranslationUnit( tu, col );
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
assertEquals( col.size(), 13 );
|
assertEquals( col.size(), 12 );
|
||||||
ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding();
|
ICPPNamespace N = (ICPPNamespace) col.getName(0).resolveBinding();
|
||||||
IFunction foo = (IFunction) col.getName(1).resolveBinding();
|
IFunction foo = (IFunction) col.getName(1).resolveBinding();
|
||||||
ICPPClassType A = (ICPPClassType) col.getName(3).resolveBinding();
|
ICPPClassType A = (ICPPClassType) col.getName(3).resolveBinding();
|
||||||
|
@ -1682,13 +1682,13 @@ public class CompleteParser2Tests extends TestCase {
|
||||||
CPPNameCollector col = new CPPNameCollector();
|
CPPNameCollector col = new CPPNameCollector();
|
||||||
CPPVisitor.visitTranslationUnit( tu, col );
|
CPPVisitor.visitTranslationUnit( tu, col );
|
||||||
|
|
||||||
assertEquals( col.size(), 11 );
|
assertEquals( col.size(), 10 );
|
||||||
|
|
||||||
ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding();
|
ICPPClassType s = (ICPPClassType) col.getName(0).resolveBinding();
|
||||||
ICPPClassType s2 = (ICPPClassType) col.getName(3).resolveBinding();
|
ICPPClassType s2 = (ICPPClassType) col.getName(3).resolveBinding();
|
||||||
|
|
||||||
ICPPClassType ref1 = (ICPPClassType) col.getName(5).resolveBinding();
|
ICPPClassType ref1 = (ICPPClassType) col.getName(5).resolveBinding();
|
||||||
ICPPClassType ref2 = (ICPPClassType) col.getName( 9 ).resolveBinding();
|
ICPPClassType ref2 = (ICPPClassType) col.getName( 8 ).resolveBinding();
|
||||||
|
|
||||||
assertSame( s, ref2 );
|
assertSame( s, ref2 );
|
||||||
assertSame( s2, ref1 );
|
assertSame( s2, ref1 );
|
||||||
|
|
|
@ -21,4 +21,7 @@ public interface ICPPASTQualifiedName extends IASTName {
|
||||||
public static final ASTNodeProperty SEGMENT_NAME = new ASTNodeProperty( "Segment"); //$NON-NLS-1$
|
public static final ASTNodeProperty SEGMENT_NAME = new ASTNodeProperty( "Segment"); //$NON-NLS-1$
|
||||||
public void addName( IASTName name );
|
public void addName( IASTName name );
|
||||||
public IASTName [] getNames();
|
public IASTName [] getNames();
|
||||||
|
|
||||||
|
public boolean isFullyQualified();
|
||||||
|
public void setFullyQualified( boolean value );
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
|
||||||
private int currentIndex = 0;
|
private int currentIndex = 0;
|
||||||
private IASTName [] names = null;
|
private IASTName [] names = null;
|
||||||
private static final int DEFAULT_NAMES_LIST_SIZE = 4;
|
private static final int DEFAULT_NAMES_LIST_SIZE = 4;
|
||||||
|
private boolean value;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#getNames()
|
||||||
|
@ -138,5 +139,19 @@ public class CPPASTQualifiedName extends CPPASTNode implements ICPPASTQualifiedN
|
||||||
return nameArray;
|
return nameArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#isFullyQualified()
|
||||||
|
*/
|
||||||
|
public boolean isFullyQualified() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName#setFullyQualified(boolean)
|
||||||
|
*/
|
||||||
|
public void setFullyQualified(boolean value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
import org.eclipse.cdt.core.parser.Keywords;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||||
|
@ -316,17 +315,20 @@ public class CPPSemantics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static protected IBinding resolveBinding( IASTName name ){
|
static protected IBinding resolveBinding( IASTName name ){
|
||||||
if( name.toCharArray().length == 2 && CharArrayUtils.equals( name.toCharArray(), Keywords.cpCOLONCOLON ) ){
|
if( name instanceof ICPPASTQualifiedName && ((ICPPASTQualifiedName)name).isFullyQualified() )
|
||||||
IASTNode node = name.getParent();
|
return ((ICPPASTTranslationUnit)name.getTranslationUnit()).resolveBinding();
|
||||||
if( node instanceof ICPPASTQualifiedName ){
|
|
||||||
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) node;
|
// if( name.toCharArray().length == 2 && CharArrayUtils.equals( name.toCharArray(), Keywords.cpCOLONCOLON ) ){
|
||||||
if( qname.getNames()[0] == name ){
|
// IASTNode node = name.getParent();
|
||||||
//translation unit
|
// if( node instanceof ICPPASTQualifiedName ){
|
||||||
return ((ICPPASTTranslationUnit)node.getTranslationUnit()).resolveBinding();
|
// ICPPASTQualifiedName qname = (ICPPASTQualifiedName) node;
|
||||||
}
|
// if( qname.getNames()[0] == name ){
|
||||||
}
|
// //translation unit
|
||||||
return null;
|
// return ((ICPPASTTranslationUnit)node.getTranslationUnit()).resolveBinding();
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
//1: get some context info off of the name to figure out what kind of lookup we want
|
//1: get some context info off of the name to figure out what kind of lookup we want
|
||||||
LookupData data = createLookupData( name );
|
LookupData data = createLookupData( name );
|
||||||
|
|
|
@ -519,6 +519,10 @@ public class CPPVisitor {
|
||||||
return ((ICPPNamespace)binding).getNamespaceScope();
|
return ((ICPPNamespace)binding).getNamespaceScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( ((ICPPASTQualifiedName)parent).isFullyQualified() )
|
||||||
|
{
|
||||||
|
return parent.getTranslationUnit().getScope();
|
||||||
|
}
|
||||||
} else if( parent instanceof ICPPASTFieldReference ){
|
} else if( parent instanceof ICPPASTFieldReference ){
|
||||||
IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner();
|
IASTExpression owner = ((ICPPASTFieldReference)parent).getFieldOwner();
|
||||||
IType type = CPPSemantics.getUltimateType( getExpressionType( owner ) );
|
IType type = CPPSemantics.getUltimateType( getExpressionType( owner ) );
|
||||||
|
|
|
@ -2487,11 +2487,21 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
result.setOffsetAndLength(duple.getStartOffset(), duple.getEndOffset()
|
result.setOffsetAndLength(duple.getStartOffset(), duple.getEndOffset()
|
||||||
- duple.getStartOffset());
|
- duple.getStartOffset());
|
||||||
ITokenDuple[] segments = duple.getSegments();
|
ITokenDuple[] segments = duple.getSegments();
|
||||||
for (int i = 0; i < segments.length; ++i) {
|
int startingValue = 0;
|
||||||
|
if( segments.length > 0 &&
|
||||||
|
segments[0] instanceof IToken &&
|
||||||
|
((IToken)segments[0]).getType() == IToken.tCOLONCOLON )
|
||||||
|
{
|
||||||
|
++startingValue;
|
||||||
|
result.setFullyQualified(true);
|
||||||
|
}
|
||||||
|
for (int i = startingValue; i < segments.length; ++i) {
|
||||||
IASTName subName = null;
|
IASTName subName = null;
|
||||||
// take each name and add it to the result
|
// take each name and add it to the result
|
||||||
if (segments[i] instanceof IToken)
|
if (segments[i] instanceof IToken)
|
||||||
|
{
|
||||||
subName = createName((IToken) segments[i]);
|
subName = createName((IToken) segments[i]);
|
||||||
|
}
|
||||||
else if (segments[i].getTemplateIdArgLists() == null)
|
else if (segments[i].getTemplateIdArgLists() == null)
|
||||||
subName = createName(segments[i]);
|
subName = createName(segments[i]);
|
||||||
else
|
else
|
||||||
|
@ -2503,7 +2513,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
segments[i].getEndOffset() - segments[i].getStartOffset());
|
segments[i].getEndOffset() - segments[i].getStartOffset());
|
||||||
result.addName(subName);
|
result.addName(subName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue