1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

bug 87705

This commit is contained in:
Andrew Niefer 2005-03-11 19:26:00 +00:00
parent 5953c8a29f
commit 39ca877911
6 changed files with 41 additions and 10 deletions

View file

@ -2871,5 +2871,16 @@ public class AST2CPPTests extends AST2BaseTest {
assertTrue( t instanceof IGPPPointerToMemberType ); assertTrue( t instanceof IGPPPointerToMemberType );
assertTrue( ((IGPPPointerToMemberType) t).isRestrict() ); assertTrue( ((IGPPPointerToMemberType) t).isRestrict() );
} }
public void testBug87705() throws Exception {
IASTTranslationUnit tu = parse( "class A { friend class B::C; };", ParserLanguage.CPP, true ); //$NON-NLS-1$
CPPNameCollector col = new CPPNameCollector();
tu.accept(col);
IProblemBinding B = (IProblemBinding) col.getName(2).resolveBinding();
assertEquals( B.getID(), IProblemBinding.SEMANTIC_NAME_NOT_FOUND );
IProblemBinding C = (IProblemBinding) col.getName(3).resolveBinding();
assertEquals( C.getID(), IProblemBinding.SEMANTIC_BAD_SCOPE );
}
} }

View file

@ -31,7 +31,7 @@ public class DOMException extends Exception {
* *
*/ */
public DOMException( IProblemBinding problem ) { public DOMException( IProblemBinding problem ) {
super( problem != null ? problem.getMessage() : CPPSemantics.EMPTY_NAME ); super( CPPSemantics.EMPTY_NAME );
problemBinding = problem; problemBinding = problem;
} }
@ -43,4 +43,8 @@ public class DOMException extends Exception {
public IProblemBinding getProblem(){ public IProblemBinding getProblem(){
return problemBinding; return problemBinding;
} }
public String getMessage() {
return problemBinding.getMessage();
}
} }

View file

@ -93,5 +93,10 @@ public interface IProblemBinding extends IBinding, IScope, IType {
*/ */
public static final int SEMANTIC_LABEL_STATEMENT_NOT_FOUND = 0x009; public static final int SEMANTIC_LABEL_STATEMENT_NOT_FOUND = 0x009;
public static final int LAST_PROBLEM = SEMANTIC_LABEL_STATEMENT_NOT_FOUND; /**
* there was a problem creating the scope
*/
public static final int SEMANTIC_BAD_SCOPE = 0x00A;
public static final int LAST_PROBLEM = SEMANTIC_BAD_SCOPE;
} }

View file

