1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

Further reduce memory footprint by trimming down Declarator and DeclarationWrapper classes.

This commit is contained in:
John Camelon 2004-05-27 04:41:59 +00:00
parent 1f636f83b5
commit dc9619b241
4 changed files with 184 additions and 274 deletions

View file

@ -10,6 +10,7 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.internal.core.parser; package org.eclipse.cdt.internal.core.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -41,42 +42,61 @@ import org.eclipse.cdt.internal.core.parser.token.TokenFactory;
*/ */
public class DeclarationWrapper implements IDeclaratorOwner public class DeclarationWrapper implements IDeclaratorOwner
{ {
private boolean imaginary, complex; private int flag = 0;
private boolean restrict; protected void setBit(boolean b, int mask){
if( b ){
flag = flag | mask;
} else {
flag = flag & ~mask;
}
}
protected boolean checkBit(int mask){
return (flag & mask) != 0;
}
private static final int DEFAULT_LIST_SIZE = 4;
protected static final int IS_IMAGINARY = 0x00000010;
protected static final int IS_COMPLEX = 0x00000020;
protected static final int IS_RESTRICT = 0x00000040;
protected static final int IS_SIGNED = 0x00000080;
protected static final int IS_SHORT = 0x00000100;
protected static final int IS_UNSIGNED = 0x00000200;
protected static final int IS_LONG = 0x00000400;
protected static final int IS_TYPENAMED = 0x00000800;
protected static final int IS_VOLATILE = 0x00001000;
protected static final int IS_VIRTUAL = 0x00002000;
protected static final int IS_TYPEDEF = 0x00004000;
protected static final int IS_STATIC = 0x00008000;
protected static final int IS_REGISTER = 0x00010000;
protected static final int IS_EXTERN = 0x00020000;
protected static final int IS_EXPLICIT = 0x00040000;
protected static final int IS_CONST = 0x00080000;
protected static final int IS_AUTO = 0x00100000;
protected static final int IS_GLOBAL = 0x00200000;
protected static final int IS_MUTABLE = 0x00400000;
protected static final int IS_FRIEND = 0x00800000;
protected static final int IS_INLINE = 0x01000000;
private int startingOffset = 0;
private int startingLine;
private int endOffset; private int endOffset;
private ITokenDuple name; private ITokenDuple name;
private Type simpleType = private Type simpleType = IASTSimpleTypeSpecifier.Type.UNSPECIFIED;
IASTSimpleTypeSpecifier.Type.UNSPECIFIED;
private boolean isSigned;
private boolean isLong;
private boolean isShort;
private boolean isUnsigned;
private final IASTTemplate templateDeclaration; private final IASTTemplate templateDeclaration;
private final IASTScope scope; private final IASTScope scope;
private IASTTypeSpecifier typeSpecifier; private IASTTypeSpecifier typeSpecifier;
private List declarators = new ArrayList();
private boolean typeNamed = false; private List declarators = Collections.EMPTY_LIST;
private boolean volatil = false;
private boolean virtual = false;
private boolean typedef = false;
private boolean staticc = false;
private boolean register = false;
private boolean extern = false;
private boolean explicit = false;
private boolean constt = false;
private int startingOffset = 0;
private boolean auto = false,
mutable = false,
friend = false,
inline = false;
private int startingLine;
private boolean global = false;
/** /**
* @param b * @param b
*/ */
public void setAuto(boolean b) public void setAuto(boolean b)
{ {
auto = b; setBit( b, IS_AUTO );
} }
/** /**
* @return * @return
@ -86,38 +106,6 @@ public class DeclarationWrapper implements IDeclaratorOwner
return scope; return scope;
} }
public DeclarationWrapper( DeclarationWrapper wrapper )
{
this( wrapper.getScope(), wrapper.getStartingOffset(), wrapper.getStartingLine(), wrapper.getOwnerTemplate() );
setAuto( wrapper.isAuto() );
setComplex( wrapper.isComplex() );
setConst( wrapper.isConst() );
setEndingOffsetAndLineNumber( wrapper.getEndOffset(), wrapper.getEndLine() );
setExplicit( wrapper.isExplicit() );
setExtern(wrapper.isExtern() );
setFriend(wrapper.isFriend());
setGloballyQualified( wrapper.isGloballyQualified() );
setImaginary( wrapper.isImaginary() );
setInline( wrapper.isInline());
setLong( wrapper.isLong() );
setMutable( wrapper.isMutable() );
setName( wrapper.getName() );
setRegister(wrapper.isRegister() );
setRestrict( wrapper.isRestrict() );
setShort(wrapper.isShort());
setSigned(wrapper.isSigned());
setSimpleType(wrapper.getSimpleType());
setStatic(wrapper.isStatic());
setTypedef(wrapper.isTypedef());
setTypenamed(wrapper.isTypeNamed());
setTypeName(wrapper.getName());
setTypeSpecifier(wrapper.getTypeSpecifier());
setUnsigned(wrapper.isUnsigned());
setVirtual(wrapper.isVirtual());
setVolatile(wrapper.isVolatile());
}
/** /**
* @param scope * @param scope
*/ */
@ -136,140 +124,140 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public void setTypenamed(boolean b) public void setTypenamed(boolean b)
{ {
typeNamed = b; setBit( b, IS_TYPENAMED );
} }
/** /**
* @param b * @param b
*/ */
public void setMutable(boolean b) public void setMutable(boolean b)
{ {
mutable = b; setBit( b, IS_MUTABLE);
} }
/** /**
* @param b * @param b
*/ */
public void setFriend(boolean b) public void setFriend(boolean b)
{ {
friend = b; setBit( b, IS_FRIEND );
} }
/** /**
* @param b * @param b
*/ */
public void setInline(boolean b) public void setInline(boolean b)
{ {
inline = b; setBit( b, IS_INLINE );
} }
/** /**
* @param b * @param b
*/ */
public void setRegister(boolean b) public void setRegister(boolean b)
{ {
register = b; setBit( b, IS_REGISTER );
} }
/** /**
* @param b * @param b
*/ */
public void setStatic(boolean b) public void setStatic(boolean b)
{ {
staticc = b; setBit( b, IS_STATIC );
} }
/** /**
* @param b * @param b
*/ */
public void setTypedef(boolean b) public void setTypedef(boolean b)
{ {
typedef = b; setBit( b, IS_TYPEDEF );
} }
/** /**
* @param b * @param b
*/ */
public void setVirtual(boolean b) public void setVirtual(boolean b)
{ {
virtual = b; setBit( b, IS_VIRTUAL );
} }
/** /**
* @param b * @param b
*/ */
public void setVolatile(boolean b) public void setVolatile(boolean b)
{ {
volatil = b; setBit( b, IS_VOLATILE );
} }
/** /**
* @param b * @param b
*/ */
public void setExtern(boolean b) public void setExtern(boolean b)
{ {
extern = b; setBit( b, IS_EXTERN );
} }
/** /**
* @param b * @param b
*/ */
public void setExplicit(boolean b) public void setExplicit(boolean b)
{ {
explicit = b; setBit( b, IS_EXPLICIT );
} }
/** /**
* @param b * @param b
*/ */
public void setConst(boolean b) public void setConst(boolean b)
{ {
constt = b; setBit( b, IS_CONST );
} }
/** /**
* @return * @return
*/ */
public boolean isAuto() public boolean isAuto()
{ {
return auto; return checkBit( IS_AUTO );
} }
/** /**
* @return * @return
*/ */
public boolean isConst() public boolean isConst()
{ {
return constt; return checkBit( IS_CONST );
} }
/** /**
* @return * @return
*/ */
public boolean isExplicit() public boolean isExplicit()
{ {
return explicit; return checkBit( IS_EXPLICIT );
} }
/** /**
* @return * @return
*/ */
public boolean isExtern() public boolean isExtern()
{ {
return extern; return checkBit( IS_EXTERN );
} }
/** /**
* @return * @return
*/ */
public boolean isFriend() public boolean isFriend()
{ {
return friend; return checkBit( IS_FRIEND );
} }
/** /**
* @return * @return
*/ */
public boolean isInline() public boolean isInline()
{ {
return inline; return checkBit( IS_INLINE );
} }
/** /**
* @return * @return
*/ */
public boolean isMutable() public boolean isMutable()
{ {
return mutable; return checkBit( IS_MUTABLE );
} }
/** /**
* @return * @return
*/ */
public boolean isRegister() public boolean isRegister()
{ {
return register; return checkBit( IS_REGISTER );
} }
/** /**
* @return * @return
@ -288,38 +276,40 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public boolean isStatic() public boolean isStatic()
{ {
return staticc; return checkBit( IS_STATIC );
} }
/** /**
* @return * @return
*/ */
public boolean isTypedef() public boolean isTypedef()
{ {
return typedef; return checkBit( IS_TYPEDEF );
} }
/** /**
* @return * @return
*/ */
public boolean isTypeNamed() public boolean isTypeNamed()
{ {
return typeNamed; return checkBit( IS_TYPENAMED );
} }
/** /**
* @return * @return
*/ */
public boolean isVirtual() public boolean isVirtual()
{ {
return virtual; return checkBit( IS_VIRTUAL );
} }
/** /**
* @return * @return
*/ */
public boolean isVolatile() public boolean isVolatile()
{ {
return volatil; return checkBit( IS_VOLATILE );
} }
public void addDeclarator(Declarator d) public void addDeclarator(Declarator d)
{ {
if( declarators == Collections.EMPTY_LIST )
declarators = new ArrayList(DEFAULT_LIST_SIZE);
declarators.add(d); declarators.add(d);
} }
public Iterator getDeclarators() public Iterator getDeclarators()
@ -426,8 +416,8 @@ public class DeclarationWrapper implements IDeclaratorOwner
IASTAbstractDeclaration abs = null; IASTAbstractDeclaration abs = null;
abs = abs =
astFactory.createAbstractDeclaration( astFactory.createAbstractDeclaration(
constt, isConst(),
volatil, isVolatile(),
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), declarator.getArrayModifiers(),
@ -436,16 +426,16 @@ public class DeclarationWrapper implements IDeclaratorOwner
ITokenDuple nameDuple = ( d.getPointerOperatorNameDuple() != null ) ? TokenFactory.createTokenDuple( d.getPointerOperatorNameDuple(), d.getNameDuple() ) : d.getNameDuple(); ITokenDuple nameDuple = ( d.getPointerOperatorNameDuple() != null ) ? TokenFactory.createTokenDuple( d.getPointerOperatorNameDuple(), d.getNameDuple() ) : d.getNameDuple();
if( typedef ) if( isTypedef() )
return astFactory.createTypedef(scope, nameDuple.toString(), abs, return astFactory.createTypedef(scope, nameDuple.toString(), abs,
getStartingOffset(), getStartingLine(), d getStartingOffset(), getStartingLine(), d
.getNameStartOffset(), d.getNameEndOffset(), d .getNameStartOffset(), d.getNameEndOffset(), d
.getNameLine()); .getNameLine());
if( isWithinClass ) if( isWithinClass )
return astFactory.createField( scope, nameDuple, auto, d.getInitializerClause(), d.getBitFieldExpression(), abs, mutable, extern, register, staticc, getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode() ); return astFactory.createField( scope, nameDuple, isAuto(), d.getInitializerClause(), d.getBitFieldExpression(), abs, isMutable(), isExtern(), isRegister(), isStatic(), getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode() );
return astFactory.createVariable( scope, nameDuple, auto, d.getInitializerClause(), d.getBitFieldExpression(), abs, mutable, extern, register, staticc, getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression() ); return astFactory.createVariable( scope, nameDuple, isAuto(), d.getInitializerClause(), d.getBitFieldExpression(), abs, isMutable(), isExtern(), isRegister(), isStatic(), getStartingOffset(), getStartingLine(), d.getNameStartOffset(), d.getNameEndOffset(), d.getNameLine(), d.getConstructorExpression() );
} }
throw new BacktrackException(); throw new BacktrackException();
@ -460,7 +450,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
{ {
return astFactory.createTypedef(scope, nested ? declarator return astFactory.createTypedef(scope, nested ? declarator
.getOwnedDeclarator().getName() : declarator.getName(), .getOwnedDeclarator().getName() : declarator.getName(),
astFactory.createAbstractDeclaration(constt, volatil, astFactory.createAbstractDeclaration(isConst(), isVolatile(),
getTypeSpecifier(), declarator.getPointerOperators(), getTypeSpecifier(), declarator.getPointerOperators(),
declarator.getArrayModifiers(), null, null), declarator.getArrayModifiers(), null, null),
startingOffset, getStartingLine(), declarator startingOffset, getStartingLine(), declarator
@ -481,15 +471,15 @@ public class DeclarationWrapper implements IDeclaratorOwner
.getOwnedDeclarator().getNameDuple() : declarator .getOwnedDeclarator().getNameDuple() : declarator
.getNameDuple(), .getNameDuple(),
createParameterList(declarator.getParameters()), astFactory createParameterList(declarator.getParameters()), astFactory
.createAbstractDeclaration(constt, volatil, .createAbstractDeclaration(isConst(), isVolatile(),
getTypeSpecifier(), declarator getTypeSpecifier(), declarator
.getPointerOperators(), declarator .getPointerOperators(), declarator
.getArrayModifiers(), null, null), .getArrayModifiers(), null, null),
declarator.getExceptionSpecification(), inline, friend, declarator.getExceptionSpecification(), isInline(), isFriend(),
staticc, startingOffset, getStartingLine(), declarator isStatic(), startingOffset, getStartingLine(), declarator
.getNameStartOffset(), declarator.getNameEndOffset(), .getNameStartOffset(), declarator.getNameEndOffset(),
declarator.getNameLine(), templateDeclaration, declarator declarator.getNameLine(), templateDeclaration, declarator
.isConst(), declarator.isVolatile(), virtual, explicit, .isConst(), declarator.isVolatile(), isVirtual(), isExplicit(),
declarator.isPureVirtual(), ((IASTClassSpecifier) classifierScope) declarator.isPureVirtual(), ((IASTClassSpecifier) classifierScope)
.getCurrentVisibilityMode(), declarator .getCurrentVisibilityMode(), declarator
.getConstructorMemberInitializers(), declarator .getConstructorMemberInitializers(), declarator
@ -506,15 +496,15 @@ public class DeclarationWrapper implements IDeclaratorOwner
.getOwnedDeclarator().getNameDuple() : declarator .getOwnedDeclarator().getNameDuple() : declarator
.getNameDuple(), .getNameDuple(),
createParameterList(declarator.getParameters()), astFactory createParameterList(declarator.getParameters()), astFactory
.createAbstractDeclaration(constt, volatil, .createAbstractDeclaration(isConst(), isVolatile(),
getTypeSpecifier(), declarator getTypeSpecifier(), declarator
.getPointerOperators(), declarator .getPointerOperators(), declarator
.getArrayModifiers(), null, null), .getArrayModifiers(), null, null),
declarator.getExceptionSpecification(), inline, friend, declarator.getExceptionSpecification(), isInline(), isFriend(),
staticc, startingOffset, getStartingLine(), declarator isStatic(), startingOffset, getStartingLine(), declarator
.getNameStartOffset(), declarator.getNameEndOffset(), .getNameStartOffset(), declarator.getNameEndOffset(),
declarator.getNameLine(), templateDeclaration, declarator declarator.getNameLine(), templateDeclaration, declarator
.isConst(), declarator.isVolatile(), virtual, explicit, .isConst(), declarator.isVolatile(), isVirtual(), isExplicit(),
declarator.isPureVirtual(), declarator declarator.isPureVirtual(), declarator
.getConstructorMemberInitializers(), declarator .getConstructorMemberInitializers(), declarator
.hasFunctionBody(), declarator.hasFunctionTryBlock(), .hasFunctionBody(), declarator.hasFunctionTryBlock(),
@ -529,18 +519,18 @@ public class DeclarationWrapper implements IDeclaratorOwner
return astFactory.createField( return astFactory.createField(
scope, scope,
nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(), nested ? declarator.getOwnedDeclarator().getNameDuple() : declarator.getNameDuple(),
auto, isAuto(),
declarator.getInitializerClause(), declarator.getInitializerClause(),
declarator.getBitFieldExpression(), declarator.getBitFieldExpression(),
astFactory.createAbstractDeclaration( astFactory.createAbstractDeclaration(
constt, isConst(),
volatil, isVolatile(),
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
mutable, isMutable(),
extern, isExtern(),
register, isRegister(),
staticc, isStatic(),
startingOffset, startingOffset,
getStartingLine(), getStartingLine(),
declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode()); declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression(), ((IASTClassSpecifier)scope).getCurrentVisibilityMode());
@ -585,14 +575,14 @@ public class DeclarationWrapper implements IDeclaratorOwner
declarator.getInitializerClause(), declarator.getInitializerClause(),
declarator.getBitFieldExpression(), declarator.getBitFieldExpression(),
astFactory.createAbstractDeclaration( astFactory.createAbstractDeclaration(
constt, isConst(),
volatil, isVolatile(),
getTypeSpecifier(), getTypeSpecifier(),
declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null), declarator.getPointerOperators(), declarator.getArrayModifiers(), null, null),
mutable, isMutable(),
extern, isExtern(),
register, isRegister(),
staticc, isStatic(),
getStartingOffset(), getStartingOffset(),
getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression()); getStartingLine(), declarator.getNameStartOffset(), declarator.getNameEndOffset(), declarator.getNameLine(), declarator.getConstructorExpression());
@ -610,56 +600,56 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public boolean isUnsigned() public boolean isUnsigned()
{ {
return isUnsigned; return checkBit( IS_UNSIGNED );
} }
/** /**
* @return * @return
*/ */
public boolean isSigned() public boolean isSigned()
{ {
return isSigned; return checkBit( IS_SIGNED );
} }
/** /**
* @return * @return
*/ */
public boolean isShort() public boolean isShort()
{ {
return isShort; return checkBit( IS_SHORT );
} }
/** /**
* @return * @return
*/ */
public boolean isLong() public boolean isLong()
{ {
return isLong; return checkBit( IS_LONG );
} }
/** /**
* @param b * @param b
*/ */
public void setLong(boolean b) public void setLong(boolean b)
{ {
isLong = b; setBit( b, IS_LONG );
} }
/** /**
* @param b * @param b
*/ */
public void setShort(boolean b) public void setShort(boolean b)
{ {
isShort = b; setBit( b, IS_SHORT );
} }
/** /**
* @param b * @param b
*/ */
public void setSigned(boolean b) public void setSigned(boolean b)
{ {
isSigned = b; setBit( b, IS_SIGNED );
} }
/** /**
* @param b * @param b
*/ */
public void setUnsigned(boolean b) public void setUnsigned(boolean b)
{ {
isUnsigned = b; setBit( b, IS_UNSIGNED );
} }
/** /**
* @return * @return
@ -685,21 +675,15 @@ public class DeclarationWrapper implements IDeclaratorOwner
/** /**
* @return * @return
*/ */
public ITokenDuple getName() public final ITokenDuple getName()
{ {
return name; return name;
} }
/**
* @param duple
*/
public void setName(ITokenDuple duple)
{
name = duple;
}
/** /**
* @return * @return
*/ */
public IASTTemplate getOwnerTemplate() public final IASTTemplate getOwnerTemplate()
{ {
return templateDeclaration; return templateDeclaration;
} }
@ -728,7 +712,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public void setRestrict(boolean b) public void setRestrict(boolean b)
{ {
restrict = b; setBit( b, IS_RESTRICT );
} }
@ -737,14 +721,14 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public boolean isRestrict() public boolean isRestrict()
{ {
return restrict; return checkBit( IS_RESTRICT );
} }
/** /**
* @param b * @param b
*/ */
public void setImaginary(boolean b) public void setImaginary(boolean b)
{ {
imaginary = b; setBit( b, IS_IMAGINARY );
} }
/** /**
@ -752,7 +736,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public boolean isComplex() public boolean isComplex()
{ {
return complex; return checkBit( IS_COMPLEX );
} }
/** /**
@ -760,7 +744,7 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public boolean isImaginary() public boolean isImaginary()
{ {
return imaginary; return checkBit( IS_IMAGINARY );
} }
/** /**
@ -768,17 +752,17 @@ public class DeclarationWrapper implements IDeclaratorOwner
*/ */
public void setComplex(boolean b) public void setComplex(boolean b)
{ {
complex = b; setBit( b, IS_COMPLEX );
} }
/** /**
* @param b * @param b
*/ */
public void setGloballyQualified(boolean b) { public void setGloballyQualified(boolean b) {
global = b; setBit( b, IS_GLOBAL );
} }
public boolean isGloballyQualified(){ public boolean isGloballyQualified(){
return global; return checkBit( IS_GLOBAL );
} }
private Hashtable extensionParameters = new Hashtable(); private Hashtable extensionParameters = new Hashtable();

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.parser.ast.IASTExceptionSpecification;
import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTExpression;
import org.eclipse.cdt.core.parser.ast.IASTInitializerClause; import org.eclipse.cdt.core.parser.ast.IASTInitializerClause;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
/** /**
* @author jcamelon * @author jcamelon
@ -31,30 +32,44 @@ import org.eclipse.cdt.core.parser.ast.IASTScope;
public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator public class Declarator implements IParameterCollection, IDeclaratorOwner, IDeclarator
{ {
private static final int DEFAULT_ARRAYLIST_SIZE = 4; private static final int DEFAULT_ARRAYLIST_SIZE = 4;
private boolean hasFunctionTryBlock; private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private ITokenDuple pointerOperatorNameDuple;
private ITokenDuple namedDuple; private final IDeclaratorOwner owner;
private boolean isFunction; private ITokenDuple pointerOperatorNameDuple = null;
private boolean hasFunctionBody; private ITokenDuple namedDuple = null;
private IASTExpression constructorExpression; private IASTExpression constructorExpression = null;
private boolean pureVirtual = false; private Declarator ownedDeclarator = null;
private final IDeclaratorOwner owner;
private Declarator ownedDeclarator = null;
private String name = ""; //$NON-NLS-1$
private IASTInitializerClause initializerClause = null; private IASTInitializerClause initializerClause = null;
private IASTExceptionSpecification exceptionSpecification = null; private IASTExceptionSpecification exceptionSpecification = null;
private IASTExpression bitFieldExpression = null; private IASTExpression bitFieldExpression = null;
private boolean isConst = false;
private boolean isVolatile = false; private int flag = 0;
private boolean isKandR = false; protected void setBit(boolean b, int mask){
if( b ){
flag = flag | mask;
} else {
flag = flag & ~mask;
}
}
protected boolean checkBit(int mask){
return (flag & mask) != 0;
}
protected static final int IS_FUNCTION = 0x000020;
protected static final int HAS_TRY_BLOCK = 0x000040;
protected static final int HAS_FUNCTION_BODY = 0x000080;
protected static final int IS_PURE_VIRTUAL = 0x000100;
protected static final int IS_VAR_ARGS = 0x000200;
protected static final int IS_VOLATILE = 0x000400;
protected static final int IS_CONST = 0x000800;
private List ptrOps = Collections.EMPTY_LIST; private List ptrOps = Collections.EMPTY_LIST;
private List parameters = Collections.EMPTY_LIST; private List parameters = Collections.EMPTY_LIST;
private List arrayModifiers = Collections.EMPTY_LIST; private List arrayModifiers = Collections.EMPTY_LIST;
private List constructorMemberInitializers = Collections.EMPTY_LIST; private List constructorMemberInitializers = Collections.EMPTY_LIST;
private int nameStartOffset, nameEndOffset;
private boolean varArgs;
private int nameLine;
public Declarator( IDeclaratorOwner owner ) public Declarator( IDeclaratorOwner owner )
{ {
@ -66,7 +81,8 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public String getName() public String getName()
{ {
return name; if( namedDuple == null ) return EMPTY_STRING;
return namedDuple.toString();
} }
/** /**
@ -74,12 +90,14 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public int getNameEndOffset() public int getNameEndOffset()
{ {
return nameEndOffset; if( namedDuple == null ) return -1;
return namedDuple.getEndOffset();
} }
public int getNameLine() public int getNameLine()
{ {
return nameLine; if( namedDuple == null ) return -1;
return namedDuple.getLineNumber();
} }
/** /**
@ -87,7 +105,8 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public int getNameStartOffset() public int getNameStartOffset()
{ {
return nameStartOffset; if( namedDuple == null ) return -1;
return namedDuple.getStartOffset();
} }
/** /**
@ -98,29 +117,6 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
return owner; return owner;
} }
/**
* @param string
*/
public void setName(String string)
{
name = string;
}
/**
* @param i
*/
public void setNameEndOffsetAndLineNumber(int offset, int lineNumber)
{
nameEndOffset = offset;
}
/**
* @param i
*/
public void setNameStartOffset(int i)
{
nameStartOffset = i;
}
/** /**
* @return * @return
@ -186,9 +182,6 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
public void setName( ITokenDuple duple ) public void setName( ITokenDuple duple )
{ {
setName( duple.toString() );
setNameStartOffset( duple.getFirstToken().getOffset());
setNameEndOffsetAndLineNumber( duple.getLastToken().getEndOffset(), duple.getLastToken().getLineNumber());
namedDuple = duple; namedDuple = duple;
} }
@ -205,7 +198,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public boolean isConst() public boolean isConst()
{ {
return isConst; return checkBit(IS_CONST);
} }
/** /**
@ -213,7 +206,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public boolean isVolatile() public boolean isVolatile()
{ {
return isVolatile; return checkBit( IS_VOLATILE);
} }
/** /**
@ -229,7 +222,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void setConst(boolean b) public void setConst(boolean b)
{ {
isConst = b; setBit(b, IS_CONST );
} }
/** /**
@ -237,23 +230,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void setVolatile(boolean b) public void setVolatile(boolean b)
{ {
isVolatile = b; setBit( b, IS_VOLATILE );
}
/**
* @return
*/
public boolean isKandR()
{
return isKandR;
}
/**
* @param b
*/
public void setKandR(boolean b)
{
isKandR = b;
} }
/** /**
@ -261,7 +238,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void setPureVirtual(boolean b) public void setPureVirtual(boolean b)
{ {
pureVirtual = b; setBit( b, IS_PURE_VIRTUAL );
} }
/** /**
@ -269,7 +246,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public boolean isPureVirtual() public boolean isPureVirtual()
{ {
return pureVirtual; return checkBit( IS_PURE_VIRTUAL );
} }
/** /**
@ -329,7 +306,6 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
{ {
if( constructorMemberInitializers == Collections.EMPTY_LIST ) if( constructorMemberInitializers == Collections.EMPTY_LIST )
constructorMemberInitializers = new ArrayList( DEFAULT_ARRAYLIST_SIZE ); constructorMemberInitializers = new ArrayList( DEFAULT_ARRAYLIST_SIZE );
constructorMemberInitializers.add( initializer ); constructorMemberInitializers.add( initializer );
} }
@ -341,20 +317,13 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
return constructorMemberInitializers; return constructorMemberInitializers;
} }
/**
* @param b
*/
public void hasFunctionBody(boolean b)
{
hasFunctionBody = b;
}
/** /**
* @return * @return
*/ */
public boolean isFunction() public boolean isFunction()
{ {
return isFunction; return checkBit( IS_FUNCTION );
} }
/** /**
@ -362,7 +331,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void setIsFunction(boolean b) public void setIsFunction(boolean b)
{ {
isFunction = b; setBit( b, IS_FUNCTION );
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -370,10 +339,12 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public Iterator getDeclarators() public Iterator getDeclarators()
{ {
List l = new ArrayList(); if( ownedDeclarator == null )
if( ownedDeclarator != null ) return EmptyIterator.EMPTY_ITERATOR;
l.add( ownedDeclarator );
return l.iterator(); List l = new ArrayList(1);
l.add( ownedDeclarator );
return l.iterator();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -417,7 +388,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public boolean hasFunctionBody() public boolean hasFunctionBody()
{ {
return hasFunctionBody; return checkBit( HAS_FUNCTION_BODY );
} }
/** /**
@ -425,7 +396,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void setHasFunctionBody(boolean b) public void setHasFunctionBody(boolean b)
{ {
hasFunctionBody = b; setBit( b, HAS_FUNCTION_BODY );
} }
/** /**
@ -433,7 +404,7 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public void setFunctionTryBlock(boolean b) public void setFunctionTryBlock(boolean b)
{ {
hasFunctionTryBlock = true; setBit( b, HAS_TRY_BLOCK );
} }
/** /**
@ -441,29 +412,21 @@ public class Declarator implements IParameterCollection, IDeclaratorOwner, IDecl
*/ */
public boolean hasFunctionTryBlock() public boolean hasFunctionTryBlock()
{ {
return hasFunctionTryBlock; return checkBit( HAS_TRY_BLOCK );
}
/**
* @param b
*/
public void setHasFunctionTryBlock(boolean b)
{
hasFunctionTryBlock = b;
} }
/** /**
* @param b * @param b
*/ */
public void setIsVarArgs(boolean b) { public void setIsVarArgs(boolean b) {
varArgs = b; setBit( b, IS_VAR_ARGS );
} }
/** /**
* @return Returns the varArgs. * @return Returns the varArgs.
*/ */
public boolean isVarArgs() { public boolean isVarArgs() {
return varArgs; return checkBit( IS_VAR_ARGS );
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -1863,6 +1863,8 @@ public abstract class Parser extends ExpressionParser implements IParser
simpleDeclarationMark = null; simpleDeclarationMark = null;
if( d.getNameDuple() != null ) if( d.getNameDuple() != null )
d.getNameDuple().getLastToken().setNext( null ); d.getNameDuple().getLastToken().setNext( null );
if( d.getPointerOperatorNameDuple() != null )
d.getPointerOperatorNameDuple().getLastToken().setNext( null );
} }

View file

@ -1,39 +0,0 @@
/**********************************************************************
* Copyright (c) 2002-2004 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 Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.core.parser.token;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
/**
* @author jcamelon
*
*/
public class SegmentedTokenDuple extends BasicTokenDuple {
/**
* @param first
* @param last
*/
public SegmentedTokenDuple(IToken first, IToken last) {
super(first, last);
numSegments = calculateSegmentCount();
}
private final int numSegments;
}