mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Andrew Niefer
core: Structural changes to ParserSymbolTable: - moved TypeInfo & Declaration inside ParserSymbolTable - removed the stack & push/pop/peek - moved nonstatic add/lookup fuctions from the table to Declaration - began undo framework: added AddDeclarationCommand tests: Rewrote ParserSymbolTableTest to reflect structural changes to the symbol table.
This commit is contained in:
parent
83f96aa7ee
commit
775f0761ca
6 changed files with 1776 additions and 1915 deletions
|
@ -1,3 +1,10 @@
|
|||
2003-05-05 Andrew Niefer
|
||||
Structural changes to ParserSymbolTable:
|
||||
- moved TypeInfo & Declaration inside ParserSymbolTable
|
||||
- removed the stack & push/pop/peek
|
||||
- moved nonstatic add/lookup fuctions from the table to Declaration
|
||||
- began undo framework: added AddDeclarationCommand
|
||||
|
||||
2003-05-01 Andrew Niefer
|
||||
Fixed Bug 36287 - Parser failure with new CDT 1.1 parser
|
||||
Fixed Bug 37011 - Scanner: #define A "//" not properly handled
|
||||
|
|
|
@ -1,257 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 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:
|
||||
* Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
|
||||
public class Declaration implements Cloneable {
|
||||
|
||||
/**
|
||||
* Constructor for Declaration.
|
||||
*/
|
||||
public Declaration(){
|
||||
super();
|
||||
_typeInfo = new TypeInfo();
|
||||
}
|
||||
|
||||
public Declaration( String name ){
|
||||
super();
|
||||
_name = name;
|
||||
_typeInfo = new TypeInfo();
|
||||
}
|
||||
|
||||
public Declaration( String name, Object obj ){
|
||||
super();
|
||||
_name = name;
|
||||
_object = obj;
|
||||
_typeInfo = new TypeInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* clone
|
||||
* @see java.lang.Object#clone()
|
||||
*
|
||||
* implement clone for the purposes of using declarations.
|
||||
* int _typeInfo; //by assignment
|
||||
* String _name; //by assignment
|
||||
* Object _object; //null this out
|
||||
* Declaration _typeDeclaration; //by assignment
|
||||
* Declaration _containingScope; //by assignment
|
||||
* LinkedList _parentScopes; //shallow copy
|
||||
* LinkedList _usingDirectives; //shallow copy
|
||||
* HashMap _containedDeclarations; //shallow copy
|
||||
* int _depth; //by assignment
|
||||
*/
|
||||
public Object clone(){
|
||||
Declaration copy = null;
|
||||
try{
|
||||
copy = (Declaration)super.clone();
|
||||
}
|
||||
catch ( CloneNotSupportedException e ){
|
||||
//should not happen
|
||||
return null;
|
||||
}
|
||||
|
||||
copy._object = null;
|
||||
copy._parentScopes = ( _parentScopes != null ) ? (LinkedList) _parentScopes.clone() : null;
|
||||
copy._usingDirectives = ( _usingDirectives != null ) ? (LinkedList) _usingDirectives.clone() : null;
|
||||
copy._containedDeclarations = ( _containedDeclarations != null ) ? (HashMap) _containedDeclarations.clone() : null;
|
||||
copy._parameters = ( _parameters != null ) ? (LinkedList) _parameters.clone() : null;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void setType(int t) throws ParserSymbolTableException{
|
||||
_typeInfo.setType( t );
|
||||
}
|
||||
|
||||
public int getType(){
|
||||
return _typeInfo.getType();
|
||||
}
|
||||
|
||||
public boolean isType( int type ){
|
||||
return _typeInfo.isType( type, 0 );
|
||||
}
|
||||
|
||||
public boolean isType( int type, int upperType ){
|
||||
return _typeInfo.isType( type, upperType );
|
||||
}
|
||||
|
||||
public Declaration getTypeDeclaration(){
|
||||
return _typeInfo.getTypeDeclaration();
|
||||
}
|
||||
|
||||
public void setTypeDeclaration( Declaration type ){
|
||||
_typeInfo.setTypeDeclaration( type );
|
||||
}
|
||||
|
||||
public TypeInfo getTypeInfo(){
|
||||
return _typeInfo;
|
||||
}
|
||||
|
||||
public String getName() { return _name; }
|
||||
public void setName(String name) { _name = name; }
|
||||
|
||||
public Object getObject() { return _object; }
|
||||
public void setObject( Object obj ) { _object = obj; }
|
||||
|
||||
public Declaration getContainingScope() { return _containingScope; }
|
||||
protected void setContainingScope( Declaration scope ){
|
||||
_containingScope = scope;
|
||||
_depth = scope._depth + 1;
|
||||
}
|
||||
|
||||
public void addParent( Declaration parent ){
|
||||
addParent( parent, false );
|
||||
}
|
||||
public void addParent( Declaration parent, boolean virtual ){
|
||||
if( _parentScopes == null ){
|
||||
_parentScopes = new LinkedList();
|
||||
}
|
||||
|
||||
_parentScopes.add( new ParentWrapper( parent, virtual ) );
|
||||
}
|
||||
|
||||
public Map getContainedDeclarations(){
|
||||
return _containedDeclarations;
|
||||
}
|
||||
|
||||
public Map createContained(){
|
||||
if( _containedDeclarations == null )
|
||||
_containedDeclarations = new HashMap();
|
||||
|
||||
return _containedDeclarations;
|
||||
}
|
||||
|
||||
public LinkedList getParentScopes(){
|
||||
return _parentScopes;
|
||||
}
|
||||
|
||||
public boolean needsDefinition(){
|
||||
return _needsDefinition;
|
||||
}
|
||||
public void setNeedsDefinition( boolean need ) {
|
||||
_needsDefinition = need;
|
||||
}
|
||||
|
||||
public int getCVQualifier(){
|
||||
return _cvQualifier;
|
||||
}
|
||||
|
||||
public void setCVQualifier( int cv ){
|
||||
_cvQualifier = cv;
|
||||
}
|
||||
|
||||
public String getPtrOperator(){
|
||||
return _typeInfo.getPtrOperator();
|
||||
}
|
||||
public void setPtrOperator( String ptrOp ){
|
||||
_typeInfo.setPtrOperator( ptrOp );
|
||||
}
|
||||
|
||||
public int getReturnType(){
|
||||
return _returnType;
|
||||
}
|
||||
|
||||
public void setReturnType( int type ){
|
||||
_returnType = type;
|
||||
}
|
||||
|
||||
public void addParameter( Declaration typeDecl, int cvQual, String ptrOperator, boolean hasDefault ){
|
||||
if( _parameters == null ){
|
||||
_parameters = new LinkedList();
|
||||
}
|
||||
|
||||
TypeInfo info = new TypeInfo( TypeInfo.t_type, typeDecl, cvQual, ptrOperator, hasDefault );
|
||||
|
||||
_parameters.add( info );
|
||||
}
|
||||
|
||||
public void addParameter( int type, int cvQual, String ptrOperator, boolean hasDefault ){
|
||||
if( _parameters == null ){
|
||||
_parameters = new LinkedList();
|
||||
}
|
||||
|
||||
TypeInfo info = new TypeInfo(type, null, cvQual, ptrOperator, hasDefault );
|
||||
|
||||
_parameters.add( info );
|
||||
}
|
||||
|
||||
public boolean hasSameParameters( Declaration function ){
|
||||
if( function.getType() != getType() ){
|
||||
return false;
|
||||
}
|
||||
|
||||
int size = _parameters.size();
|
||||
if( function._parameters.size() != size ){
|
||||
return false;
|
||||
}
|
||||
|
||||
Iterator iter = _parameters.iterator();
|
||||
Iterator fIter = function._parameters.iterator();
|
||||
|
||||
TypeInfo info = null;
|
||||
TypeInfo fInfo = null;
|
||||
|
||||
for( int i = size; i > 0; i-- ){
|
||||
info = (TypeInfo) iter.next();
|
||||
fInfo = (TypeInfo) fIter.next();
|
||||
|
||||
if( !info.equals( fInfo ) ){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private String _name; //our name
|
||||
private Object _object; //the object associated with us
|
||||
private boolean _needsDefinition; //this name still needs to be defined
|
||||
private int _cvQualifier;
|
||||
//private String _ptrOperator;
|
||||
protected TypeInfo _typeInfo; //our type info
|
||||
protected Declaration _containingScope; //the scope that contains us
|
||||
protected LinkedList _parentScopes; //inherited scopes (is base classes)
|
||||
protected LinkedList _usingDirectives; //collection of nominated namespaces
|
||||
protected HashMap _containedDeclarations; //declarations contained by us.
|
||||
|
||||
protected LinkedList _parameters; //parameter list
|
||||
protected int _returnType;
|
||||
|
||||
protected int _depth; //how far down the scope stack we are
|
||||
|
||||
protected class ParentWrapper
|
||||
{
|
||||
public ParentWrapper( Declaration p, boolean v ){
|
||||
parent = p;
|
||||
isVirtual = v;
|
||||
}
|
||||
|
||||
public boolean isVirtual = false;
|
||||
public Declaration parent = null;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,366 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 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:
|
||||
* Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.core.parser;
|
||||
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change this generated comment edit the template variable "typecomment":
|
||||
* Window>Preferences>Java>Templates.
|
||||
* To enable and disable the creation of type comments go to
|
||||
* Window>Preferences>Java>Code Generation.
|
||||
*/
|
||||
|
||||
public class TypeInfo{
|
||||
public TypeInfo(){
|
||||
super();
|
||||
}
|
||||
|
||||
public TypeInfo( int type, Declaration decl ){
|
||||
super();
|
||||
_typeInfo = type;
|
||||
_typeDeclaration = decl;
|
||||
}
|
||||
|
||||
public TypeInfo( int type, Declaration decl, int cvQualifier, String ptrOp, boolean hasDefault ){
|
||||
super();
|
||||
_typeInfo = type;
|
||||
_typeDeclaration = decl;
|
||||
_cvQualifier = cvQualifier;
|
||||
_ptrOperator = ( ptrOp != null ) ? new String( ptrOp ) : null;
|
||||
_hasDefaultValue = hasDefault;
|
||||
}
|
||||
|
||||
public TypeInfo( TypeInfo info ){
|
||||
super();
|
||||
|
||||
_typeInfo = info._typeInfo;
|
||||
_typeDeclaration = info._typeDeclaration;
|
||||
_cvQualifier = info._cvQualifier;
|
||||
_ptrOperator = ( info._ptrOperator == null ) ? null : new String( info._ptrOperator );
|
||||
_hasDefaultValue = info._hasDefaultValue;
|
||||
}
|
||||
|
||||
public static final int typeMask = 0x001f;
|
||||
public static final int isAuto = 0x0020;
|
||||
public static final int isRegister = 0x0040;
|
||||
public static final int isStatic = 0x0080;
|
||||
public static final int isExtern = 0x0100;
|
||||
public static final int isMutable = 0x0200;
|
||||
public static final int isInline = 0x0400;
|
||||
public static final int isVirtual = 0x0800;
|
||||
public static final int isExplicit = 0x1000;
|
||||
public static final int isTypedef = 0x2000;
|
||||
public static final int isFriend = 0x4000;
|
||||
public static final int isConst = 0x8000;
|
||||
public static final int isVolatile = 0x10000;
|
||||
public static final int isUnsigned = 0x20000;
|
||||
public static final int isShort = 0x40000;
|
||||
public static final int isLong = 0x80000;
|
||||
|
||||
// Types (maximum type is typeMask
|
||||
// Note that these should be considered ordered and if you change
|
||||
// the order, you should consider the ParserSymbolTable uses
|
||||
public static final int t_undef = 0; //not specified
|
||||
public static final int t_type = 1; // Type Specifier
|
||||
public static final int t_namespace = 2;
|
||||
public static final int t_class = 3;
|
||||
public static final int t_struct = 4;
|
||||
public static final int t_union = 5;
|
||||
public static final int t_enumeration = 6;
|
||||
public static final int t_function = 7;
|
||||
public static final int t_bool = 8;
|
||||
public static final int t_char = 9;
|
||||
public static final int t_wchar_t = 10;
|
||||
public static final int t_int = 11;
|
||||
public static final int t_float = 12;
|
||||
public static final int t_double = 13;
|
||||
public static final int t_void = 14;
|
||||
public static final int t_enumerator = 15;
|
||||
|
||||
private static final String _image[] = { "",
|
||||
"",
|
||||
"namespace",
|
||||
"class",
|
||||
"struct",
|
||||
"union",
|
||||
"enum",
|
||||
"",
|
||||
"bool",
|
||||
"char",
|
||||
"wchar_t",
|
||||
"int",
|
||||
"float",
|
||||
"double",
|
||||
"void",
|
||||
""
|
||||
};
|
||||
//Partial ordering :
|
||||
// none < const
|
||||
// none < volatile
|
||||
// none < const volatile
|
||||
// const < const volatile
|
||||
// volatile < const volatile
|
||||
public static final int cvConst = 2;
|
||||
public static final int cvVolatile = 3;
|
||||
public static final int cvConstVolatile = 5;
|
||||
|
||||
// Convenience methods
|
||||
public void setBit(boolean b, int mask){
|
||||
if( b ){
|
||||
_typeInfo = _typeInfo | mask;
|
||||
} else {
|
||||
_typeInfo = _typeInfo & ~mask;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkBit(int mask){
|
||||
return (_typeInfo & mask) != 0;
|
||||
}
|
||||
|
||||
public void setType(int t) throws ParserSymbolTableException{
|
||||
//sanity check, t must fit in its allocated 5 bits in _typeInfo
|
||||
if( t > typeMask ){
|
||||
throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo );
|
||||
}
|
||||
|
||||
_typeInfo = _typeInfo & ~typeMask | t;
|
||||
}
|
||||
|
||||
public int getType(){
|
||||
return _typeInfo & typeMask;
|
||||
}
|
||||
|
||||
public boolean isType( int type ){
|
||||
return isType( type, 0 );
|
||||
}
|
||||
|
||||
public int getTypeInfo(){
|
||||
return _typeInfo;
|
||||
}
|
||||
|
||||
public void setTypeInfo( int typeInfo ){
|
||||
_typeInfo = typeInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type
|
||||
* @param upperType
|
||||
* @return boolean
|
||||
*
|
||||
* type checking, check that this declaration's type is between type and
|
||||
* upperType (inclusive). upperType of 0 means no range and our type must
|
||||
* be type.
|
||||
*/
|
||||
public boolean isType( int type, int upperType ){
|
||||
//type of -1 means we don't care
|
||||
if( type == -1 )
|
||||
return true;
|
||||
|
||||
//upperType of 0 means no range
|
||||
if( upperType == 0 ){
|
||||
return ( getType() == type );
|
||||
} else {
|
||||
return ( getType() >= type && getType() <= upperType );
|
||||
}
|
||||
}
|
||||
|
||||
public Declaration getTypeDeclaration(){
|
||||
return _typeDeclaration;
|
||||
}
|
||||
|
||||
public void setTypeDeclaration( Declaration type ){
|
||||
_typeDeclaration = type;
|
||||
}
|
||||
|
||||
public int getCVQualifier(){
|
||||
return _cvQualifier;
|
||||
}
|
||||
|
||||
public void setCVQualifier( int cv ){
|
||||
_cvQualifier = cv;
|
||||
}
|
||||
|
||||
public void addCVQualifier( int cv ){
|
||||
switch( _cvQualifier ){
|
||||
case 0:
|
||||
_cvQualifier = cv;
|
||||
break;
|
||||
|
||||
case cvConst:
|
||||
if( cv != cvConst ){
|
||||
_cvQualifier = cvConstVolatile;
|
||||
}
|
||||
break;
|
||||
|
||||
case cvVolatile:
|
||||
if( cv != cvVolatile ){
|
||||
_cvQualifier = cvConstVolatile;
|
||||
}
|
||||
break;
|
||||
|
||||
case cvConstVolatile:
|
||||
break; //nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
public String getPtrOperator(){
|
||||
return _ptrOperator;
|
||||
}
|
||||
|
||||
public void setPtrOperator( String ptr ){
|
||||
_ptrOperator = ptr;
|
||||
}
|
||||
|
||||
public void addPtrOperator( String ptr ){
|
||||
if( ptr == null ){
|
||||
return;
|
||||
}
|
||||
|
||||
char chars[] = ( _ptrOperator == null ) ? ptr.toCharArray() : ( ptr + _ptrOperator ).toCharArray();
|
||||
|
||||
int nChars = ( _ptrOperator == null ) ? ptr.length() : ptr.length() + _ptrOperator.length();
|
||||
|
||||
char dest[] = new char [ nChars ];
|
||||
int j = 0;
|
||||
|
||||
char currChar, nextChar, tempChar;
|
||||
|
||||
for( int i = 0; i < nChars; i++ ){
|
||||
currChar = chars[ i ];
|
||||
nextChar = ( i + 1 < nChars ) ? chars[ i + 1 ] : 0;
|
||||
|
||||
switch( currChar ){
|
||||
case '&':{
|
||||
switch( nextChar ){
|
||||
case '[':
|
||||
tempChar = ( i + 2 < nChars ) ? chars[ i + 2 ] : 0;
|
||||
if( tempChar == ']' ){
|
||||
i++;
|
||||
nextChar = '*';
|
||||
}
|
||||
//fall through to '*'
|
||||
case '*':
|
||||
i++;
|
||||
break;
|
||||
case '&':
|
||||
default:
|
||||
dest[ j++ ] = currChar;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '[':{
|
||||
if( nextChar == ']' ){
|
||||
i++;
|
||||
currChar = '*';
|
||||
nextChar = ( i + 2 < nChars ) ? chars[ i + 2 ] : 0;
|
||||
}
|
||||
//fall through to '*'
|
||||
}
|
||||
case '*':{
|
||||
|
||||
if( nextChar == '&' ){
|
||||
i++;
|
||||
} else {
|
||||
dest[ j++ ] = currChar;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
_ptrOperator = new String( dest, 0, j );
|
||||
}
|
||||
|
||||
public String getInvertedPtrOperator(){
|
||||
if( _ptrOperator == null ){
|
||||
return null;
|
||||
}
|
||||
|
||||
char chars[] = _ptrOperator.toCharArray();
|
||||
int nChars = _ptrOperator.length();
|
||||
|
||||
char dest[] = new char [ nChars ];
|
||||
char currChar;
|
||||
|
||||
for( int i = 0; i < nChars; i++ ){
|
||||
currChar = chars[ i ];
|
||||
switch( currChar ){
|
||||
case '*' : dest[ i ] = '&'; break;
|
||||
case '&' : dest[ i ] = '*'; break;
|
||||
default: dest[ i ] = currChar; break;
|
||||
}
|
||||
}
|
||||
|
||||
return new String( dest );
|
||||
}
|
||||
|
||||
public boolean getHasDefault(){
|
||||
return _hasDefaultValue;
|
||||
}
|
||||
|
||||
public void setHasDefault( boolean def ){
|
||||
_hasDefaultValue = def;
|
||||
}
|
||||
|
||||
/**
|
||||
* canHold
|
||||
* @param type
|
||||
* @return boolean
|
||||
* return true is the our type can hold all the values of the passed in
|
||||
* type.
|
||||
* TBD, for now return true if our type is "larger" (based on ordering of
|
||||
* the type values)
|
||||
*/
|
||||
public boolean canHold( TypeInfo type ){
|
||||
return getType() >= type.getType();
|
||||
}
|
||||
|
||||
public boolean equals( Object t ){
|
||||
if( t == null || !(t instanceof TypeInfo) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeInfo type = (TypeInfo)t;
|
||||
|
||||
boolean result = ( _typeInfo == type._typeInfo );
|
||||
result &= ( _typeDeclaration == type._typeDeclaration );
|
||||
result &= ( _cvQualifier == type._cvQualifier );
|
||||
|
||||
String op1 = ( _ptrOperator != null && _ptrOperator.equals("") ) ? null : _ptrOperator;
|
||||
String op2 = ( type._ptrOperator != null && type._ptrOperator.equals("") ) ? null : type._ptrOperator;
|
||||
result &= (( op1 != null && op2 != null && op1.equals( op2 ) ) || op1 == op2 );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
if( isType( t_type ) ){
|
||||
return _typeDeclaration.getName();
|
||||
} else {
|
||||
return _image[ getType() ];
|
||||
}
|
||||
}
|
||||
|
||||
private int _typeInfo = 0;
|
||||
private Declaration _typeDeclaration;
|
||||
private int _cvQualifier = 0;
|
||||
|
||||
private boolean _hasDefaultValue = false;
|
||||
private String _ptrOperator;
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
2003-05-05 Andrew Niefer
|
||||
Rewrote ParserSymbolTableTest to reflect structural changes to the symbol table.
|
||||
|
||||
2003-05-01 Andrew Niefer
|
||||
Updated FractionalAutomatedTest to use threads
|
||||
Modified ScannerTestCase::testBug36287
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue