1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fixed 46246 - C Scoping rules

Use a collator to sort the symbol table
This commit is contained in:
Andrew Niefer 2004-04-13 15:31:15 +00:00
parent 52d4876576
commit 9a2fdef54b
4 changed files with 54 additions and 4 deletions

View file

@ -1,3 +1,6 @@
2004-04-13 Andrew Niefer
added parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.testBug46246()
2004-04-12
Updated search tests to work with new Enumerator type, added a derived search test
2004-04-11 John Camelon

View file

@ -1450,4 +1450,26 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
assertFalse( baseClauses.hasNext() );
assertEquals( baseClause.getParentClassSpecifier(), AltG2 );
}
public void testBug46246() throws Exception
{
Writer writer = new StringWriter();
writer.write( "struct A { ");
writer.write( " struct B { int ab; } b; ");
writer.write( " int a; ");
writer.write( "}; ");
writer.write( "struct A a1; ");
writer.write( "struct B b1; ");
Iterator i = parse( writer.toString(), true, ParserLanguage.C ).getDeclarations();
IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
IASTVariable a1 = (IASTVariable) i.next();
IASTVariable b1 = (IASTVariable) i.next();
i = getDeclarations( A );
IASTField b = (IASTField) i.next();
IASTField a = (IASTField) i.next();
IASTClassSpecifier B = (IASTClassSpecifier) b.getAbstractDeclaration().getTypeSpecifier();
assertAllReferences( 2, createTaskList( new Task( A ), new Task( B ) ) );
}
}

View file

@ -1,3 +1,7 @@
2004-04-13 Andrew Niefer
fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=46246
modified symbol table sorting to use a collator instead of String.compare()
2004-04-11 John Camelon
Fixed https://bugs.eclipse.org/bugs/show_bug.cgi?id=55785.
Fix required update to ISourceElementRequestor interface : clients updated accordingly.

View file

@ -14,6 +14,7 @@
package org.eclipse.cdt.internal.core.parser.pst;
import java.text.Collator;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@ -26,6 +27,7 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.IASTMember;
@ -176,6 +178,13 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
}
}
//in C, structs, unions, enums don't nest
if( getSymbolTable().getLanguage() == ParserLanguage.C ){
if( obj.isType( TypeInfo.t_struct, TypeInfo.t_enumeration ) ){
containing = getScopeForCTag( containing );
}
}
//14.6.1-4 A Template parameter shall not be redeclared within its scope.
if( isTemplateMember() || isType( TypeInfo.t_template ) ){
if( TemplateEngine.alreadyHasTemplateParameter( this, obj.getName() ) ){
@ -918,7 +927,16 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
return false;
}
private IContainerSymbol getScopeForCTag( IContainerSymbol container ){
while( !container.isType( TypeInfo.t_namespace ) &&
!container.isType( TypeInfo.t_function ) &&
!container.isType( TypeInfo.t_block ) )
{
container = container.getContainingSymbol();
}
return container;
}
protected List getContents(){
if(_contents == null ){
_contents = new LinkedList();
@ -927,7 +945,6 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
}
public Iterator getContentsIterator(){
//return getContents().iterator();
return new ContentsIterator( getContents().iterator() );
}
@ -1069,10 +1086,14 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
}
static protected class SymbolTableComparator implements Comparator{
static final private Collator collator = Collator.getInstance();
static { collator.setStrength( Collator.PRIMARY ); }
public int compare( Object o1, Object o2 ){
int result = ((String) o1).compareToIgnoreCase( (String) o2 );
int result = collator.compare( o1, o2 );
if( result == 0 ){
return ((String) o1).compareTo( (String) o2 );
collator.setStrength( Collator.IDENTICAL );
result = collator.compare( o1, o2 );
collator.setStrength( Collator.PRIMARY );
}
return result;
}