@ -52,6 +52,7 @@ public class ProblemBinding implements IProblemBinding, IType, IScope {
errorMessages[SEMANTIC_DEFINITION_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.definitionNotFound"); //$NON-NLS-1$ errorMessages[SEMANTIC_DEFINITION_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.definitionNotFound"); //$NON-NLS-1$
errorMessages[SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound"); //$NON-NLS-1$ errorMessages[SEMANTIC_KNR_PARAMETER_DECLARATION_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound"); //$NON-NLS-1$
errorMessages[SEMANTIC_LABEL_STATEMENT_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.labelStatementNotFound"); //$NON-NLS-1$ errorMessages[SEMANTIC_LABEL_STATEMENT_NOT_FOUND - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.labelStatementNotFound"); //$NON-NLS-1$
errorMessages[SEMANTIC_BAD_SCOPE - 1] = ParserMessages.getString("ASTProblemFactory.error.semantic.dom.badScope"); //$NON-NLS-1$
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -68,7 +69,7 @@ public class ProblemBinding implements IProblemBinding, IType, IScope {
if (message != null) if (message != null)
return message; return message;
String msg = ( id >= 0 && id < LAST_PROBLEM ) ? errorMessages[ id - 1 ] : ""; //$NON-NLS-1$ String msg = ( id >= 0 && id <= LAST_PROBLEM ) ? errorMessages[ id - 1 ] : ""; //$NON-NLS-1$
if (arg != null) { if (arg != null) {
msg = MessageFormat.format(msg, new Object[] { new String(arg) }); msg = MessageFormat.format(msg, new Object[] { new String(arg) });

View file

@ -127,9 +127,11 @@ public class CPPVisitor {
{ {
binding = CPPSemantics.resolveBinding( name ); binding = CPPSemantics.resolveBinding( name );
if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName ){ if( binding instanceof IProblemBinding && parent instanceof ICPPASTQualifiedName ){
//if( ((IProblemBinding)binding).getID() == IProblemBinding.SEMANTIC_NAME_NOT_FOUND ){ IASTName [] ns = ((ICPPASTQualifiedName)parent).getNames();
if( ns[ ns.length - 1 ] == name )
parent = parent.getParent(); parent = parent.getParent();
//} else
return binding;
} else { } else {
return binding; return binding;
} }
@ -233,12 +235,19 @@ public class CPPVisitor {
IBinding binding = null; IBinding binding = null;
boolean mustBeSimple = true; boolean mustBeSimple = true;
boolean isFriend = false; boolean isFriend = false;
boolean qualified = false;
IASTName name = elabType.getName();
if( name instanceof ICPPASTQualifiedName ){
qualified = true;
IASTName [] ns = ((ICPPASTQualifiedName)name).getNames();
name = ns[ ns.length - 1 ];
}
if( parent instanceof IASTSimpleDeclaration ){ if( parent instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators(); IASTDeclarator [] dtors = ((IASTSimpleDeclaration)parent).getDeclarators();
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier(); ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration)parent).getDeclSpecifier();
isFriend = declSpec.isFriend() && dtors.length == 0; isFriend = declSpec.isFriend() && dtors.length == 0;
if( dtors.length > 0 || isFriend ){ if( dtors.length > 0 || isFriend ){
binding = CPPSemantics.resolveBinding( elabType.getName() ); binding = CPPSemantics.resolveBinding( name );
mustBeSimple = !isFriend; mustBeSimple = !isFriend;
} else { } else {
mustBeSimple = false; mustBeSimple = false;
@ -261,7 +270,7 @@ public class CPPVisitor {
if( mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName ) if( mustBeSimple && elabType.getName() instanceof ICPPASTQualifiedName )
return binding; return binding;
ICPPScope scope = (ICPPScope) getContainingScope( elabType ); ICPPScope scope = (ICPPScope) getContainingScope( name );
if( mustBeSimple ){ if( mustBeSimple ){
//3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains //3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
@ -273,7 +282,7 @@ public class CPPVisitor {
} }
} }
} }
if( scope instanceof ICPPClassScope && isFriend ){ if( scope instanceof ICPPClassScope && isFriend && !qualified ){
try { try {
while( scope instanceof ICPPClassScope ) while( scope instanceof ICPPClassScope )
scope = (ICPPScope) scope.getParent(); scope = (ICPPScope) scope.getParent();
@ -578,7 +587,7 @@ public class CPPVisitor {
} else if( binding instanceof IProblemBinding ){ } else if( binding instanceof IProblemBinding ){
if( binding instanceof ICPPScope ) if( binding instanceof ICPPScope )
return (IScope) binding; return (IScope) binding;
return new CPPScope.CPPScopeProblem( -1, names[i-1].toCharArray() ); return new CPPScope.CPPScopeProblem( IProblemBinding.SEMANTIC_BAD_SCOPE, names[i-1].toCharArray() );
} }
} }
else if( ((ICPPASTQualifiedName)parent).isFullyQualified() ) else if( ((ICPPASTQualifiedName)parent).isFullyQualified() )

View file

@ -80,3 +80,4 @@ ASTProblemFactory.error.semantic.pst.recursiveTemplateInstantiation=Possible inf
ASTProblemFactory.error.semantic.dom.definitionNotFound=A definition was not found for {0} ASTProblemFactory.error.semantic.dom.definitionNotFound=A definition was not found for {0}
ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound=A declaration was not found for the k&r parameter {0} ASTProblemFactory.error.semantic.dom.knrParameterDeclarationNotFound=A declaration was not found for the k&r parameter {0}
ASTProblemFactory.error.semantic.dom.labelStatementNotFound=A label statement was not found for the name {0} ASTProblemFactory.error.semantic.dom.labelStatementNotFound=A label statement was not found for the name {0}
ASTProblemFactory.error.semantic.dom.badScope=A scope could not be created to represent the name {0}