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

Patch for Hoda Amer

Core: 
        Solution to bug#43373: No reference to static member in definition  (Major) 
        Solution to bug#43371: constructor incorrectly marked private (Normal) 
Tests: 
        Added CompleteParseASTTest.testBug43373() 
        Added QuickParseASTTests.testBug43371() 
UI: 
        Solution to bug#43143: Naming of Code Assist Menus/Tab are not consistent 
        changed both names to Content Assist. No tests provided.
This commit is contained in:
John Camelon 2003-09-23 20:46:22 +00:00
parent 558e9619c2
commit ef856ea3e1
13 changed files with 213 additions and 27 deletions

View file

@ -1,3 +1,7 @@
2003-09-23 Hoda Amer
Added CompleteParseASTTest.testBug43373()
Added QuickParseASTTests.testBug43371()
2003-09-22 Bogdan Gheorghe
- modified CompletionProposalsTests, BaseSearchTest
to avoid using isEnabled for the IndexManager

View file

@ -773,5 +773,28 @@ public class CompleteParseASTTest extends CompleteParseBaseTest
for( int j =0; j < 4; ++j )
assertFalse( classOp.getNameOffset() == ((IASTReference)callback.getReferences().get(j)).getOffset() );
}
/**
* class A { static int x; } int A::x = 5;
*/
public void testBug43373() throws Exception
{
try { // This is to prove that there are no exceptions
// Used to cause AST Semantic exception
Iterator i = parse( "class A { static int x; }; int A::x = 5;" ).getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator j = getDeclarations(classA);
IASTField field1 = (IASTField) j.next();
// Note : this used to be considered a variable, not a field
IASTField field2 = (IASTField)i.next();
assertEquals( callback.getReferences().size(), 1 );
Iterator references = callback.getReferences().iterator();
assertEquals( ((IASTReference)references.next()).getReferencedElement(), classA );
assertTrue (field1.getVisiblity() == field2.getVisiblity());
}catch (Exception e){
fail();
}
}
}

View file

@ -1815,5 +1815,31 @@ public class QuickParseASTTests extends BaseASTTest
{
parse("int *restrict ip_fn (void);", true, true, ParserLanguage.C).getDeclarations().next();
}
/**
* Test code: struct Example { Example(); Example(int); ~Example();};
* Purpose: tests a declaration in a class scope.
*/
public void testBug43371 () throws Exception
{
// Parse and get the translaton unit
Writer code = new StringWriter();
code.write("struct Example { Example(); Example(int); ~Example();};");
IASTCompilationUnit cu = parse(code.toString());
Iterator i = cu.getDeclarations();
assertTrue(i.hasNext());
IASTAbstractTypeSpecifierDeclaration declaration =
(IASTAbstractTypeSpecifierDeclaration)i.next();
assertFalse(i.hasNext());
assertTrue( declaration.getTypeSpecifier() instanceof IASTClassSpecifier);
assertTrue(((IASTClassSpecifier)declaration.getTypeSpecifier()).getClassKind()== ASTClassKind.STRUCT);
Iterator j =((IASTClassSpecifier)declaration.getTypeSpecifier()).getDeclarations();
assertTrue(j.hasNext());
IASTMethod m1 = (IASTMethod)j.next();
IASTMethod m2 = (IASTMethod)j.next();
IASTMethod m3 = (IASTMethod)j.next();
assertFalse(j.hasNext());
assertTrue(m1.getVisiblity() == ASTAccessVisibility.PUBLIC);
assertTrue(m2.getVisiblity() == ASTAccessVisibility.PUBLIC);
assertTrue(m3.getVisiblity() == ASTAccessVisibility.PUBLIC);
}
}

View file

@ -521,6 +521,10 @@ public class CModelBuilder {
}
}
methodElement.setParameterTypes(parameterTypes);
methodElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) );
methodElement.setStatic(functionDeclaration.isStatic());
// Common settings for method declaration
methodElement.setVisibility(methodDeclaration.getVisiblity());
methodElement.setVolatile(methodDeclaration.isVolatile());
@ -535,15 +539,16 @@ public class CModelBuilder {
}
else // instance of IASTFunction
{
FunctionDeclaration functionElement = null;
if (functionDeclaration.hasFunctionBody())
{
// function
if(!isTemplate){
Function newElement = new Function( parent, name );
element = newElement;
functionElement = newElement;
} else {
FunctionTemplate newElement = new FunctionTemplate( parent, name );
element = newElement;
functionElement = newElement;
}
}
else
@ -551,17 +556,17 @@ public class CModelBuilder {
// functionDeclaration
if(!isTemplate){
FunctionDeclaration newElement = new FunctionDeclaration( parent, name );
element = newElement;
functionElement = newElement;
} else {
FunctionTemplate newElement = new FunctionTemplate( parent, name );
element = newElement;
functionElement = newElement;
}
}
functionElement.setParameterTypes(parameterTypes);
functionElement.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) );
functionElement.setStatic(functionDeclaration.isStatic());
element = functionElement;
}
element.setParameterTypes(parameterTypes);
element.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) );
element.setStatic(functionDeclaration.isStatic());
// add to parent
parent.addChild( element );

