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

Patch for John Camelon:

CORE
		 Minor cleanup of callbacks due to removal of NewModelBuilder.
		 Added parser support to partially fix bug36416 & bug36294.  Also
added minimal C-Model support for these fixes. 

TESTS
		 Added DOMTests::testPointersToFunctions.
This commit is contained in:
Doug Schaefer 2003-04-14 14:14:52 +00:00
parent 1408e4cd83
commit ad0b7bce68
15 changed files with 134 additions and 89 deletions

View file

@ -79,16 +79,30 @@ public class DOMBuilder implements IParserCallback
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorBegin()
*/
public Object declaratorBegin(Object container) {
DeclSpecifier.Container decl = (DeclSpecifier.Container )container;
if( container instanceof DeclSpecifier.IContainer )
{
DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer )container;
Declarator declarator = new Declarator(decl);
decl.addDeclarator(declarator);
return declarator;
}
else if( container instanceof IDeclaratorOwner )
{
IDeclaratorOwner owner = (IDeclaratorOwner)container;
Declarator declarator = new Declarator(owner);
return declarator;
}
return null;
}
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorEnd()
*/
public void declaratorEnd(Object declarator) {
Declarator d = (Declarator)declarator;
if( d.getDeclaration() != null )
d.getDeclaration().addDeclarator(d);
else if( d.getOwnerDeclarator() != null )
d.getOwnerDeclarator().setDeclarator(d);
}
/**
@ -102,14 +116,8 @@ public class DOMBuilder implements IParserCallback
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declSpecifier(org.eclipse.cdt.internal.core.newparser.Token)
*/
public void simpleDeclSpecifier(Object Container, Token specifier) {
DeclSpecifier.Container decl = (DeclSpecifier.Container)Container;
DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer)Container;
DeclSpecifier declSpec = decl.getDeclSpecifier();
if( declSpec == null )
{
declSpec = new DeclSpecifier();
decl.setDeclSpecifier( declSpec );
}
declSpec.setType( specifier );
}
@ -280,12 +288,8 @@ public class DOMBuilder implements IParserCallback
/**
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
*/
public void declaratorAbort(Object container, Object declarator) {
DeclSpecifier.Container decl = (DeclSpecifier.Container )container;
Declarator toBeRemoved = (Declarator)declarator;
decl.removeDeclarator( toBeRemoved );
public void declaratorAbort(Object declarator) {
currName = null;
toBeRemoved = null;
}
/**
@ -311,12 +315,6 @@ public class DOMBuilder implements IParserCallback
cs.getOwner().setTypeSpecifier(null);
}
/**
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
*/
public void classSpecifierSafe(Object classSpecifier) {
}
/**
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
*/
@ -359,7 +357,7 @@ public class DOMBuilder implements IParserCallback
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierName(java.lang.Object)
*/
public void simpleDeclSpecifierName(Object declaration) {
DeclSpecifier.Container decl = (DeclSpecifier.Container)declaration;
DeclSpecifier.IContainer decl = (DeclSpecifier.IContainer)declaration;
DeclSpecifier declSpec = decl.getDeclSpecifier();
declSpec.setName( currName );
}

View file

@ -252,14 +252,10 @@ public class DeclSpecifier {
return declSpecifierSeq & typeMask;
}
public interface Container {
public interface IContainer {
public DeclSpecifier getDeclSpecifier();
public void setDeclSpecifier(DeclSpecifier in);
public void addDeclarator(Object declarator);
public void removeDeclarator(Object declarator);
public List getDeclarators();
};

View file

@ -6,19 +6,27 @@ import java.util.List;
public class Declarator implements IExpressionOwner {
public class Declarator implements IExpressionOwner, IDeclaratorOwner {
public Declarator(DeclSpecifier.Container declaration) {
public Declarator(DeclSpecifier.IContainer declaration) {
this.declaration = declaration;
this.ownerDeclarator = null;
}
private DeclSpecifier.Container declaration;
public Declarator( IDeclaratorOwner owner )
{
this.ownerDeclarator = owner;
this.declaration = null;
}
private final DeclSpecifier.IContainer declaration;
private final IDeclaratorOwner ownerDeclarator;
/**
* Returns the declaration.
* @return SimpleDeclaration
*/
public DeclSpecifier.Container getDeclaration() {
public DeclSpecifier.IContainer getDeclaration() {
return declaration;
}
@ -27,7 +35,7 @@ public class Declarator implements IExpressionOwner {
* @param declaration The declaration to set
*/
public void setDeclaration(SimpleDeclaration declaration) {
this.declaration = declaration;
}
private Name name;
@ -178,4 +186,26 @@ public class Declarator implements IExpressionOwner {
this.isPureVirtual = isPureVirtual;
}
private Declarator innerDeclarator = null;
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.IDeclaratorOwner#getDeclarator()
*/
public Declarator getDeclarator() {
return innerDeclarator;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.IDeclaratorOwner#setDeclarator(org.eclipse.cdt.internal.core.dom.Declarator)
*/
public void setDeclarator(Declarator input) {
innerDeclarator = input;
}
/**
* @return
*/
public IDeclaratorOwner getOwnerDeclarator() {
return ownerDeclarator;
}
}

View file

@ -0,0 +1,23 @@
/**********************************************************************
* Created on Apr 13, 2003
*
* Copyright (c) 2002,2003 IBM/Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Ltd. - Rational Software - Initial API and implementation
************************************************************************/
package org.eclipse.cdt.internal.core.dom;
/**
* @author jcamelon
*
*/
public interface IDeclaratorOwner {
public Declarator getDeclarator();
public void setDeclarator( Declarator input );
}

View file

@ -14,7 +14,7 @@ import java.util.List;
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class ParameterDeclaration extends Declaration implements DeclSpecifier.Container, TypeSpecifier.IOwner {
public class ParameterDeclaration extends Declaration implements DeclSpecifier.IContainer, TypeSpecifier.IOwner {
private DeclSpecifier declSpec = null;
private TypeSpecifier typeSpecifier;
@ -51,12 +51,6 @@ public class ParameterDeclaration extends Declaration implements DeclSpecifier.C
return declSpec;
}
/**
* @see org.eclipse.cdt.internal.core.dom.DeclarationSpecifier.CElementWrapper#setDeclSpecifier(org.eclipse.cdt.internal.core.dom.DeclarationSpecifier)
*/
public void setDeclSpecifier(DeclSpecifier in) {
declSpec = in;
}
private List declarators = new LinkedList();
public void addDeclarator(Object declarator) {
@ -67,10 +61,4 @@ public class ParameterDeclaration extends Declaration implements DeclSpecifier.C
return Collections.unmodifiableList( declarators );
}
/**
* @see org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier.Container#removeDeclarator(java.lang.Object)
*/
public void removeDeclarator(Object declarator) {
declarators.remove( declarator );
}
}

View file

@ -5,7 +5,7 @@ import java.util.LinkedList;
import java.util.List;
public class SimpleDeclaration extends Declaration implements DeclSpecifier.Container, IOffsetable, TypeSpecifier.IOwner {
public class SimpleDeclaration extends Declaration implements DeclSpecifier.IContainer, IOffsetable, TypeSpecifier.IOwner {
private int startingOffset = 0, totalLength = 0;
private AccessSpecifier accessSpecifier = null;
@ -25,11 +25,6 @@ public class SimpleDeclaration extends Declaration implements DeclSpecifier.Cont
return declSpec;
}
public void setDeclSpecifier( DeclSpecifier in )
{
declSpec = in;
}
/**
* This is valid when the type is t_type. It points to a
* classSpecifier, etc.
@ -63,12 +58,6 @@ public class SimpleDeclaration extends Declaration implements DeclSpecifier.Cont
return Collections.unmodifiableList( declarators );
}
/**
* @see org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier.Container#removeDeclarator(java.lang.Object)
*/
public void removeDeclarator(Object declarator) {
declarators.remove( declarator );
}
/**
* @return
*/

View file

@ -3,7 +3,6 @@ package org.eclipse.cdt.internal.core.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
@ -12,7 +11,7 @@ import java.util.NoSuchElementException;
*/
public class TranslationUnit implements IScope {
private List declarations = new LinkedList();
private List declarations = new ArrayList();
private List macros = new ArrayList();
private List inclusions = new ArrayList();

View file

@ -1,3 +1,7 @@
2003-04-13 John Camelon
Minor cleanup of callbacks due to removal of NewModelBuilder.
Added parser support to partially fix bug36416 & bug36294. Also added minimal C-Model support for these fixes.
2003-04-11 John Camelon
Minimized the number of objects being returned from Parser callbacks.
Fixed CModelBuilder to handle errors better.

View file

@ -44,8 +44,6 @@ import org.eclipse.cdt.internal.core.dom.TemplateParameter;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
public class CModelBuilder {
org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
@ -368,7 +366,8 @@ public class CModelBuilder {
}
private FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc, boolean isTemplate){
String declaratorName = declarator.getName().toString();
boolean pointerToFunction = declarator.getDeclarator() != null;
String declaratorName = pointerToFunction ? declarator.getDeclarator().getName().toString() : declarator.getName().toString();
DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
// getParameterTypes
List parameterList = pdc.getDeclarations();
@ -439,6 +438,9 @@ public class CModelBuilder {
parent.addChild( element );
// hook up the offsets
if( pointerToFunction )
element.setIdPos( declarator.getDeclarator().getName().getStartOffset(), declarator.getDeclarator().getName().length() );
else
element.setIdPos( declarator.getName().getStartOffset(), declarator.getName().length() );
element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
return element;

View file

@ -185,7 +185,7 @@ public class ExpressionEvaluator implements IParserCallback {
/**
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
*/
public void declaratorAbort(Object container, Object declarator) {
public void declaratorAbort(Object declarator) {
}
/**
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorEnd(java.lang.Object)
@ -276,12 +276,6 @@ public class ExpressionEvaluator implements IParserCallback {
public void classSpecifierAbort(Object classSpecifier) {
}
/**
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
*/
public void classSpecifierSafe(Object classSpecifier) {
}
/**
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
*/

View file

@ -32,7 +32,7 @@ public interface IParserCallback {
public Object declaratorBegin(Object container);
public void declaratorId(Object declarator);
public void declaratorAbort( Object container, Object declarator );
public void declaratorAbort( Object declarator );
public void declaratorPureVirtual( Object declarator );
public void declaratorCVModifier( Object declarator, Token modifier );
public void declaratorThrowsException( Object declarator );
@ -58,7 +58,6 @@ public interface IParserCallback {
public Object classSpecifierBegin(Object container, Token classKey);
public void classSpecifierName(Object classSpecifier);
public void classSpecifierAbort( Object classSpecifier );
public void classSpecifierSafe( Object classSpecifier );
public void classMemberVisibility( Object classSpecifier, Token visibility );
public void classSpecifierEnd(Object classSpecifier, Token closingBrace );

View file

@ -101,7 +101,7 @@ public class NullParserCallback implements IParserCallback {
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorAbort(java.lang.Object, java.lang.Object)
*/
public void declaratorAbort(Object container, Object declarator) {
public void declaratorAbort(Object declarator) {
}
/* (non-Javadoc)
@ -211,13 +211,6 @@ public class NullParserCallback implements IParserCallback {
public void classSpecifierAbort(Object classSpecifier) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
*/
public void classSpecifierSafe(Object classSpecifier) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classMemberVisibility(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token)
*/

View file

@ -1026,12 +1026,11 @@ c, quick);
if (LT(1) == Token.tLPAREN) {
consume();
declarator(declarator);
Object subDeclarator = declarator(declarator);
consume(Token.tRPAREN);
return declarator;
try{ callback.declaratorEnd( subDeclarator );} catch( Exception e ) {}
}
if( LT(1) == Token.t_operator )
else if( LT(1) == Token.t_operator )
{
// we know this is an operator
Token operatorToken = consume( Token.t_operator );
@ -1263,7 +1262,7 @@ c, quick);
if( LA(1).getType() == Token.tIDENTIFIER )
{
try{ callback.declaratorAbort( container, declarator ); } catch( Exception e ) {}
try{ callback.declaratorAbort( declarator ); } catch( Exception e ) {}
declarator = null;
}
else
@ -1433,8 +1432,6 @@ c, quick);
backup( mark );
throw backtrack;
}
else
try{ callback.classSpecifierSafe( classSpec ); } catch( Exception e ){}
// base clause
if (LT(1) == Token.tCOLON) {

View file

@ -1,3 +1,6 @@
2003-04-13 John Camelon
Added DOMTests::testPointersToFunctions.
2003-04-11 John Camelon
Added DOMTests::testBug36247().

View file

@ -1232,6 +1232,37 @@ public class DOMTests extends TestCase {
assertEquals( tu.getDeclarations().size(), 1 );
}
public void testPointersToFunctions() throws Exception
{
Writer code = new StringWriter();
code.write( "void (*name)( void );\n");
code.write( "static void * (*orig_malloc_hook)(const char *file, int line, size_t size);\n");
TranslationUnit tu = parse( code.toString() );
assertEquals( tu.getDeclarations().size(), 2 );
SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0);
assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void );
assertEquals( declaration.getDeclarators().size(), 1);
assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() );
assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() );
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "name" );
ParameterDeclarationClause clause = ((Declarator)declaration.getDeclarators().get(0)).getParms();
assertEquals( clause.getDeclarations().size(), 1 );
assertEquals( ((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclarators().size(), 1 );
assertNull( ((Declarator)((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclarators().get(0)).getName() );
assertEquals( ((ParameterDeclaration)clause.getDeclarations().get(0)).getDeclSpecifier().getType(), DeclSpecifier.t_void );
declaration = (SimpleDeclaration)tu.getDeclarations().get(1);
assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_void );
assertTrue( declaration.getDeclSpecifier().isStatic() );
assertEquals( declaration.getDeclarators().size(), 1);
assertNull( ((Declarator)declaration.getDeclarators().get(0)).getName() );
assertNotNull( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator() );
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getDeclarator().getName().toString(), "orig_malloc_hook" );
clause = ((Declarator)declaration.getDeclarators().get(0)).getParms();
assertEquals( clause.getDeclarations().size(), 3 );
}
public void testBug36247() throws Exception
{
Writer code = new StringWriter();
@ -1287,6 +1318,5 @@ public class DOMTests extends TestCase {
}
}
}