View file

@ -1,3 +1,7 @@
2003-09-23 Hoda Amer
Solution to bug#43373: No reference to static member in definition
Solution to bug#43371: constructor incorrectly marked private
2003-09-18 Andrew Niefer
- modified Symbol table interfaces to use Lists & Maps instead of LinkedList and HashMap
- fixed warnings in ParserSymbolTable

View file

@ -147,7 +147,7 @@ public interface IASTFactory
boolean isVolatile,
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isDefinition ) throws ASTSemanticException;
boolean isPureVirtual, List constructorChain, boolean isDefinition ) throws ASTSemanticException;
public IASTAbstractDeclaration createAbstractDeclaration(
boolean isConst,
boolean isVolatile,

View file

@ -468,7 +468,6 @@ public class DeclarationWrapper implements IDeclaratorOwner
virtual,
explicit,
declarator.isPureVirtual(),
ASTAccessVisibility.PUBLIC,
declarator.getConstructorMemberInitializers(), declarator.hasFunctionBody() );
}
/**

View file

@ -37,9 +37,9 @@ public class ASTField extends ASTVariable implements IASTField
* @param references
* @param visibility
*/
public ASTField(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int nameOffset, List references, IASTExpression constructorExpression, ASTAccessVisibility visibility)
public ASTField(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int nameOffset, List references, boolean previouslyDeclared, IASTExpression constructorExpression, ASTAccessVisibility visibility)
{
super( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, constructorExpression );
super( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, constructorExpression, previouslyDeclared );
this.visibility = visibility;
}

View file

@ -29,6 +29,7 @@ import org.eclipse.cdt.internal.core.parser.pst.TypeInfo;
*/
public class ASTVariable extends ASTSymbol implements IASTVariable
{
private final boolean previouslyDeclared;
private final IASTExpression constructorExpression;
protected final ASTReferenceStore referenceDelegate;
private final ASTQualifiedNamedElement qualifiedName;
@ -45,7 +46,7 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
* @param nameOffset
* @param references
*/
public ASTVariable(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int nameOffset, List references, IASTExpression constructorExpression )
public ASTVariable(ISymbol newSymbol, IASTAbstractDeclaration abstractDeclaration, IASTInitializerClause initializerClause, IASTExpression bitfieldExpression, int startingOffset, int nameOffset, List references, IASTExpression constructorExpression, boolean previouslyDeclared )
{
super( newSymbol );
this.abstractDeclaration = abstractDeclaration;
@ -56,6 +57,7 @@ public class ASTVariable extends ASTSymbol implements IASTVariable
setNameOffset( nameOffset );
referenceDelegate = new ASTReferenceStore( references );
qualifiedName = new ASTQualifiedNamedElement( getOwnerScope(), newSymbol.getName() );
this.previouslyDeclared =previouslyDeclared;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTVariable#isAuto()

View file

@ -157,6 +157,10 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
return result;
}
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, String name, List references, boolean throwOnError ) throws ASTSemanticException{
return lookupQualifiedName(startingScope, name, TypeInfo.t_any, null, 0, references, throwOnError);
}
protected ISymbol lookupQualifiedName( IContainerSymbol startingScope, String name, TypeInfo.eType type, List parameters, int offset, List references, boolean throwOnError ) throws ASTSemanticException
{
ISymbol result = null;
@ -1406,7 +1410,8 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isVirtual,
boolean isExplicit,
boolean isPureVirtual,
ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition ) throws ASTSemanticException
List constructorChain,
boolean isFunctionDefinition ) throws ASTSemanticException
{
List references = new ArrayList();
IContainerSymbol ownerScope = scopeToSymbol( scope );
@ -1437,7 +1442,12 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
if(parentSymbol == null){
parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_namespace, null, offset, references, false);
}
if(parentSymbol == null)
if(parentSymbol == null){
parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_struct, null, offset, references, false);
}
if(parentSymbol == null){
parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_union, null, offset, references, false);
} if(parentSymbol == null)
break;
else {
parentScope = parentSymbol;
@ -1445,12 +1455,16 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
}
}
if((parentScope != null) && (parentScope.getType() == TypeInfo.t_class)){
IASTClassSpecifier methodParentScope = (IASTClassSpecifier)parentScope.getASTExtension().getPrimaryDeclaration();
if((parentScope != null) &&
( (parentScope.getType() == TypeInfo.t_class)
|| (parentScope.getType() == TypeInfo.t_struct)
|| (parentScope.getType() == TypeInfo.t_union))
){
IASTScope methodParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration();
return createMethod(methodParentScope, functionName,nameEndOffset, parameters, returnType,
exception, isInline, isFriend, isStatic, startOffset, offset,
ownerTemplate, isConst, isVolatile, isVirtual, isExplicit, isPureVirtual,
visibility, constructorChain, references, isFunctionDefinition);
ASTAccessVisibility.PRIVATE, constructorChain, references, isFunctionDefinition);
}
}
@ -1852,6 +1866,59 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
int nameOffset, IASTExpression constructorExpression) throws ASTSemanticException
{
List references = new ArrayList();
IContainerSymbol ownerScope = scopeToSymbol( scope );
// check if this is a scoped field, not a variable
StringTokenizer tokenizer = new StringTokenizer(name,DOUBLE_COLON);
int tokencount = tokenizer.countTokens();
if(tokencount > 1){
List tokens = new ArrayList();
String oneToken = "";
// This is NOT a function. This is a method definition
while (tokenizer.hasMoreTokens()){
oneToken = tokenizer.nextToken();
tokens.add(oneToken);
}
String fieldName = oneToken;
String parentName = name.substring(0, name.lastIndexOf(DOUBLE_COLON));
int numOfTokens = 1;
int offset = nameOffset;
IContainerSymbol parentScope = ownerScope;
Iterator i = tokens.iterator();
while (i.hasNext() && (numOfTokens++) < tokens.size()){
String token = (String) i.next();
IContainerSymbol parentSymbol =
(IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_class, null, offset, references, false);
if(parentSymbol == null){
parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_namespace, null, offset, references, false);
}
if(parentSymbol == null){
parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_struct, null, offset, references, false);
}
if(parentSymbol == null){
parentSymbol = (IContainerSymbol) lookupQualifiedName(parentScope, token, TypeInfo.t_union, null, offset, references, false);
}
if(parentSymbol == null)
break;
else {
parentScope = parentSymbol;
offset += token.length()+ DOUBLE_COLON.length();
}
}
if((parentScope != null) &&
( (parentScope.getType() == TypeInfo.t_class)
|| (parentScope.getType() == TypeInfo.t_struct)
|| (parentScope.getType() == TypeInfo.t_union))
){
IASTScope fieldParentScope = (IASTScope)parentScope.getASTExtension().getPrimaryDeclaration();
return createField(fieldParentScope, fieldName,isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern,
isRegister, isStatic, startingOffset, offset, constructorExpression, ASTAccessVisibility.PRIVATE, references);
}
}
ISymbol newSymbol = cloneSimpleTypeSymbol(name, abstractDeclaration, references);
setVariableTypeInfoBits(
isAuto,
@ -1862,16 +1929,28 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
isStatic,
newSymbol);
setPointerOperators( newSymbol, abstractDeclaration.getPointerOperators(), abstractDeclaration.getArrayModifiers() );
newSymbol.setIsForwardDeclaration(isStatic);
boolean previouslyDeclared = false;
if(!isStatic){
ISymbol variableDeclaration = (ISymbol) lookupQualifiedName(ownerScope, name, new ArrayList(), false);
if( variableDeclaration != null )
{
variableDeclaration.setTypeSymbol( newSymbol );
previouslyDeclared = true;
}
}
try
{
scopeToSymbol(scope).addSymbol( newSymbol );
ownerScope.addSymbol( newSymbol );
}
catch (ParserSymbolTableException e)
{
// TODO Auto-generated catch block
}
ASTVariable variable = new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, constructorExpression );
ASTVariable variable = new ASTVariable( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, constructorExpression, previouslyDeclared );
try
{
attachSymbolExtension(newSymbol, variable );
@ -1931,6 +2010,25 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createField(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, boolean, org.eclipse.cdt.core.parser.ast.IASTInitializerClause, org.eclipse.cdt.core.parser.ast.IASTExpression, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, boolean, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.ASTAccessVisibility)
*/
public IASTField createField(
IASTScope scope,
String name,
boolean isAuto,
IASTInitializerClause initializerClause,
IASTExpression bitfieldExpression,
IASTAbstractDeclaration abstractDeclaration,
boolean isMutable,
boolean isExtern,
boolean isRegister,
boolean isStatic,
int startingOffset,
int nameOffset,
IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException
{
return createField(scope, name,isAuto, initializerClause, bitfieldExpression, abstractDeclaration, isMutable, isExtern,
isRegister, isStatic, startingOffset, nameOffset, constructorExpression, visibility, null);
}
public IASTField createField(
IASTScope scope,
String name,
@ -1944,9 +2042,14 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
boolean isStatic,
int startingOffset,
int nameOffset,
IASTExpression constructorExpression, ASTAccessVisibility visibility) throws ASTSemanticException
IASTExpression constructorExpression,
ASTAccessVisibility visibility,
List references) throws ASTSemanticException
{
List references = new ArrayList();
IContainerSymbol ownerScope = scopeToSymbol( scope );
if(references == null)
references = new ArrayList();
ISymbol newSymbol = cloneSimpleTypeSymbol(name, abstractDeclaration, references);
setVariableTypeInfoBits(
isAuto,
@ -1958,16 +2061,32 @@ public class CompleteParseASTFactory extends BaseASTFactory implements IASTFacto
newSymbol);
setPointerOperators( newSymbol, abstractDeclaration.getPointerOperators(), abstractDeclaration.getArrayModifiers() );
newSymbol.setIsForwardDeclaration(isStatic);
boolean previouslyDeclared = false;
if(!isStatic){
List fieldReferences = new ArrayList();
ISymbol fieldDeclaration = lookupQualifiedName(ownerScope, name, fieldReferences, false);
if( fieldDeclaration != null )
{
previouslyDeclared = true;
fieldDeclaration.setTypeSymbol( newSymbol );
// set the definition visibility = declaration visibility
ASTReference reference = (ASTReference) fieldReferences.iterator().next();
visibility = ((IASTField)reference.getReferencedElement()).getVisiblity();
}
}
try
{
scopeToSymbol(scope).addSymbol( newSymbol );
ownerScope.addSymbol( newSymbol );
}
catch (ParserSymbolTableException e)
{
throw new ASTSemanticException();
}
ASTField field = new ASTField( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, constructorExpression, visibility );
ASTField field = new ASTField( newSymbol, abstractDeclaration, initializerClause, bitfieldExpression, startingOffset, nameOffset, references, previouslyDeclared, constructorExpression, visibility );
try
{
attachSymbolExtension(newSymbol, field );

View file

@ -188,7 +188,7 @@ public class QuickParseASTFactory extends BaseASTFactory implements IASTFactory
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.ast.IASTFactory#createFunction(org.eclipse.cdt.core.parser.ast.IASTScope, java.lang.String, java.util.List, org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration, org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification, boolean, boolean, boolean, int, int, org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration)
*/
public IASTFunction createFunction(IASTScope scope, String name, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, ASTAccessVisibility visibility, List constructorChain, boolean isFunctionDefinition )
public IASTFunction createFunction(IASTScope scope, String name, int nameEndOffset, List parameters, IASTAbstractDeclaration returnType, IASTExceptionSpecification exception, boolean isInline, boolean isFriend, boolean isStatic, int startOffset, int nameOffset, IASTTemplate ownerTemplate, boolean isConst, boolean isVolatile, boolean isVirtual, boolean isExplicit, boolean isPureVirtual, List constructorChain, boolean isFunctionDefinition )
{
return new ASTFunction(scope, name, nameEndOffset, parameters, returnType, exception, isInline, isFriend, isStatic, startOffset, nameOffset, ownerTemplate );
}

View file

@ -10,6 +10,10 @@
* src/org/eclipse/cdt/ui/dialogs/AbstractErrorParserBlock.java
* src/org/eclipse/cdt/ui/dialogs/BinaryParserBlock.java
2003-09-23 Hoda Amer
Solution to bug#43143: Naming of Code Assist Menus/Tab are not consistent
changed both names to Content Assist. No tests provided.
2003-09-22 Bogdan Gheorghe
Got rid of the C/C++ Project property page (only the indexer tab
was left). Here are the changes:

View file

@ -950,7 +950,7 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
item.setControl(createColorPage(folder));
item = new TabItem(folder, SWT.NONE);
item.setText("Code A&ssist");
item.setText("Content A&ssist");
item.setImage(CPluginImages.get(CPluginImages.IMG_OBJS_TUNIT));
item.setControl(createContentAssistPage(folder));