diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 91312df8157..8cacfb59374 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declaration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declaration.java deleted file mode 100644 index 3233cd17f90..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Declaration.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java index 730aaf26871..af4b4f370fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java @@ -20,7 +20,7 @@ import java.util.LinkedList; import java.util.ListIterator; import java.util.Map; import java.util.Set; -import java.util.Stack; +//import java.util.Stack; /** @@ -45,511 +45,12 @@ public class ParserSymbolTable { } catch ( ParserSymbolTableException e ){ /*shouldn't happen*/ } - - push( _compilationUnit ); } - public void push( Declaration obj ){ - if( _contextStack.empty() == false && obj.getContainingScope() == null ){ - obj.setContainingScope( (Declaration) _contextStack.peek() ); - } - - _contextStack.push( obj ); - } - - public Declaration pop(){ - return (Declaration) _contextStack.pop(); - } - - public Declaration peek(){ - return (Declaration) _contextStack.peek(); - } - public Declaration getCompilationUnit(){ return _compilationUnit; } - - public Declaration Lookup( String name ) throws ParserSymbolTableException { - LookupData data = new LookupData( name, -1 ); - - Lookup( data, (Declaration) _contextStack.peek() ); - - return ResolveAmbiguities( data ); - } - - public Declaration ElaboratedLookup( int type, String name ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, type ); - - Lookup( data, (Declaration) _contextStack.peek() ); - - return ResolveAmbiguities( data ); - } - /** - * Method LookupNestedNameSpecifier. - * @param name - * @return Declaration - * The name of a class or namespace member can be referred to after the :: - * scope resolution operator applied to a nested-name-specifier that - * nominates its class or namespace. During the lookup for a name preceding - * the ::, object, function and enumerator names are ignored. If the name - * is not a class-name or namespace-name, the program is ill-formed - */ - - public Declaration LookupNestedNameSpecifier( String name ) throws ParserSymbolTableException { - return LookupNestedNameSpecifier( name, (Declaration) _contextStack.peek() ); - } - - private Declaration LookupNestedNameSpecifier(String name, Declaration inDeclaration ) throws ParserSymbolTableException{ - Declaration foundDeclaration = null; - - LookupData data = new LookupData( name, TypeInfo.t_namespace ); - data.upperType = TypeInfo.t_union; - - LookupInContained( data, inDeclaration ); - - if( data.foundItems != null ){ - foundDeclaration = ResolveAmbiguities( data );//, data.foundItems ); - } - - if( foundDeclaration == null && inDeclaration._containingScope != null ){ - foundDeclaration = LookupNestedNameSpecifier( name, inDeclaration._containingScope ); - } - - return foundDeclaration; - } - - /** - * LookupMemberForDefinition - * @param name - * @return Declaration - * @throws ParserSymbolTableException - * - * In a definition for a namespace member in which the declarator-id is a - * qualified-id, given that the qualified-id for the namespace member has - * the form "nested-name-specifier unqualified-id", the unqualified-id shall - * name a member of the namespace designated by the nested-name-specifier. - * - * ie: - * you have this: - * namespace A{ - * namespace B{ - * void f1(int); - * } - * using namespace B; - * } - * - * if you then do this - * void A::f1(int) { ... } //ill-formed, f1 is not a member of A - * but, you can do this (Assuming f1 has been defined elsewhere) - * A::f1( 1 ); //ok, finds B::f1 - * - * ie, We need a seperate lookup function for looking up the member names - * for a definition. - */ - public Declaration LookupMemberForDefinition( String name ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, -1 ); - data.qualified = true; - - LookupInContained( data, (Declaration) _contextStack.peek() ); - - return ResolveAmbiguities( data ); - } - - /** - * - * @param name - * @return Declaration - * @throws ParserSymbolTableException - * - */ - public Declaration QualifiedLookup( String name ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, -1 ); - data.qualified = true; - Lookup( data, (Declaration) _contextStack.peek() ); - - return ResolveAmbiguities( data ); - } - - /** - * - * @param name - * @param parameters - * @return Declaration - * @throws ParserSymbolTableException - */ - public Declaration QualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, TypeInfo.t_function ); - data.qualified = true; - //if parameters == null, thats no parameters, but we need to distinguish that from - //no parameter information at all, so make an empty list. - data.parameters = ( parameters == null ) ? new LinkedList() : parameters; - - Lookup( data, (Declaration) _contextStack.peek() ); - - return ResolveAmbiguities( data ); - } - - /** - * MemberFunctionLookup - * @param name - * @param parameters - * @return Declaration - * @throws ParserSymbolTableException - * - * Member lookup really proceeds as an unqualified lookup, but doesn't - * include argument dependant scopes - */ - public Declaration MemberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, TypeInfo.t_function ); - //if parameters == null, thats no parameters, but we need to distinguish that from - //no parameter information at all, so make an empty list. - data.parameters = ( parameters == null ) ? new LinkedList() : parameters; - - Lookup( data, (Declaration) _contextStack.peek() ); - return ResolveAmbiguities( data ); - } - - /** - * UnqualifiedFunctionLookup - * @param name - * @param parameters - * @return Declaration - * @throws ParserSymbolTableException - * - * 3.4.2-1 When an unqualified name is used as the post-fix expression in a - * function call, other namespaces not consdiered during the usual - * unqualified lookup may be searched. - * - * 3.4.2-2 For each argument type T in the function call, there is a set of - * zero or more associated namespaces and a set of zero or more associated - * classes to be considered. - * - * If the ordinary unqualified lookup of the name find the declaration of a - * class member function, the associated namespaces and classes are not - * considered. Otherwise, the set of declarations found by the lookup of - * the function name is the union of the set of declarations found using - * ordinary unqualified lookup and the set of declarations found in the - * namespaces and classes associated with the argument types. - */ - public Declaration UnqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ - //figure out the set of associated scopes first, so we can remove those that are searched - //during the normal lookup to avoid doing them twice - HashSet associated = new HashSet(); - - //collect associated namespaces & classes. - int size = ( parameters == null ) ? 0 : parameters.size(); - Iterator iter = ( parameters == null ) ? null : parameters.iterator(); - - TypeInfo param = null; - Declaration paramType = null; - for( int i = size; i > 0; i-- ){ - param = (TypeInfo) iter.next(); - paramType = getFlatTypeInfo( param ).getTypeDeclaration(); - - getAssociatedScopes( paramType, associated ); - - //if T is a pointer to a data member of class X, its associated namespaces and classes - //are those associated with the member type together with those associated with X - if( param.getPtrOperator() != null && - (param.getPtrOperator().equals("*") || param.getPtrOperator().equals("[]")) && - paramType._containingScope.isType( TypeInfo.t_class, TypeInfo.t_union ) ) - { - getAssociatedScopes( paramType._containingScope, associated ); - } - } - - LookupData data = new LookupData( name, TypeInfo.t_function ); - //if parameters == null, thats no parameters, but we need to distinguish that from - //no parameter information at all, so make an empty list. - data.parameters = ( parameters == null ) ? new LinkedList() : parameters; - data.associated = associated; - - Lookup( data, (Declaration) _contextStack.peek() ); - - Declaration found = ResolveAmbiguities( data ); - - //if we haven't found anything, or what we found is not a class member, consider the - //associated scopes - if( found == null || found._containingScope.getType() != TypeInfo.t_class ){ - if( found != null ){ - data.foundItems.add( found ); - } - - Declaration decl; - Declaration temp; - - //dump the hash to an array and iterate over the array because we - //could be removing items from the collection as we go and we don't - //want to get ConcurrentModificationExceptions - Object [] scopes = associated.toArray(); - - size = associated.size(); - - for( int i = 0; i < size; i++ ){ - decl = (Declaration) scopes[ i ]; - if( associated.contains( decl ) ){ - data.qualified = true; - data.ignoreUsingDirectives = true; - Lookup( data, decl ); - } - } - - found = ResolveAmbiguities( data ); - } - - return found; - } - - /** - * LookupForFriendship - * @param name - * @return Declaration - * 7.3.1.2-3 When looking for a prior declaration of a class or a function - * declared as a friend, scopes outside the innermost enclosing namespace - * scope are not considered. - * 11.4-9 If a friend declaration appears in a local class and the name - * specified is an unqualified name, a prior declaration is looked up - * without considering scopes that are outside the innermost enclosing non- - * class scope. - */ - private Declaration LookupForFriendship( String name ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, -1 ); - - Declaration decl = (Declaration) _contextStack.peek(); - boolean inClass = (decl.getType() == TypeInfo.t_class); - - Declaration enclosing = decl._containingScope; - while( enclosing != null && (inClass ? enclosing.getType() != TypeInfo.t_class - : enclosing.getType() == TypeInfo.t_namespace) ) - { - enclosing = enclosing._containingScope; - } - - data.stopAt = enclosing; - - Lookup( data, (Declaration) _contextStack.peek() ); - - return ResolveAmbiguities( data ); - } - - public void addUsingDirective( Declaration namespace ) throws ParserSymbolTableException{ - if( namespace.getType() != TypeInfo.t_namespace ){ - throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); - } - - Declaration declaration = (Declaration) _contextStack.peek(); - - if( declaration._usingDirectives == null ){ - declaration._usingDirectives = new LinkedList(); - } - - declaration._usingDirectives.add( namespace ); - } - - /** - * addUsingDeclaration - * @param obj - * @throws ParserSymbolTableException - * - * 7.3.3-9 The entity declared by a using-declaration shall be known in the - * context using it according to its definition at the point of the using- - * declaration. Definitions added to the namespace after the using- - * declaration are not considered when a use of the name is made. - * - * 7.3.3-4 A using-declaration used as a member-declaration shall refer to a - * member of a base class of the class being defined, shall refer to a - * member of an anonymous union that is a member of a base class of the - * class being defined, or shall refer to an enumerator for an enumeration - * type that is a member of a base class of the class being defined. - */ - public Declaration addUsingDeclaration( String name ) throws ParserSymbolTableException { - return addUsingDeclaration( name, null ); - } - - public Declaration addUsingDeclaration( String name, Declaration declContext ) throws ParserSymbolTableException{ - LookupData data = new LookupData( name, -1 ); - - if( declContext != null ){ - push( declContext ); - data.qualified = true; - Lookup( data, (Declaration) _contextStack.peek() ); - pop(); - } else { - Lookup( data, (Declaration) _contextStack.peek() ); - } - - //figure out which declaration we are talking about, if it is a set of functions, - //then they will be in data.foundItems (since we provided no parameter info); - Declaration obj = ResolveAmbiguities( data ); - - if( data.foundItems == null ){ - throw new ParserSymbolTableException(); - } - - Declaration clone = null; - - //if obj != null, then that is the only object to consider, so size is 1, - //otherwise we consider the foundItems set - int size = ( obj == null ) ? data.foundItems.size() : 1; - Iterator iter = data.foundItems.iterator(); - for( int i = size; i > 0; i-- ){ - obj = ( obj != null && size == 1 ) ? obj : (Declaration) iter.next(); - - if( okToAddUsingDeclaration( obj, (Declaration) _contextStack.peek() ) ){ - clone = (Declaration) obj.clone(); //7.3.3-9 - addDeclaration( clone ); - } else { - throw new ParserSymbolTableException(); - } - } - - return ( size == 1 ) ? clone : null; - } - - public void addDeclaration( Declaration obj ) throws ParserSymbolTableException{ - - Declaration containing = (Declaration) _contextStack.peek(); - - //handle enumerators - if( obj.getType() == TypeInfo.t_enumerator ){ - //a using declaration of an enumerator will not be contained in a - //enumeration. - if( containing.getType() == TypeInfo.t_enumeration ){ - //Following the closing brace of an enum-specifier, each enumerator has the type of its - //enumeration - obj.setTypeDeclaration( containing ); - //Each enumerator is declared in the scope that immediately contains the enum-specifier - containing = containing.getContainingScope(); - } - } - - Map declarations = containing.getContainedDeclarations(); - - boolean unnamed = obj.getName().equals( "" ); - - Object origObj = null; - - obj.setContainingScope( containing ); - - if( declarations == null ){ - declarations = containing.createContained(); - } else { - //does this name exist already? - origObj = declarations.get( obj.getName() ); - } - - if( origObj != null ) - { - Declaration origDecl = null; - LinkedList origList = null; - - if( origObj.getClass() == Declaration.class ){ - origDecl = (Declaration)origObj; - } else if( origObj.getClass() == LinkedList.class ){ - origList = (LinkedList)origObj; - } else { - throw new ParserSymbolTableException(); - } - - if( unnamed || (origList == null) ? isValidOverload( origDecl, obj ) : isValidOverload( origList, obj ) ){ - if( origList == null ){ - origList = new LinkedList(); - origList.add( origDecl ); - origList.add( obj ); - - declarations.remove( obj ); - declarations.put( obj.getName(), origList ); - } else { - origList.add( obj ); - //origList is already in _containedDeclarations - } - } else { - throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload ); - } - } else { - declarations.put( obj.getName(), obj ); - } - - //take care of the this pointer - TypeInfo type = obj._typeInfo; - if( type.isType( TypeInfo.t_function ) && !type.checkBit( TypeInfo.isStatic ) ){ - addThis( obj ); - } - } - - /** - * - * @param name - * @return Declaration - * @throws ParserSymbolTableException - * - * 7.3.1.2-3 If a friend declaration in a non-local class first declares a - * class or function, the friend class or function is a member of the - * innermost enclosing namespace. - * - * TBD: if/when the parser symbol table starts caring about visibility - * (public/protected/private) we will need to do more to record friendship. - */ - public Declaration addFriend( String name ) throws ParserSymbolTableException{ - Declaration friend = LookupForFriendship( name ); - - if( friend == null ){ - friend = new Declaration( name ); - friend.setNeedsDefinition( true ); - - Declaration decl = (Declaration) _contextStack.peek(); - Declaration containing = decl._containingScope; - //find innermost enclosing namespace - while( containing != null && containing.getType() != TypeInfo.t_namespace ){ - containing = containing._containingScope; - } - - Declaration namespace = (containing == null ) ? _compilationUnit : containing; - push( namespace ); - addDeclaration( friend ); - pop(); - } - - return friend; - } - - /** - * - * @param obj - * @throws ParserSymbolTableException - * 9.3.2-1 In the body of a nonstatic member function... the type of this of - * a class X is X*. If the member function is declared const, the type of - * this is const X*, if the member function is declared volatile, the type - * of this is volatile X*.... - */ - private void addThis( Declaration obj ) throws ParserSymbolTableException{ - TypeInfo type = obj._typeInfo; - if( !type.isType( TypeInfo.t_function ) || type.checkBit( TypeInfo.isStatic ) ){ - return; - } - - if( obj._containingScope.isType( TypeInfo.t_class, TypeInfo.t_union ) ){ - //check to see if there is already a this object, since using declarations - //of function will have them from the original declaration - LookupData data = new LookupData( "this", -1 ); - LookupInContained( data, obj ); - //if we didn't find "this" then foundItems will still be null, no need to actually - //check its contents - if( data.foundItems == null ){ - Declaration thisObj = new Declaration("this"); - thisObj.setType( TypeInfo.t_type ); - thisObj.setTypeDeclaration( obj._containingScope ); - thisObj.setCVQualifier( obj.getCVQualifier() ); - thisObj.setPtrOperator("*"); - - push( obj ); - addDeclaration( thisObj ); - pop(); - } - } - } - /** * Lookup the name from LookupData starting in the inDeclaration * @param data @@ -583,8 +84,8 @@ public class ParserSymbolTable { if( !data.qualified || data.foundItems == null ){ ProcessDirectives( inDeclaration, data, transitives ); - if( inDeclaration._usingDirectives != null ){ - ProcessDirectives( inDeclaration, data, inDeclaration._usingDirectives ); + if( inDeclaration.getUsingDirectives() != null ){ + ProcessDirectives( inDeclaration, data, inDeclaration.getUsingDirectives() ); } while( data.usingDirectives != null && data.usingDirectives.get( inDeclaration ) != null ){ @@ -674,9 +175,9 @@ public class ParserSymbolTable { //only consider the transitive using directives if we are an unqualified //lookup, or we didn't find the name in decl - if( (!data.qualified || !foundSomething ) && decl._usingDirectives != null ){ + if( (!data.qualified || !foundSomething ) && decl.getUsingDirectives() != null ){ //name wasn't found, add transitive using directives for later consideration - transitiveDirectives.addAll( decl._usingDirectives ); + transitiveDirectives.addAll( decl.getUsingDirectives() ); } } } @@ -804,7 +305,7 @@ public class ParserSymbolTable { } else if ( temp != null ) { //it is not ambiguous if temp & decl are the same thing and it is static //or an enumerator - TypeInfo type = temp._typeInfo; + TypeInfo type = temp.getTypeInfo(); if( decl == temp && ( type.checkBit( TypeInfo.isStatic ) || type.isType( TypeInfo.t_enumerator ) ) ){ temp = null; @@ -886,7 +387,7 @@ public class ParserSymbolTable { if( origDecl.hasSameParameters( newDecl ) ){ //functions with the same name and same parameter types cannot be overloaded if any of them //is static - if( origDecl._typeInfo.checkBit( TypeInfo.isStatic ) || newDecl._typeInfo.checkBit( TypeInfo.isStatic ) ){ + if( origDecl.getTypeInfo().checkBit( TypeInfo.isStatic ) || newDecl.getTypeInfo().checkBit( TypeInfo.isStatic ) ){ return false; } @@ -1082,10 +583,10 @@ public class ParserSymbolTable { currFn = (Declaration) iterFns.next(); sourceParams = data.parameters.iterator(); - targetParams = currFn._parameters.iterator(); + targetParams = currFn.getParameters().iterator(); //number of parameters in the current function - numTargetParams = currFn._parameters.size(); + numTargetParams = currFn.getParameters().size(); //we only need to look at the smaller number of parameters //(a larger number in the Target means default parameters, a larger @@ -1169,7 +670,7 @@ public class ParserSymbolTable { Iterator iter = functions.iterator(); while( iter.hasNext() ){ function = (Declaration) iter.next(); - num = ( function._parameters == null ) ? 0 : function._parameters.size(); + num = ( function.getParameters() == null ) ? 0 : function.getParameters().size(); //if there are m arguments in the list, all candidate functions having m parameters //are viable @@ -1186,7 +687,7 @@ public class ParserSymbolTable { //a candidate function having more than m parameters is viable only if the (m+1)-st //parameter has a default argument else { - ListIterator listIter = function._parameters.listIterator( num ); + ListIterator listIter = function.getParameters().listIterator( num ); TypeInfo param; for( int i = num; i > ( numParameters - num + 1); i-- ){ param = (TypeInfo)listIter.previous(); @@ -1262,9 +763,9 @@ public class ParserSymbolTable { return decl1; } - if( decl1._depth == decl2._depth ){ + if( decl1.getDepth() == decl2.getDepth() ){ return getClosestEnclosingDeclaration( decl1._containingScope, decl2._containingScope ); - } else if( decl1._depth > decl2._depth ) { + } else if( decl1.getDepth() > decl2.getDepth() ) { return getClosestEnclosingDeclaration( decl1._containingScope, decl2 ); } else { return getClosestEnclosingDeclaration( decl1, decl2._containingScope ); @@ -1290,12 +791,12 @@ public class ParserSymbolTable { return 0; } - if( obj._parentScopes != null ){ + if( obj.getParentScopes() != null ){ Declaration decl; Declaration.ParentWrapper wrapper; - Iterator iter = obj._parentScopes.iterator(); - int size = obj._parentScopes.size(); + Iterator iter = obj.getParentScopes().iterator(); + int size = obj.getParentScopes().size(); for( int i = size; i > 0; i-- ){ wrapper = (Declaration.ParentWrapper) iter.next(); @@ -1336,13 +837,13 @@ public class ParserSymbolTable { } static private void getBaseClassesAndContainingNamespaces( Declaration obj, HashSet classes ){ - if( obj._parentScopes != null ){ + if( obj.getParentScopes() != null ){ if( classes == null ){ return; } - Iterator iter = obj._parentScopes.iterator(); - int size = obj._parentScopes.size(); + Iterator iter = obj.getParentScopes().iterator(); + int size = obj.getParentScopes().size(); Declaration.ParentWrapper wrapper; Declaration base; @@ -1691,10 +1192,52 @@ public class ParserSymbolTable { return returnInfo; } - - - private Stack _contextStack = new Stack(); + + //private Stack _contextStack = new Stack(); private Declaration _compilationUnit; + private LinkedList undoList = new LinkedList(); + + static abstract private class Command{ + abstract public void undoIt(); + } + + static private class AddDeclarationCommand extends Command{ + AddDeclarationCommand( Declaration newDecl, Declaration context, boolean removeThis ){ + _decl = newDecl; + _context = context; + _removeThis = removeThis; + } + public void undoIt(){ + Object obj = _context.getContainedDeclarations().get( _decl.getName() ); + + if( obj instanceof LinkedList ){ + LinkedList list = (LinkedList)obj; + ListIterator iter = list.listIterator(); + int size = list.size(); + Declaration item = null; + for( int i = 0; i < size; i++ ){ + item = (Declaration)iter.next(); + if( item == _decl ){ + iter.remove(); + break; + } + } + if( list.size() == 1 ){ + _context.getContainedDeclarations().remove( _decl.getName() ); + _context.getContainedDeclarations().put( _decl.getName(), list.getFirst() ); + } + } else if( obj instanceof Declaration ){ + _context.getContainedDeclarations().remove( _decl.getName() ); + } + if( _removeThis ){ + _context.getContainedDeclarations().remove( "this" ); + } + } + + private Declaration _decl; + private Declaration _context; + private boolean _removeThis; + } static private class LookupData { @@ -1780,4 +1323,1046 @@ public class ParserSymbolTable { } } + 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; + } + + private int getDepth(){ + return _depth; + } + + 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 LinkedList getParameters(){ + return _parameters; + } + + 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 = getParameters().size(); + if( function.getParameters().size() != size ){ + return false; + } + + Iterator iter = getParameters().iterator(); + Iterator fIter = function.getParameters().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; + } + + public void addDeclaration( Declaration obj ) throws ParserSymbolTableException{ + Declaration containing = this; + + //handle enumerators + if( obj.getType() == TypeInfo.t_enumerator ){ + //a using declaration of an enumerator will not be contained in a + //enumeration. + if( containing.getType() == TypeInfo.t_enumeration ){ + //Following the closing brace of an enum-specifier, each enumerator has the type of its + //enumeration + obj.setTypeDeclaration( containing ); + //Each enumerator is declared in the scope that immediately contains the enum-specifier + containing = containing.getContainingScope(); + } + } + + Map declarations = containing.getContainedDeclarations(); + + boolean unnamed = obj.getName().equals( "" ); + + Object origObj = null; + + obj.setContainingScope( containing ); + + if( declarations == null ){ + declarations = containing.createContained(); + } else { + //does this name exist already? + origObj = declarations.get( obj.getName() ); + } + + if( origObj != null ) + { + Declaration origDecl = null; + LinkedList origList = null; + + if( origObj.getClass() == Declaration.class ){ + origDecl = (Declaration)origObj; + } else if( origObj.getClass() == LinkedList.class ){ + origList = (LinkedList)origObj; + } else { + throw new ParserSymbolTableException(); + } + + if( unnamed || (origList == null) ? isValidOverload( origDecl, obj ) : isValidOverload( origList, obj ) ){ + if( origList == null ){ + origList = new LinkedList(); + origList.add( origDecl ); + origList.add( obj ); + + declarations.remove( obj ); + declarations.put( obj.getName(), origList ); + } else { + origList.add( obj ); + //origList is already in _containedDeclarations + } + } else { + throw new ParserSymbolTableException( ParserSymbolTableException.r_InvalidOverload ); + } + } else { + declarations.put( obj.getName(), obj ); + } + + //take care of the this pointer + TypeInfo type = obj.getTypeInfo(); + boolean addedThis = false; + if( type.isType( TypeInfo.t_function ) && !type.checkBit( TypeInfo.isStatic ) ){ + addThis( obj ); + addedThis = true; + } + + Command command = new AddDeclarationCommand( obj, containing, addedThis ); + } + + /** + * + * @param obj + * @throws ParserSymbolTableException + * 9.3.2-1 In the body of a nonstatic member function... the type of this of + * a class X is X*. If the member function is declared const, the type of + * this is const X*, if the member function is declared volatile, the type + * of this is volatile X*.... + */ + private void addThis( Declaration obj ) throws ParserSymbolTableException{ + TypeInfo type = obj.getTypeInfo(); + if( !type.isType( TypeInfo.t_function ) || type.checkBit( TypeInfo.isStatic ) ){ + return; + } + + if( obj.getContainingScope().isType( TypeInfo.t_class, TypeInfo.t_union ) ){ + //check to see if there is already a this object, since using declarations + //of function will have them from the original declaration + LookupData data = new LookupData( "this", -1 ); + LookupInContained( data, obj ); + //if we didn't find "this" then foundItems will still be null, no need to actually + //check its contents + if( data.foundItems == null ){ + Declaration thisObj = new Declaration("this"); + thisObj.setType( TypeInfo.t_type ); + thisObj.setTypeDeclaration( obj.getContainingScope() ); + thisObj.setCVQualifier( obj.getCVQualifier() ); + thisObj.setPtrOperator("*"); + + obj.addDeclaration( thisObj ); + } + } + } + + /** + * + * @param name + * @return Declaration + * @throws ParserSymbolTableException + * + * 7.3.1.2-3 If a friend declaration in a non-local class first declares a + * class or function, the friend class or function is a member of the + * innermost enclosing namespace. + * + * TBD: if/when the parser symbol table starts caring about visibility + * (public/protected/private) we will need to do more to record friendship. + */ + public Declaration addFriend( String name ) throws ParserSymbolTableException{ + Declaration friend = LookupForFriendship( name ); + + if( friend == null ){ + friend = new Declaration( name ); + friend.setNeedsDefinition( true ); + + Declaration containing = getContainingScope(); + //find innermost enclosing namespace + while( containing != null && containing.getType() != TypeInfo.t_namespace ){ + containing = containing.getContainingScope(); + } + + Declaration namespace = ( containing == null ) ? ParserSymbolTable.this.getCompilationUnit() : containing; + namespace.addDeclaration( friend ); + } + + return friend; + } + + /** + * LookupForFriendship + * @param name + * @return Declaration + * 7.3.1.2-3 When looking for a prior declaration of a class or a function + * declared as a friend, scopes outside the innermost enclosing namespace + * scope are not considered. + * 11.4-9 If a friend declaration appears in a local class and the name + * specified is an unqualified name, a prior declaration is looked up + * without considering scopes that are outside the innermost enclosing non- + * class scope. + */ + private Declaration LookupForFriendship( String name ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, -1 ); + + boolean inClass = ( getType() == TypeInfo.t_class); + + Declaration enclosing = getContainingScope(); + while( enclosing != null && (inClass ? enclosing.getType() != TypeInfo.t_class + : enclosing.getType() == TypeInfo.t_namespace) ) + { + enclosing = enclosing.getContainingScope(); + } + + data.stopAt = enclosing; + + ParserSymbolTable.Lookup( data, this ); + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + /** + * addUsingDeclaration + * @param obj + * @throws ParserSymbolTableException + * + * 7.3.3-9 The entity declared by a using-declaration shall be known in the + * context using it according to its definition at the point of the using- + * declaration. Definitions added to the namespace after the using- + * declaration are not considered when a use of the name is made. + * + * 7.3.3-4 A using-declaration used as a member-declaration shall refer to a + * member of a base class of the class being defined, shall refer to a + * member of an anonymous union that is a member of a base class of the + * class being defined, or shall refer to an enumerator for an enumeration + * type that is a member of a base class of the class being defined. + */ + public Declaration addUsingDeclaration( String name ) throws ParserSymbolTableException { + return addUsingDeclaration( name, null ); + } + + public Declaration addUsingDeclaration( String name, Declaration declContext ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, -1 ); + + if( declContext != null ){ + data.qualified = true; + ParserSymbolTable.Lookup( data, declContext ); + } else { + ParserSymbolTable.Lookup( data, this ); + } + + //figure out which declaration we are talking about, if it is a set of functions, + //then they will be in data.foundItems (since we provided no parameter info); + Declaration obj = ParserSymbolTable.ResolveAmbiguities( data ); + + if( data.foundItems == null ){ + throw new ParserSymbolTableException(); + } + + Declaration clone = null; + + //if obj != null, then that is the only object to consider, so size is 1, + //otherwise we consider the foundItems set + int size = ( obj == null ) ? data.foundItems.size() : 1; + Iterator iter = data.foundItems.iterator(); + for( int i = size; i > 0; i-- ){ + obj = ( obj != null && size == 1 ) ? obj : (Declaration) iter.next(); + + if( ParserSymbolTable.okToAddUsingDeclaration( obj, this ) ){ + clone = (Declaration) obj.clone(); //7.3.3-9 + addDeclaration( clone ); + } else { + throw new ParserSymbolTableException(); + } + } + + return ( size == 1 ) ? clone : null; + } + + public void addUsingDirective( Declaration namespace ) throws ParserSymbolTableException{ + if( namespace.getType() != TypeInfo.t_namespace ){ + throw new ParserSymbolTableException( ParserSymbolTableException.r_BadTypeInfo ); + } + + if( _usingDirectives == null ){ + _usingDirectives = new LinkedList(); + } + + _usingDirectives.add( namespace ); + } + + public LinkedList getUsingDirectives(){ + return _usingDirectives; + } + + public Declaration ElaboratedLookup( int type, String name ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, type ); + + ParserSymbolTable.Lookup( data, this ); + + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + public Declaration Lookup( String name ) throws ParserSymbolTableException { + LookupData data = new LookupData( name, -1 ); + + ParserSymbolTable.Lookup( data, this ); + + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + /** + * LookupMemberForDefinition + * @param name + * @return Declaration + * @throws ParserSymbolTableException + * + * In a definition for a namespace member in which the declarator-id is a + * qualified-id, given that the qualified-id for the namespace member has + * the form "nested-name-specifier unqualified-id", the unqualified-id shall + * name a member of the namespace designated by the nested-name-specifier. + * + * ie: + * you have this: + * namespace A{ + * namespace B{ + * void f1(int); + * } + * using namespace B; + * } + * + * if you then do this + * void A::f1(int) { ... } //ill-formed, f1 is not a member of A + * but, you can do this (Assuming f1 has been defined elsewhere) + * A::f1( 1 ); //ok, finds B::f1 + * + * ie, We need a seperate lookup function for looking up the member names + * for a definition. + */ + public Declaration LookupMemberForDefinition( String name ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, -1 ); + data.qualified = true; + + ParserSymbolTable.LookupInContained( data, this ); + + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + /** + * Method LookupNestedNameSpecifier. + * @param name + * @return Declaration + * The name of a class or namespace member can be referred to after the :: + * scope resolution operator applied to a nested-name-specifier that + * nominates its class or namespace. During the lookup for a name preceding + * the ::, object, function and enumerator names are ignored. If the name + * is not a class-name or namespace-name, the program is ill-formed + */ + public Declaration LookupNestedNameSpecifier( String name ) throws ParserSymbolTableException { + return LookupNestedNameSpecifier( name, this ); + } + private Declaration LookupNestedNameSpecifier(String name, Declaration inDeclaration ) throws ParserSymbolTableException{ + Declaration foundDeclaration = null; + + LookupData data = new LookupData( name, TypeInfo.t_namespace ); + data.upperType = TypeInfo.t_union; + + ParserSymbolTable.LookupInContained( data, inDeclaration ); + + if( data.foundItems != null ){ + foundDeclaration = ParserSymbolTable.ResolveAmbiguities( data );//, data.foundItems ); + } + + if( foundDeclaration == null && inDeclaration.getContainingScope() != null ){ + foundDeclaration = LookupNestedNameSpecifier( name, inDeclaration.getContainingScope() ); + } + + return foundDeclaration; + } + + /** + * MemberFunctionLookup + * @param name + * @param parameters + * @return Declaration + * @throws ParserSymbolTableException + * + * Member lookup really proceeds as an unqualified lookup, but doesn't + * include argument dependant scopes + */ + public Declaration MemberFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, TypeInfo.t_function ); + //if parameters == null, thats no parameters, but we need to distinguish that from + //no parameter information at all, so make an empty list. + data.parameters = ( parameters == null ) ? new LinkedList() : parameters; + + ParserSymbolTable.Lookup( data, this ); + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + public Declaration QualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, TypeInfo.t_function ); + data.qualified = true; + //if parameters == null, thats no parameters, but we need to distinguish that from + //no parameter information at all, so make an empty list. + data.parameters = ( parameters == null ) ? new LinkedList() : parameters; + + ParserSymbolTable.Lookup( data, this ); + + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + public Declaration QualifiedLookup( String name ) throws ParserSymbolTableException{ + LookupData data = new LookupData( name, -1 ); + data.qualified = true; + ParserSymbolTable.Lookup( data, this ); + + return ParserSymbolTable.ResolveAmbiguities( data ); + } + + /** + * UnqualifiedFunctionLookup + * @param name + * @param parameters + * @return Declaration + * @throws ParserSymbolTableException + * + * 3.4.2-1 When an unqualified name is used as the post-fix expression in a + * function call, other namespaces not consdiered during the usual + * unqualified lookup may be searched. + * + * 3.4.2-2 For each argument type T in the function call, there is a set of + * zero or more associated namespaces and a set of zero or more associated + * classes to be considered. + * + * If the ordinary unqualified lookup of the name find the declaration of a + * class member function, the associated namespaces and classes are not + * considered. Otherwise, the set of declarations found by the lookup of + * the function name is the union of the set of declarations found using + * ordinary unqualified lookup and the set of declarations found in the + * namespaces and classes associated with the argument types. + */ + public Declaration UnqualifiedFunctionLookup( String name, LinkedList parameters ) throws ParserSymbolTableException{ + //figure out the set of associated scopes first, so we can remove those that are searched + //during the normal lookup to avoid doing them twice + HashSet associated = new HashSet(); + + //collect associated namespaces & classes. + int size = ( parameters == null ) ? 0 : parameters.size(); + Iterator iter = ( parameters == null ) ? null : parameters.iterator(); + + TypeInfo param = null; + Declaration paramType = null; + for( int i = size; i > 0; i-- ){ + param = (TypeInfo) iter.next(); + paramType = ParserSymbolTable.getFlatTypeInfo( param ).getTypeDeclaration(); + + ParserSymbolTable.getAssociatedScopes( paramType, associated ); + + //if T is a pointer to a data member of class X, its associated namespaces and classes + //are those associated with the member type together with those associated with X + if( param.getPtrOperator() != null && + (param.getPtrOperator().equals("*") || param.getPtrOperator().equals("[]")) && + paramType.getContainingScope().isType( TypeInfo.t_class, TypeInfo.t_union ) ) + { + ParserSymbolTable.getAssociatedScopes( paramType.getContainingScope(), associated ); + } + } + + LookupData data = new LookupData( name, TypeInfo.t_function ); + //if parameters == null, thats no parameters, but we need to distinguish that from + //no parameter information at all, so make an empty list. + data.parameters = ( parameters == null ) ? new LinkedList() : parameters; + data.associated = associated; + + ParserSymbolTable.Lookup( data, this ); + + Declaration found = ResolveAmbiguities( data ); + + //if we haven't found anything, or what we found is not a class member, consider the + //associated scopes + if( found == null || found.getContainingScope().getType() != TypeInfo.t_class ){ + if( found != null ){ + data.foundItems.add( found ); + } + + Declaration decl; + Declaration temp; + + //dump the hash to an array and iterate over the array because we + //could be removing items from the collection as we go and we don't + //want to get ConcurrentModificationExceptions + Object [] scopes = associated.toArray(); + + size = associated.size(); + + for( int i = 0; i < size; i++ ){ + decl = (Declaration) scopes[ i ]; + if( associated.contains( decl ) ){ + data.qualified = true; + data.ignoreUsingDirectives = true; + ParserSymbolTable.Lookup( data, decl ); + } + } + + found = ParserSymbolTable.ResolveAmbiguities( data ); + } + + return found; + } + + 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 TypeInfo _typeInfo; //our type info + private Declaration _containingScope; //the scope that contains us + private LinkedList _parentScopes; //inherited scopes (is base classes) + private LinkedList _usingDirectives; //collection of nominated namespaces + private HashMap _containedDeclarations; //declarations contained by us. + + private LinkedList _parameters; //parameter list + private int _returnType; + + private 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; + } + } + + static 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; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeInfo.java deleted file mode 100644 index 63dca932e32..00000000000 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/TypeInfo.java +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/ChangeLog b/core/org.eclipse.cdt.ui.tests/ChangeLog index 0fe1a3c609a..bcdfcef9b53 100644 --- a/core/org.eclipse.cdt.ui.tests/ChangeLog +++ b/core/org.eclipse.cdt.ui.tests/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java index 4c49937d5c9..3fa9fb37dba 100644 --- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java +++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ParserSymbolTableTest.java @@ -17,10 +17,8 @@ import java.util.Map; import junit.framework.TestCase; -import org.eclipse.cdt.internal.core.parser.Declaration; import org.eclipse.cdt.internal.core.parser.ParserSymbolTable; import org.eclipse.cdt.internal.core.parser.ParserSymbolTableException; -import org.eclipse.cdt.internal.core.parser.TypeInfo; /** * @author aniefer @@ -53,21 +51,18 @@ public class ParserSymbolTableTest extends TestCase { public void testSimpleAdd() throws Exception{ newTable(); //create the symbol table - Declaration decl = new Declaration( "x" ); - - table.addDeclaration( decl ); - - Declaration compUnit = table.getCompilationUnit(); - assertEquals( compUnit, table.peek() ); - + ParserSymbolTable.Declaration x = table.new Declaration( "x" ); + ParserSymbolTable.Declaration compUnit = (ParserSymbolTable.Declaration) table.getCompilationUnit(); + compUnit.addDeclaration( x ); + Map declarations = compUnit.getContainedDeclarations(); assertEquals( 1, declarations.size() ); Iterator iter = declarations.values().iterator(); - Declaration contained = (Declaration) iter.next(); + ParserSymbolTable.Declaration contained = (ParserSymbolTable.Declaration) iter.next(); assertEquals( false, iter.hasNext() ); - assertEquals( decl, contained ); + assertEquals( x, contained ); assertEquals( contained.getName(), "x" ); } @@ -79,19 +74,18 @@ public class ParserSymbolTableTest extends TestCase { public void testSimpleLookup() throws Exception{ newTable(); //new symbol table - Declaration decl = new Declaration( "x" ); + ParserSymbolTable.Declaration x = table.new Declaration( "x" ); + table.getCompilationUnit().addDeclaration( x ); - table.addDeclaration( decl ); + ParserSymbolTable.Declaration look = table.getCompilationUnit().Lookup( "x" ); - Declaration look = table.Lookup( "x" ); - - assertEquals( decl, look ); + assertEquals( x, look ); } public void testLookupNonExistant() throws Exception{ newTable(); - Declaration look = table.Lookup( "boo" ); + ParserSymbolTable.Declaration look = table.getCompilationUnit().Lookup("boo"); assertEquals( look, null ); } @@ -99,7 +93,7 @@ public class ParserSymbolTableTest extends TestCase { * testSimplePushPop * test pushing and popping * @throws Exception - */ + *//* public void testSimplePushPop() throws Exception{ newTable(); @@ -113,19 +107,19 @@ public class ParserSymbolTableTest extends TestCase { Declaration popped = table.pop(); assertEquals( pushing, popped ); assertEquals( table.peek(), table.getCompilationUnit() ); - } + }*/ public void testSimpleSetGetObject() throws Exception{ newTable(); - Declaration decl = new Declaration( "x" ); + ParserSymbolTable.Declaration x = table.new Declaration("x"); + Object obj = new Object(); + x.setObject( obj ); + + table.getCompilationUnit().addDeclaration( x ); - decl.setObject( obj ); - - table.addDeclaration( decl ); - - Declaration look = table.Lookup( "x" ); + ParserSymbolTable.Declaration look = table.getCompilationUnit().Lookup( "x" ); assertEquals( look.getObject(), obj ); } @@ -139,25 +133,23 @@ public class ParserSymbolTableTest extends TestCase { public void testHide() throws Exception{ newTable(); - Declaration firstX = new Declaration( "x" ); - table.addDeclaration( firstX ); + ParserSymbolTable.Declaration firstX = table.new Declaration("x"); + table.getCompilationUnit().addDeclaration( firstX ); - Declaration firstClass = new Declaration( "class" ); - table.addDeclaration( firstClass ); - table.push( firstClass ); - - Declaration look = table.Lookup( "x" ); + ParserSymbolTable.Declaration firstClass = table.new Declaration("class"); + firstClass.setType( ParserSymbolTable.TypeInfo.t_class ); + table.getCompilationUnit().addDeclaration( firstClass ); + + ParserSymbolTable.Declaration look = firstClass.Lookup( "x" ); assertEquals( look, firstX ); - Declaration secondX = new Declaration( "x" ); - table.addDeclaration( secondX ); + ParserSymbolTable.Declaration secondX = table.new Declaration("x"); + firstClass.addDeclaration( secondX ); - look = table.Lookup( "x" ); + look = firstClass.Lookup( "x" ); assertEquals( look, secondX ); - table.pop(); - - look = table.Lookup( "x" ); + look = table.getCompilationUnit().Lookup( "x" ); assertEquals( look, firstX ); } @@ -169,14 +161,14 @@ public class ParserSymbolTableTest extends TestCase { public void testContainingScopeLookup() throws Exception{ newTable(); - Declaration x = new Declaration("x"); - Declaration cls = new Declaration("class"); + ParserSymbolTable.Declaration x = table.new Declaration("x"); + table.getCompilationUnit().addDeclaration( x ); + + ParserSymbolTable.Declaration decl = table.new Declaration("class"); + decl.setType( ParserSymbolTable.TypeInfo.t_class ); + table.getCompilationUnit().addDeclaration( decl ); - table.addDeclaration( x ); - table.addDeclaration( cls ); - table.push( cls ); - - Declaration look = table.Lookup( "x" ); + ParserSymbolTable.Declaration look = decl.Lookup( "x" ); assertEquals( x, look ); } @@ -190,24 +182,21 @@ public class ParserSymbolTableTest extends TestCase { public void testParentLookup() throws Exception{ newTable(); - Declaration class1 = new Declaration( "class" ); - Declaration parent = new Declaration( "parent" ); - Declaration decl = new Declaration( "x" ); - - table.addDeclaration( parent ); - table.push( parent ); - table.addDeclaration( decl ); - table.pop(); - + ParserSymbolTable.Declaration parent = table.new Declaration("parent"); + parent.setType( ParserSymbolTable.TypeInfo.t_class ); + + ParserSymbolTable.Declaration class1 = table.new Declaration("class"); + class1.setType( ParserSymbolTable.TypeInfo.t_class ); class1.addParent( parent ); - table.addDeclaration( class1 ); - table.push( class1 ); - Declaration look = table.Lookup( "x" ); + ParserSymbolTable.Declaration decl = table.new Declaration("x"); + parent.addDeclaration( decl ); + + table.getCompilationUnit().addDeclaration( parent ); + table.getCompilationUnit().addDeclaration( class1 ); + + ParserSymbolTable.Declaration look = class1.Lookup( "x" ); assertEquals( look, decl ); - - table.pop(); - assertEquals( table.peek(), table.getCompilationUnit() ); } /** @@ -221,28 +210,23 @@ public class ParserSymbolTableTest extends TestCase { */ public void testAmbiguousParentLookup() throws Exception{ testParentLookup(); + + ParserSymbolTable.Declaration parent2 = table.new Declaration("parent2"); + table.getCompilationUnit().addDeclaration( parent2 ); - Declaration parent2 = new Declaration( "parent2" ); - - table.addDeclaration( parent2 ); - - Declaration class1 = table.Lookup( "class" ); + ParserSymbolTable.Declaration class1 = table.getCompilationUnit().Lookup( "class" ); class1.addParent( parent2 ); - Declaration decl = new Declaration("x"); - table.push( parent2 ); - table.addDeclaration( decl ); - table.pop(); - - table.push( class1 ); + ParserSymbolTable.Declaration decl = table.new Declaration("x"); + parent2.addDeclaration( decl ); + try{ - table.Lookup( "x" ); + class1.Lookup( "x" ); assertTrue( false ); } catch ( ParserSymbolTableException e ){ - assertTrue( true ); + assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } - } /** @@ -253,19 +237,17 @@ public class ParserSymbolTableTest extends TestCase { public void testCircularParentLookup() throws Exception{ newTable(); - Declaration a = new Declaration("a"); - table.addDeclaration( a ); + ParserSymbolTable.Declaration a = table.new Declaration("a"); + table.getCompilationUnit().addDeclaration( a ); - Declaration b = new Declaration("b"); - table.addDeclaration(b); - - a.addParent( b ); + ParserSymbolTable.Declaration b = table.new Declaration("b"); b.addParent( a ); - - table.push( a ); + table.getCompilationUnit().addDeclaration( b ); + + a.addParent( b ); try{ - Declaration look = table.Lookup("foo"); + ParserSymbolTable.Declaration look = a.Lookup("foo"); assertTrue( false ); } catch ( ParserSymbolTableException e) { assertEquals( e.reason, ParserSymbolTableException.r_CircularInheritance ); @@ -287,37 +269,31 @@ public class ParserSymbolTableTest extends TestCase { public void testVirtualParentLookup() throws Exception{ newTable(); - Declaration decl = new Declaration("class"); - Declaration c = new Declaration("C"); + ParserSymbolTable.Declaration decl = table.new Declaration("class"); + ParserSymbolTable.Declaration c = table.new Declaration("C"); - Declaration a = new Declaration("A"); + ParserSymbolTable.Declaration a = table.new Declaration("A"); a.addParent( c, true ); - Declaration b = new Declaration("B"); + ParserSymbolTable.Declaration b = table.new Declaration("B"); b.addParent( c, true ); decl.addParent( a ); decl.addParent( b ); - table.addDeclaration( c ); - table.push( c ); - Declaration x = new Declaration( "x" ); - table.addDeclaration( x ); - table.pop(); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + compUnit.addDeclaration( c ); - table.addDeclaration( decl ); - table.addDeclaration( a ); - table.addDeclaration( b ); + ParserSymbolTable.Declaration x = table.new Declaration( "x" ); + c.addDeclaration( x ); - table.push(decl); + compUnit.addDeclaration( decl ); + compUnit.addDeclaration( a ); + compUnit.addDeclaration( b ); - Declaration look = table.Lookup( "x" ); + ParserSymbolTable.Declaration look = decl.Lookup( "x" ); assertEquals( look, x ); - - table.pop(); - - assertEquals( table.peek(), table.getCompilationUnit() ); } /** @@ -334,18 +310,17 @@ public class ParserSymbolTableTest extends TestCase { public void testAmbiguousVirtualParentLookup() throws Exception{ testVirtualParentLookup(); - Declaration cls = table.Lookup("class"); - Declaration c = table.Lookup("C"); - Declaration d = new Declaration("D"); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + + ParserSymbolTable.Declaration cls = compUnit.Lookup("class"); + ParserSymbolTable.Declaration c = compUnit.Lookup("C"); + ParserSymbolTable.Declaration d = table.new Declaration("D"); d.addParent( c ); - cls.addParent( d ); - table.push( cls ); - try{ - table.Lookup( "x" ); + cls.Lookup( "x" ); assertTrue( false ); } catch( ParserSymbolTableException e){ @@ -369,44 +344,42 @@ public class ParserSymbolTableTest extends TestCase { public void testStaticEnumParentLookup() throws Exception{ newTable(); - Declaration a = new Declaration( "a" ); - Declaration b = new Declaration( "b" ); - Declaration c = new Declaration( "c" ); - Declaration d = new Declaration( "d" ); + ParserSymbolTable.Declaration a = table.new Declaration( "a" ); + ParserSymbolTable.Declaration b = table.new Declaration( "b" ); + ParserSymbolTable.Declaration c = table.new Declaration( "c" ); + ParserSymbolTable.Declaration d = table.new Declaration( "d" ); - table.addDeclaration( a ); - table.addDeclaration( b ); - table.addDeclaration( c ); - table.addDeclaration( d ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration enum = new Declaration("enum"); - enum.setType( TypeInfo.t_enumeration ); + compUnit.addDeclaration( a ); + compUnit.addDeclaration( b ); + compUnit.addDeclaration( c ); + compUnit.addDeclaration( d ); - Declaration enumerator = new Declaration( "enumerator" ); - enumerator.setType( TypeInfo.t_enumerator ); + ParserSymbolTable.Declaration enum = table.new Declaration("enum"); + enum.setType( ParserSymbolTable.TypeInfo.t_enumeration ); - Declaration stat = new Declaration("static"); - stat.getTypeInfo().setBit( true, TypeInfo.isStatic ); + ParserSymbolTable.Declaration enumerator = table.new Declaration( "enumerator" ); + enumerator.setType( ParserSymbolTable.TypeInfo.t_enumerator ); - Declaration x = new Declaration("x"); + ParserSymbolTable.Declaration stat = table.new Declaration("static"); + stat.getTypeInfo().setBit( true, ParserSymbolTable.TypeInfo.isStatic ); - table.push(d); - table.addDeclaration( enum ); - table.push( enum ); - table.addDeclaration( enumerator ); - table.pop(); - table.addDeclaration( stat ); - table.addDeclaration( x ); - table.pop(); + ParserSymbolTable.Declaration x = table.new Declaration("x"); + + d.addDeclaration( enum ); + d.addDeclaration( stat ); + d.addDeclaration( x ); + + enum.addDeclaration( enumerator ); a.addParent( b ); a.addParent( c ); b.addParent( d ); c.addParent( d ); - table.push( a ); try{ - table.Lookup( "enumerator" ); + a.Lookup( "enumerator" ); assertTrue( true ); } catch ( ParserSymbolTableException e){ @@ -414,7 +387,7 @@ public class ParserSymbolTableTest extends TestCase { } try{ - table.Lookup( "static" ); + a.Lookup( "static" ); assertTrue( true ); } catch ( ParserSymbolTableException e){ @@ -422,7 +395,7 @@ public class ParserSymbolTableTest extends TestCase { } try{ - table.Lookup( "x" ); + a.Lookup( "x" ); assertTrue( false ); } catch ( ParserSymbolTableException e){ @@ -438,76 +411,74 @@ public class ParserSymbolTableTest extends TestCase { public void testElaboratedLookup() throws Exception{ newTable(); - Declaration cls = new Declaration( "class" ); - cls.setType( TypeInfo.t_class ); + ParserSymbolTable.Declaration cls = table.new Declaration( "class" ); + cls.setType( ParserSymbolTable.TypeInfo.t_class ); - Declaration struct = new Declaration("struct"); - struct.setType( TypeInfo.t_struct ); + ParserSymbolTable.Declaration struct = table.new Declaration("struct"); + struct.setType( ParserSymbolTable.TypeInfo.t_struct ); - Declaration union = new Declaration("union"); - union.setType( TypeInfo.t_union ); + ParserSymbolTable.Declaration union = table.new Declaration("union"); + union.setType( ParserSymbolTable.TypeInfo.t_union ); - Declaration hideCls = new Declaration( "class" ); - Declaration hideStruct = new Declaration("struct"); - Declaration hideUnion = new Declaration("union"); + ParserSymbolTable.Declaration hideCls = table.new Declaration( "class" ); + ParserSymbolTable.Declaration hideStruct = table.new Declaration("struct"); + ParserSymbolTable.Declaration hideUnion = table.new Declaration("union"); - Declaration a = new Declaration("a"); - Declaration b = new Declaration("b"); + ParserSymbolTable.Declaration a = table.new Declaration("a"); + ParserSymbolTable.Declaration b = table.new Declaration("b"); - table.push(a); - table.addDeclaration(hideCls); - table.addDeclaration(hideStruct); - table.addDeclaration(hideUnion); + a.addDeclaration(hideCls); + a.addDeclaration(hideStruct); + a.addDeclaration(hideUnion); a.addParent( b ); - table.push(b); - table.addDeclaration(cls); - table.addDeclaration(struct); - table.addDeclaration(union); - table.pop(); + b.addDeclaration(cls); + b.addDeclaration(struct); + b.addDeclaration(union); - Declaration look = table.ElaboratedLookup( TypeInfo.t_class, "class" ); + ParserSymbolTable.Declaration look = a.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_class, "class" ); assertEquals( look, cls ); - look = table.ElaboratedLookup( TypeInfo.t_struct, "struct" ); + look = a.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_struct, "struct" ); assertEquals( look, struct ); - look = table.ElaboratedLookup( TypeInfo.t_union, "union" ); + look = a.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_union, "union" ); assertEquals( look, union ); } /** * testDeclarationType * @throws Exception - * test the use of Declaration type in the scenario + * test the use of ParserSymbolTable.Declaration type in the scenario * A a; * a.member <=...>; * where A was previously declared */ public void testDeclarationType() throws Exception{ newTable(); + + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + //pre-condition - Declaration A = new Declaration("A"); - table.addDeclaration(A); + ParserSymbolTable.Declaration A = table.new Declaration("A"); + compUnit.addDeclaration(A); - Declaration member = new Declaration("member"); - table.push(A); - table.addDeclaration(member); - table.pop(); + ParserSymbolTable.Declaration member = table.new Declaration("member"); + A.addDeclaration(member); //at time of "A a;" - Declaration look = table.Lookup("A"); + ParserSymbolTable.Declaration look = compUnit.Lookup("A"); assertEquals( look, A ); - Declaration a = new Declaration("a"); + ParserSymbolTable.Declaration a = table.new Declaration("a"); a.setTypeDeclaration( look ); - table.addDeclaration( a ); + compUnit.addDeclaration( a ); //later "a.member" - look = table.Lookup("a"); + look = compUnit.Lookup("a"); assertEquals( look, a ); - Declaration type = look.getTypeDeclaration(); + ParserSymbolTable.Declaration type = look.getTypeDeclaration(); assertEquals( type, A ); - table.push(type); - look = table.Lookup("member"); + + look = type.Lookup("member"); assertEquals( look, member ); } @@ -528,23 +499,24 @@ public class ParserSymbolTableTest extends TestCase { public void testFunctionHidesClass() throws Exception{ newTable(); - Declaration struct = new Declaration( "stat"); - struct.setType( TypeInfo.t_struct ); - table.addDeclaration( struct ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration function = new Declaration( "stat" ); - function.setType( TypeInfo.t_function ); - table.addDeclaration( function ); + ParserSymbolTable.Declaration struct = table.new Declaration( "stat"); + struct.setType( ParserSymbolTable.TypeInfo.t_struct ); + compUnit.addDeclaration( struct ); - Declaration f = new Declaration("f"); - f.setType( TypeInfo.t_function ); - table.addDeclaration( f ); - table.push( f ); + ParserSymbolTable.Declaration function = table.new Declaration( "stat" ); + function.setType( ParserSymbolTable.TypeInfo.t_function ); + compUnit.addDeclaration( function ); - Declaration look = table.ElaboratedLookup( TypeInfo.t_struct, "stat" ); + ParserSymbolTable.Declaration f = table.new Declaration("f"); + f.setType( ParserSymbolTable.TypeInfo.t_function ); + compUnit.addDeclaration( f ); + + ParserSymbolTable.Declaration look = f.ElaboratedLookup( ParserSymbolTable.TypeInfo.t_struct, "stat" ); assertEquals( look, struct ); - look = table.Lookup( "stat" ); + look = f.Lookup( "stat" ); assertEquals( look, function ); } @@ -582,64 +554,54 @@ public class ParserSymbolTableTest extends TestCase { public void testUsingDirectives_1() throws Exception{ newTable(); - Declaration nsA = new Declaration("A"); - nsA.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsA ); - table.push( nsA ); + ParserSymbolTable.Declaration nsA = table.new Declaration("A"); + nsA.setType( ParserSymbolTable.TypeInfo.t_namespace ); + table.getCompilationUnit().addDeclaration( nsA ); - Declaration nsA_i = new Declaration("i"); - table.addDeclaration( nsA_i ); + ParserSymbolTable.Declaration nsA_i = table.new Declaration("i"); + nsA.addDeclaration( nsA_i ); - Declaration nsB = new Declaration("B"); - nsB.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsB ); - table.push( nsB ); + ParserSymbolTable.Declaration nsB = table.new Declaration("B"); + nsB.setType( ParserSymbolTable.TypeInfo.t_namespace ); + nsA.addDeclaration( nsB ); - Declaration nsC = new Declaration("C"); - nsC.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsC ); - table.push( nsC ); + ParserSymbolTable.Declaration nsC = table.new Declaration("C"); + nsC.setType( ParserSymbolTable.TypeInfo.t_namespace ); + nsB.addDeclaration( nsC ); - Declaration nsC_i = new Declaration("i"); - table.addDeclaration( nsC_i ); - table.pop(); + ParserSymbolTable.Declaration nsC_i = table.new Declaration("i"); + nsC.addDeclaration( nsC_i ); - Declaration look = table.Lookup("C"); - table.addUsingDirective( look ); + ParserSymbolTable.Declaration look = nsB.Lookup("C"); + nsB.addUsingDirective( look ); - Declaration f1 = new Declaration("f"); - f1.setType( TypeInfo.t_function ); - table.push( f1 ); + ParserSymbolTable.Declaration f1 = table.new Declaration("f"); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); - look = table.Lookup( "i" ); + nsB.addDeclaration( f1 ); + + look = f1.Lookup( "i" ); assertEquals( look, nsC_i ); //C::i visible and hides A::i - table.pop(); //end of f1 - table.pop(); //end of nsB + ParserSymbolTable.Declaration nsD = table.new Declaration("D"); + nsD.setType( ParserSymbolTable.TypeInfo.t_namespace ); + nsA.addDeclaration( nsD ); - assertEquals( table.peek(), nsA ); - - Declaration nsD = new Declaration("D"); - nsD.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsD ); - table.push( nsD ); - - look = table.Lookup("B"); + look = nsD.Lookup("B"); assertEquals( look, nsB ); - table.addUsingDirective( look ); + nsD.addUsingDirective( look ); - look = table.Lookup("C"); + look = nsD.Lookup("C"); assertEquals( look, nsC ); - table.addUsingDirective( look ); + nsD.addUsingDirective( look ); - Declaration f2 = new Declaration( "f2" ); - f2.setType( TypeInfo.t_function ); - table.addDeclaration( f2 ); - table.push( f2 ); + ParserSymbolTable.Declaration f2 = table.new Declaration( "f2" ); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); + nsD.addDeclaration( f2 ); try { - look = table.Lookup( "i" ); + look = f2.Lookup( "i" ); assertTrue( false ); } catch ( ParserSymbolTableException e ) @@ -647,26 +609,19 @@ public class ParserSymbolTableTest extends TestCase { //ambiguous B::C::i and A::i assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } - table.pop(); //end f2 - table.pop(); //end nsD - Declaration f3 = new Declaration ("f3"); - f3.setType( TypeInfo.t_function ); - table.addDeclaration( f3 ); - table.push( f3 ); + ParserSymbolTable.Declaration f3 = table.new Declaration ("f3"); + f3.setType( ParserSymbolTable.TypeInfo.t_function ); + nsA.addDeclaration( f3 ); - look = table.Lookup("i"); + look = f3.Lookup("i"); assertEquals( look, nsA_i ); //uses A::i - table.pop(); - table.pop(); + ParserSymbolTable.Declaration f4 = table.new Declaration ("f4"); + f4.setType( ParserSymbolTable.TypeInfo.t_function ); + table.getCompilationUnit().addDeclaration( f4 ); - Declaration f4 = new Declaration ("f4"); - f4.setType( TypeInfo.t_function ); - table.addDeclaration( f4 ); - table.push( f4 ); - - look = table.Lookup("i"); + look = f4.Lookup("i"); assertEquals( look, null );//neither i is visible here. } /** @@ -693,37 +648,34 @@ public class ParserSymbolTableTest extends TestCase { { newTable(); - Declaration nsM = new Declaration( "M" ); - nsM.setType( TypeInfo.t_namespace ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - table.addDeclaration( nsM ); + ParserSymbolTable.Declaration nsM = table.new Declaration( "M" ); + nsM.setType( ParserSymbolTable.TypeInfo.t_namespace ); - table.push( nsM ); - Declaration nsM_i = new Declaration("i"); - table.addDeclaration( nsM_i ); - table.pop(); + compUnit.addDeclaration( nsM ); - Declaration nsN = new Declaration( "N" ); - nsN.setType( TypeInfo.t_namespace ); + ParserSymbolTable.Declaration nsM_i = table.new Declaration("i"); + nsM.addDeclaration( nsM_i ); + + ParserSymbolTable.Declaration nsN = table.new Declaration( "N" ); + nsN.setType( ParserSymbolTable.TypeInfo.t_namespace ); - table.addDeclaration( nsN ); + compUnit.addDeclaration( nsN ); - table.push( nsN ); - Declaration nsN_i = new Declaration("i"); - table.addDeclaration( nsN_i ); - table.addUsingDirective( nsM ); - table.pop(); + ParserSymbolTable.Declaration nsN_i = table.new Declaration("i"); + nsN.addDeclaration( nsN_i ); + nsN.addUsingDirective( nsM ); - Declaration f = new Declaration("f"); - table.addDeclaration( f ); - table.push( f ); + ParserSymbolTable.Declaration f = table.new Declaration("f"); + compUnit.addDeclaration( f ); - table.addUsingDirective( nsN ); + f.addUsingDirective( nsN ); - Declaration look = null; + ParserSymbolTable.Declaration look = null; try { - look = table.Lookup( "i" ); + look = f.Lookup( "i" ); assertTrue( false ); } catch ( ParserSymbolTableException e ) @@ -732,9 +684,8 @@ public class ParserSymbolTableTest extends TestCase { assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } - look = table.LookupNestedNameSpecifier("N"); - table.push( look ); - look = table.QualifiedLookup("i"); //ok + look = f.LookupNestedNameSpecifier("N"); + look = look.QualifiedLookup("i"); //ok assertEquals( look, nsN_i ); } @@ -765,46 +716,38 @@ public class ParserSymbolTableTest extends TestCase { { newTable(); - Declaration nsA = new Declaration("A"); - nsA.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsA ); - table.push( nsA ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration a = new Declaration("a"); - table.addDeclaration( a ); - table.pop(); + ParserSymbolTable.Declaration nsA = table.new Declaration("A"); + nsA.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsA ); - Declaration nsB = new Declaration("B"); - nsB.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsB ); - table.push( nsB ); - table.addUsingDirective( nsA ); - table.pop(); - - Declaration nsC = new Declaration("C"); - nsC.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsC ); - table.push( nsC ); - table.addUsingDirective( nsA ); - table.pop(); + ParserSymbolTable.Declaration a = table.new Declaration("a"); + nsA.addDeclaration( a ); + + ParserSymbolTable.Declaration nsB = table.new Declaration("B"); + nsB.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsB ); + nsB.addUsingDirective( nsA ); - Declaration nsBC = new Declaration("BC"); - nsBC.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsBC ); - table.push( nsBC ); - table.addUsingDirective( nsB ); - table.addUsingDirective( nsC ); - table.pop(); + ParserSymbolTable.Declaration nsC = table.new Declaration("C"); + nsC.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsC ); + nsC.addUsingDirective( nsA ); - Declaration f = new Declaration("f"); - f.setType(TypeInfo.t_function); - table.addDeclaration( f ); - table.push(f); + ParserSymbolTable.Declaration nsBC = table.new Declaration("BC"); + nsBC.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsBC ); + nsBC.addUsingDirective( nsB ); + nsBC.addUsingDirective( nsC ); - Declaration look = table.LookupNestedNameSpecifier("BC"); + ParserSymbolTable.Declaration f = table.new Declaration("f"); + f.setType(ParserSymbolTable.TypeInfo.t_function); + compUnit.addDeclaration( f ); + + ParserSymbolTable.Declaration look = f.LookupNestedNameSpecifier("BC"); assertEquals( look, nsBC ); - table.push(look); - look = table.QualifiedLookup("a"); + look = look.QualifiedLookup("a"); assertEquals( look, a ); } @@ -834,53 +777,42 @@ public class ParserSymbolTableTest extends TestCase { { newTable(); - Declaration nsB = new Declaration( "B" ); - nsB.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsB ); - table.push( nsB ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration b = new Declaration("b"); - table.addDeclaration( b ); - table.pop(); + ParserSymbolTable.Declaration nsB = table.new Declaration( "B" ); + nsB.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsB ); - Declaration nsA = new Declaration( "A" ); - nsA.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsA ); - table.push( nsA ); + ParserSymbolTable.Declaration b = table.new Declaration("b"); + nsB.addDeclaration( b ); - table.addUsingDirective( nsB ); + ParserSymbolTable.Declaration nsA = table.new Declaration( "A" ); + nsA.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsA ); - Declaration a = new Declaration("a"); - table.addDeclaration( a ); + nsA.addUsingDirective( nsB ); - table.pop(); + ParserSymbolTable.Declaration a = table.new Declaration("a"); + nsA.addDeclaration( a ); - table.push( nsB ); - table.addUsingDirective( nsA ); - table.pop(); + nsB.addUsingDirective( nsA ); - Declaration f = new Declaration("f"); - table.addDeclaration(f); - table.push(f); + ParserSymbolTable.Declaration f = table.new Declaration("f"); + compUnit.addDeclaration(f); - Declaration look = table.LookupNestedNameSpecifier("A"); - table.push(look); - look = table.QualifiedLookup("a"); + ParserSymbolTable.Declaration lookA = f.LookupNestedNameSpecifier("A"); + ParserSymbolTable.Declaration look = lookA.QualifiedLookup("a"); assertEquals( look, a ); - look = table.QualifiedLookup("b"); + look = lookA.QualifiedLookup("b"); assertEquals( look, b ); - table.pop(); - look = table.LookupNestedNameSpecifier("B"); - table.push(look); - look = table.QualifiedLookup("a"); + ParserSymbolTable.Declaration lookB = f.LookupNestedNameSpecifier("B"); + look = lookB.QualifiedLookup("a"); assertEquals( look, a ); - look = table.QualifiedLookup("b"); + look = lookB.QualifiedLookup("b"); assertEquals( look, b ); - table.pop(); - } /** @@ -908,30 +840,26 @@ public class ParserSymbolTableTest extends TestCase { { newTable(); - Declaration nsA = new Declaration( "A" ); - nsA.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsA ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + + ParserSymbolTable.Declaration nsA = table.new Declaration( "A" ); + nsA.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsA ); - Declaration nsB = new Declaration( "B" ); - nsB.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsB ); - table.push( nsB ); - table.addUsingDirective( nsA ); - table.pop(); + ParserSymbolTable.Declaration nsB = table.new Declaration( "B" ); + nsB.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsB ); + nsB.addUsingDirective( nsA ); - table.push( nsA ); - table.addUsingDirective( nsB ); - table.pop(); - - Declaration f = new Declaration("f"); - table.addDeclaration(f); - table.push(f); - table.addUsingDirective(nsA); - table.addUsingDirective(nsB); + nsA.addUsingDirective( nsB ); - Declaration look = table.Lookup("i"); + ParserSymbolTable.Declaration f = table.new Declaration("f"); + compUnit.addDeclaration(f); + f.addUsingDirective(nsA); + f.addUsingDirective(nsB); + + ParserSymbolTable.Declaration look = f.Lookup("i"); assertEquals( look, null ); - } /** @@ -961,66 +889,57 @@ public class ParserSymbolTableTest extends TestCase { public void testNamespaceMemberHiding() throws Exception{ newTable(); - Declaration nsA = new Declaration("A"); - nsA.setType( TypeInfo.t_namespace ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - table.addDeclaration( nsA ); - table.push( nsA ); + ParserSymbolTable.Declaration nsA = table.new Declaration("A"); + nsA.setType( ParserSymbolTable.TypeInfo.t_namespace ); - Declaration structX = new Declaration("x"); - structX.setType( TypeInfo.t_struct ); - table.addDeclaration( structX ); + compUnit.addDeclaration( nsA ); - Declaration intX = new Declaration("x"); - intX.setType( TypeInfo.t_int ); - table.addDeclaration( intX ); + ParserSymbolTable.Declaration structX = table.new Declaration("x"); + structX.setType( ParserSymbolTable.TypeInfo.t_struct ); + nsA.addDeclaration( structX ); - Declaration intY = new Declaration("y"); - intY.setType( TypeInfo.t_int ); - table.addDeclaration( intY ); + ParserSymbolTable.Declaration intX = table.new Declaration("x"); + intX.setType( ParserSymbolTable.TypeInfo.t_int ); + nsA.addDeclaration( intX ); + + ParserSymbolTable.Declaration intY = table.new Declaration("y"); + intY.setType( ParserSymbolTable.TypeInfo.t_int ); + nsA.addDeclaration( intY ); - table.pop(); + ParserSymbolTable.Declaration nsB = table.new Declaration("B"); + nsB.setType( ParserSymbolTable.TypeInfo.t_namespace ); - Declaration nsB = new Declaration("B"); - nsB.setType( TypeInfo.t_namespace ); + compUnit.addDeclaration( nsB ); + ParserSymbolTable.Declaration structY = table.new Declaration("y"); + structY.setType( ParserSymbolTable.TypeInfo.t_struct ); + nsB.addDeclaration( structY ); - table.addDeclaration( nsB ); - table.push( nsB ); + ParserSymbolTable.Declaration nsC = table.new Declaration("C"); + nsC.setType( ParserSymbolTable.TypeInfo.t_namespace); + compUnit.addDeclaration( nsC ); - Declaration structY = new Declaration("y"); - structY.setType( TypeInfo.t_struct ); - table.addDeclaration( structY ); - - table.pop(); - - Declaration nsC = new Declaration("C"); - nsC.setType( TypeInfo.t_namespace); - table.addDeclaration( nsC ); - - table.push( nsC ); - - Declaration look = table.Lookup("A"); + ParserSymbolTable.Declaration look = nsC.Lookup("A"); assertEquals( look, nsA ); - table.addUsingDirective( look ); + nsC.addUsingDirective( look ); - look = table.Lookup("B"); + look = nsC.Lookup("B"); assertEquals( look, nsB ); - table.addUsingDirective( look ); + nsC.addUsingDirective( look ); //lookup C::x - look = table.LookupNestedNameSpecifier("C"); + look = nsC.LookupNestedNameSpecifier("C"); assertEquals( look, nsC ); - table.push(look); - look = table.QualifiedLookup( "x" ); + look = look.QualifiedLookup( "x" ); assertEquals( look, intX ); - table.pop(); //lookup C::y - look = table.LookupNestedNameSpecifier("C"); + look = nsC.LookupNestedNameSpecifier("C"); assertEquals( look, nsC ); - table.push(look); + try{ - look = table.QualifiedLookup( "y" ); + look = look.QualifiedLookup( "y" ); assertTrue(false); } catch ( ParserSymbolTableException e ) { assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); @@ -1044,34 +963,30 @@ public class ParserSymbolTableTest extends TestCase { public void testLookupMemberForDefinition() throws Exception{ newTable(); - Declaration nsA = new Declaration( "A" ); - nsA.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsA ); - table.push( nsA ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + + ParserSymbolTable.Declaration nsA = table.new Declaration( "A" ); + nsA.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( nsA ); - Declaration nsB = new Declaration( "B" ); - nsB.setType( TypeInfo.t_namespace ); - table.addDeclaration( nsB ); - table.push( nsB ); + ParserSymbolTable.Declaration nsB = table.new Declaration( "B" ); + nsB.setType( ParserSymbolTable.TypeInfo.t_namespace ); + nsA.addDeclaration( nsB ); - Declaration f1 = new Declaration("f1"); - f1.setType( TypeInfo.t_function ); - table.addDeclaration( f1 ); + ParserSymbolTable.Declaration f1 = table.new Declaration("f1"); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); + nsB.addDeclaration( f1 ); - table.pop(); + nsA.addUsingDirective( nsB ); - table.addUsingDirective( nsB ); - table.pop(); + ParserSymbolTable.Declaration lookA = compUnit.LookupNestedNameSpecifier( "A" ); + assertEquals( nsA, lookA ); - Declaration look = table.LookupNestedNameSpecifier( "A" ); - assertEquals( nsA, look ); - table.push( look ); - - look = table.LookupMemberForDefinition( "f1" ); + ParserSymbolTable.Declaration look = lookA.LookupMemberForDefinition( "f1" ); assertEquals( look, null ); //but notice if you wanted to do A::f1 as a function call, it is ok - look = table.QualifiedLookup( "f1" ); + look = lookA.QualifiedLookup( "f1" ); assertEquals( look, f1 ); } @@ -1102,63 +1017,58 @@ public class ParserSymbolTableTest extends TestCase { public void testUsingDeclaration() throws Exception{ newTable(); - Declaration B = new Declaration("B"); - B.setType( TypeInfo.t_struct ); - table.addDeclaration( B ); - table.push( B ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration f = new Declaration("f"); - f.setType( TypeInfo.t_function ); - table.addDeclaration( f ); + ParserSymbolTable.Declaration B = table.new Declaration("B"); + B.setType( ParserSymbolTable.TypeInfo.t_struct ); + compUnit.addDeclaration( B ); + + ParserSymbolTable.Declaration f = table.new Declaration("f"); + f.setType( ParserSymbolTable.TypeInfo.t_function ); + B.addDeclaration( f ); - Declaration E = new Declaration( "E" ); - E.setType( TypeInfo.t_enumeration ); - table.addDeclaration( E ); + ParserSymbolTable.Declaration E = table.new Declaration( "E" ); + E.setType( ParserSymbolTable.TypeInfo.t_enumeration ); + B.addDeclaration( E ); - table.push( E ); - Declaration e = new Declaration( "e" ); - e.setType( TypeInfo.t_enumerator ); - table.addDeclaration( e ); - table.pop(); + ParserSymbolTable.Declaration e = table.new Declaration( "e" ); + e.setType( ParserSymbolTable.TypeInfo.t_enumerator ); + E.addDeclaration( e ); - //TBD: Anonymous unions are not yet implemented + /** + * TBD: Anonymous unions are not yet implemented + */ - table.pop(); + ParserSymbolTable.Declaration C = table.new Declaration( "C" ); + C.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( C ); - Declaration C = new Declaration( "C" ); - C.setType( TypeInfo.t_class ); - table.addDeclaration( C ); + ParserSymbolTable.Declaration g = table.new Declaration( "g" ); + g.setType( ParserSymbolTable.TypeInfo.t_function ); + C.addDeclaration( g ); - table.push( C ); - Declaration g = new Declaration( "g" ); - g.setType( TypeInfo.t_function ); - table.addDeclaration( g ); - table.pop(); - - Declaration D = new Declaration( "D" ); - D.setType( TypeInfo.t_struct ); - Declaration look = table.Lookup( "B" ); + ParserSymbolTable.Declaration D = table.new Declaration( "D" ); + D.setType( ParserSymbolTable.TypeInfo.t_struct ); + ParserSymbolTable.Declaration look = compUnit.Lookup( "B" ); assertEquals( look, B ); D.addParent( look ); - table.addDeclaration( D ); - table.push( D ); + compUnit.addDeclaration( D ); - Declaration lookB = table.LookupNestedNameSpecifier("B"); + ParserSymbolTable.Declaration lookB = D.LookupNestedNameSpecifier("B"); assertEquals( lookB, B ); - table.addUsingDeclaration( "f", lookB ); - - table.addUsingDeclaration( "e", lookB ); + D.addUsingDeclaration( "f", lookB ); + D.addUsingDeclaration( "e", lookB ); //TBD anonymous union - //table.addUsingDeclaration( "x", lookB ); + //D.addUsingDeclaration( "x", lookB ); - look = table.LookupNestedNameSpecifier("C"); + look = D.LookupNestedNameSpecifier("C"); assertEquals( look, C ); try{ - table.addUsingDeclaration( "g", look ); + D.addUsingDeclaration( "g", look ); assertTrue( false ); } catch ( ParserSymbolTableException exception ){ @@ -1193,65 +1103,57 @@ public class ParserSymbolTableTest extends TestCase { public void testUsingDeclaration_2() throws Exception{ newTable(); - Declaration A = new Declaration( "A" ); - A.setType( TypeInfo.t_namespace ); - table.addDeclaration( A ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - table.push( A ); + ParserSymbolTable.Declaration A = table.new Declaration( "A" ); + A.setType( ParserSymbolTable.TypeInfo.t_namespace ); + compUnit.addDeclaration( A ); - Declaration f1 = new Declaration( "f" ); - f1.setType( TypeInfo.t_function ); - f1.setReturnType( TypeInfo.t_void ); - f1.addParameter( TypeInfo.t_int, 0, "", false ); - table.addDeclaration( f1 ); + ParserSymbolTable.Declaration f1 = table.new Declaration( "f" ); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); + f1.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, "", false ); + A.addDeclaration( f1 ); - table.pop(); - - Declaration look = table.LookupNestedNameSpecifier("A"); + ParserSymbolTable.Declaration look = compUnit.LookupNestedNameSpecifier("A"); assertEquals( look, A ); - Declaration usingF = table.addUsingDeclaration( "f", look ); + ParserSymbolTable.Declaration usingF = compUnit.addUsingDeclaration( "f", look ); - look = table.Lookup("A"); + look = compUnit.Lookup("A"); assertEquals( look, A ); - table.push( look ); - Declaration f2 = new Declaration("f"); - f2.setType( TypeInfo.t_function ); - f2.setReturnType( TypeInfo.t_void ); - f2.addParameter( TypeInfo.t_char, 0, "", false ); + ParserSymbolTable.Declaration f2 = table.new Declaration("f"); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); + f2.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, "", false ); - table.addDeclaration( f2 ); + look.addDeclaration( f2 ); - table.pop(); - - Declaration foo = new Declaration("foo"); - foo.setType( TypeInfo.t_function ); - table.addDeclaration( foo ); - table.push( foo ); + ParserSymbolTable.Declaration foo = table.new Declaration("foo"); + foo.setType( ParserSymbolTable.TypeInfo.t_function ); + compUnit.addDeclaration( foo ); + LinkedList paramList = new LinkedList(); - TypeInfo param = new TypeInfo( TypeInfo.t_char, null ); + ParserSymbolTable.TypeInfo param = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, null ); paramList.add( param ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = foo.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, usingF ); assertTrue( look.hasSameParameters( f1 ) ); - Declaration bar = new Declaration( "bar" ); - bar.setType( TypeInfo.t_function ); - bar.addParameter( TypeInfo.t_char, 0, null, false ); - table.addDeclaration( bar ); - table.push( bar ); + ParserSymbolTable.Declaration bar = table.new Declaration( "bar" ); + bar.setType( ParserSymbolTable.TypeInfo.t_function ); + bar.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, null, false ); + compUnit.addDeclaration( bar ); - look = table.LookupNestedNameSpecifier( "A" ); + look = bar.LookupNestedNameSpecifier( "A" ); assertEquals( look, A ); - table.addUsingDeclaration( "f", A ); + bar.addUsingDeclaration( "f", A ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = bar.UnqualifiedFunctionLookup( "f", paramList ); assertTrue( look != null ); assertTrue( look.hasSameParameters( f2 ) ); - - table.pop(); } /** @@ -1265,23 +1167,20 @@ public class ParserSymbolTableTest extends TestCase { public void testThisPointer() throws Exception{ newTable(); - Declaration cls = new Declaration("class"); - cls.setType( TypeInfo.t_class ); + ParserSymbolTable.Declaration cls = table.new Declaration("class"); + cls.setType( ParserSymbolTable.TypeInfo.t_class ); - Declaration fn = new Declaration("function"); - fn.setType( TypeInfo.t_function ); - fn.setCVQualifier( TypeInfo.cvConst ); + ParserSymbolTable.Declaration fn = table.new Declaration("function"); + fn.setType( ParserSymbolTable.TypeInfo.t_function ); + fn.setCVQualifier( ParserSymbolTable.TypeInfo.cvConst ); - table.addDeclaration( cls ); - table.push( cls ); + table.getCompilationUnit().addDeclaration( cls ); + cls.addDeclaration( fn ); - table.addDeclaration( fn ); - table.push( fn ); - - Declaration look = table.Lookup("this"); + ParserSymbolTable.Declaration look = fn.Lookup("this"); assertTrue( look != null ); - assertEquals( look.getType(), TypeInfo.t_type ); + assertEquals( look.getType(), ParserSymbolTable.TypeInfo.t_type ); assertEquals( look.getTypeDeclaration(), cls ); assertEquals( look.getPtrOperator(), "*" ); assertEquals( look.getCVQualifier(), fn.getCVQualifier() ); @@ -1299,24 +1198,20 @@ public class ParserSymbolTableTest extends TestCase { public void testEnumerator() throws Exception{ newTable(); - Declaration cls = new Declaration("class"); - cls.setType( TypeInfo.t_class ); + ParserSymbolTable.Declaration cls = table.new Declaration("class"); + cls.setType( ParserSymbolTable.TypeInfo.t_class ); - Declaration enumeration = new Declaration("enumeration"); - enumeration.setType( TypeInfo.t_enumeration ); + ParserSymbolTable.Declaration enumeration = table.new Declaration("enumeration"); + enumeration.setType( ParserSymbolTable.TypeInfo.t_enumeration ); - table.addDeclaration( cls ); - table.push( cls ); - table.addDeclaration( enumeration ); - table.push( enumeration ); + table.getCompilationUnit().addDeclaration( cls ); + cls.addDeclaration( enumeration ); - Declaration enumerator = new Declaration( "enumerator" ); - enumerator.setType( TypeInfo.t_enumerator ); - table.addDeclaration( enumerator ); + ParserSymbolTable.Declaration enumerator = table.new Declaration( "enumerator" ); + enumerator.setType( ParserSymbolTable.TypeInfo.t_enumerator ); + enumeration.addDeclaration( enumerator ); - table.pop(); - - Declaration look = table.Lookup( "enumerator" ); + ParserSymbolTable.Declaration look = cls.Lookup( "enumerator" ); assertEquals( look, enumerator ); assertEquals( look.getContainingScope(), cls ); assertEquals( look.getTypeDeclaration(), enumeration ); @@ -1338,54 +1233,50 @@ public class ParserSymbolTableTest extends TestCase { public void testArgumentDependentLookup() throws Exception{ newTable(); - Declaration NS = new Declaration("NS"); - NS.setType( TypeInfo.t_namespace ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - table.addDeclaration( NS ); - table.push( NS ); + ParserSymbolTable.Declaration NS = table.new Declaration("NS"); + NS.setType( ParserSymbolTable.TypeInfo.t_namespace ); - Declaration T = new Declaration("T"); - T.setType( TypeInfo.t_class ); + compUnit.addDeclaration( NS ); - table.addDeclaration( T ); + ParserSymbolTable.Declaration T = table.new Declaration("T"); + T.setType( ParserSymbolTable.TypeInfo.t_class ); - Declaration f = new Declaration("f"); - f.setType( TypeInfo.t_function ); - f.setReturnType( TypeInfo.t_void ); + NS.addDeclaration( T ); - Declaration look = table.Lookup( "T" ); + ParserSymbolTable.Declaration f = table.new Declaration("f"); + f.setType( ParserSymbolTable.TypeInfo.t_function ); + f.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + + ParserSymbolTable.Declaration look = NS.Lookup( "T" ); assertEquals( look, T ); f.addParameter( look, 0, "", false ); - table.addDeclaration( f ); - - table.pop(); //done NS + NS.addDeclaration( f ); - look = table.LookupNestedNameSpecifier( "NS" ); + look = compUnit.LookupNestedNameSpecifier( "NS" ); assertEquals( look, NS ); - table.push( look ); - look = table.QualifiedLookup( "T" ); + look = look.QualifiedLookup( "T" ); assertEquals( look, T ); - table.pop(); - Declaration param = new Declaration("parm"); - param.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration param = table.new Declaration("parm"); + param.setType( ParserSymbolTable.TypeInfo.t_type ); param.setTypeDeclaration( look ); - table.addDeclaration( param ); - - Declaration main = new Declaration("main"); - main.setType( TypeInfo.t_function ); - main.setReturnType( TypeInfo.t_int ); - table.addDeclaration( main ); - table.push( main ); + compUnit.addDeclaration( param ); + ParserSymbolTable.Declaration main = table.new Declaration("main"); + main.setType( ParserSymbolTable.TypeInfo.t_function ); + main.setReturnType( ParserSymbolTable.TypeInfo.t_int ); + compUnit.addDeclaration( main ); + LinkedList paramList = new LinkedList(); - look = table.Lookup( "parm" ); + look = main.Lookup( "parm" ); assertEquals( look, param ); - TypeInfo p = new TypeInfo( TypeInfo.t_type, look, 0, null, false ); + ParserSymbolTable.TypeInfo p = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, look, 0, null, false ); paramList.add( p ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = main.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f ); } @@ -1415,65 +1306,63 @@ public class ParserSymbolTableTest extends TestCase { public void testArgumentDependentLookup_2() throws Exception{ newTable(); - Declaration NS1 = new Declaration( "NS1" ); - NS1.setType( TypeInfo.t_namespace ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + + ParserSymbolTable.Declaration NS1 = table.new Declaration( "NS1" ); + NS1.setType( ParserSymbolTable.TypeInfo.t_namespace ); - table.addDeclaration( NS1 ); - table.push( NS1 ); + compUnit.addDeclaration( NS1 ); - Declaration f1 = new Declaration( "f" ); - f1.setType( TypeInfo.t_function ); - f1.setReturnType( TypeInfo.t_void ); - f1.addParameter( TypeInfo.t_void, 0, "*", false ); - table.addDeclaration( f1 ); - table.pop(); + ParserSymbolTable.Declaration f1 = table.new Declaration( "f" ); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); + f1.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f1.addParameter( ParserSymbolTable.TypeInfo.t_void, 0, "*", false ); + NS1.addDeclaration( f1 ); - Declaration NS2 = new Declaration( "NS2" ); - NS2.setType( TypeInfo.t_namespace ); + ParserSymbolTable.Declaration NS2 = table.new Declaration( "NS2" ); + NS2.setType( ParserSymbolTable.TypeInfo.t_namespace ); - table.addDeclaration( NS2 ); - table.push( NS2 ); + compUnit.addDeclaration( NS2 ); - Declaration look = table.Lookup( "NS1" ); + ParserSymbolTable.Declaration look = NS2.Lookup( "NS1" ); assertEquals( look, NS1 ); - table.addUsingDirective( look ); + NS2.addUsingDirective( look ); - Declaration B = new Declaration( "B" ); - B.setType( TypeInfo.t_class ); - table.addDeclaration( B ); + ParserSymbolTable.Declaration B = table.new Declaration( "B" ); + B.setType( ParserSymbolTable.TypeInfo.t_class ); + NS2.addDeclaration( B ); - Declaration f2 = new Declaration( "f" ); - f2.setType( TypeInfo.t_function ); - f2.setReturnType( TypeInfo.t_void ); - f2.addParameter( TypeInfo.t_void, 0, "*", false ); - table.addDeclaration( f2 ); - table.pop(); + ParserSymbolTable.Declaration f2 = table.new Declaration( "f" ); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); + f2.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_void, 0, "*", false ); + NS2.addDeclaration( f2 ); - Declaration A = new Declaration( "A" ); - A.setType( TypeInfo.t_class ); - look = table.LookupNestedNameSpecifier( "NS2" ); + ParserSymbolTable.Declaration A = table.new Declaration( "A" ); + A.setType( ParserSymbolTable.TypeInfo.t_class ); + look = compUnit.LookupNestedNameSpecifier( "NS2" ); assertEquals( look, NS2 ); - table.push( look ); - look = table.QualifiedLookup( "B" ); + + look = NS2.QualifiedLookup( "B" ); assertEquals( look, B ); A.addParent( look ); - table.addDeclaration( A ); + compUnit.addDeclaration( A ); - look = table.Lookup( "A" ); + look = compUnit.Lookup( "A" ); assertEquals( look, A ); - Declaration a = new Declaration( "a" ); - a.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration a = table.new Declaration( "a" ); + a.setType( ParserSymbolTable.TypeInfo.t_type ); a.setTypeDeclaration( look ); - table.addDeclaration( a ); + compUnit.addDeclaration( a ); LinkedList paramList = new LinkedList(); - look = table.Lookup( "a" ); + look = compUnit.Lookup( "a" ); assertEquals( look, a ); - TypeInfo param = new TypeInfo( look.getType(), look, 0, "&", false ); + ParserSymbolTable.TypeInfo param = new ParserSymbolTable.TypeInfo( look.getType(), look, 0, "&", false ); paramList.add( param ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f2 ); } @@ -1500,62 +1389,61 @@ public class ParserSymbolTableTest extends TestCase { public void testFunctionOverloading() throws Exception{ newTable(); - Declaration C = new Declaration( "C" ); - C.setType( TypeInfo.t_class ); - table.addDeclaration(C); - table.push(C); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); + + ParserSymbolTable.Declaration C = table.new Declaration( "C" ); + C.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration(C); - Declaration f1 = new Declaration("foo"); - f1.setType( TypeInfo.t_function ); - f1.setReturnType( TypeInfo.t_void ); - f1.addParameter( TypeInfo.t_int, 0, "", false ); - table.addDeclaration( f1 ); + ParserSymbolTable.Declaration f1 = table.new Declaration("foo"); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); + f1.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, "", false ); + C.addDeclaration( f1 ); - Declaration f2 = new Declaration("foo"); - f2.setType( TypeInfo.t_function ); - f2.setReturnType( TypeInfo.t_void ); - f2.addParameter( TypeInfo.t_int, 0, "", false ); - f2.addParameter( TypeInfo.t_char, 0, "", false ); - table.addDeclaration( f2 ); + ParserSymbolTable.Declaration f2 = table.new Declaration("foo"); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); + f2.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, "", false ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, "", false ); + C.addDeclaration( f2 ); - Declaration f3 = new Declaration("foo"); - f3.setType( TypeInfo.t_function ); - f3.setReturnType( TypeInfo.t_void ); - f3.addParameter( TypeInfo.t_int, 0, "", false ); - f3.addParameter( TypeInfo.t_char, 0, "", false ); + ParserSymbolTable.Declaration f3 = table.new Declaration("foo"); + f3.setType( ParserSymbolTable.TypeInfo.t_function ); + f3.setReturnType( ParserSymbolTable.TypeInfo.t_void ); + f3.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, "", false ); + f3.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, "", false ); f3.addParameter( C, 0, "*", false ); - table.addDeclaration( f3 ); - table.pop(); + C.addDeclaration( f3 ); - Declaration look = table.Lookup("C"); + ParserSymbolTable.Declaration look = compUnit.Lookup("C"); assertEquals( look, C ); - Declaration c = new Declaration("c"); - c.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration c = table.new Declaration("c"); + c.setType( ParserSymbolTable.TypeInfo.t_type ); c.setTypeDeclaration( look ); c.setPtrOperator( "*" ); - table.addDeclaration( c ); + compUnit.addDeclaration( c ); - look = table.Lookup( "c" ); + look = compUnit.Lookup( "c" ); assertEquals( look, c ); assertEquals( look.getTypeDeclaration(), C ); - table.push( look.getTypeDeclaration() ); LinkedList paramList = new LinkedList(); - TypeInfo p1 = new TypeInfo( TypeInfo.t_int, null, 0, "", false); - TypeInfo p2 = new TypeInfo( TypeInfo.t_char, null, 0, "", false); - TypeInfo p3 = new TypeInfo( TypeInfo.t_type, c, 0, "", false); + ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_int, null, 0, "", false); + ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, null, 0, "", false); + ParserSymbolTable.TypeInfo p3 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, c, 0, "", false); paramList.add( p1 ); - look = table.MemberFunctionLookup( "foo", paramList ); + look = C.MemberFunctionLookup( "foo", paramList ); assertEquals( look, f1 ); paramList.add( p2 ); - look = table.MemberFunctionLookup( "foo", paramList ); + look = C.MemberFunctionLookup( "foo", paramList ); assertEquals( look, f2 ); paramList.add( p3 ); - look = table.MemberFunctionLookup( "foo", paramList ); + look = C.MemberFunctionLookup( "foo", paramList ); assertEquals( look, f3 ); } @@ -1574,36 +1462,38 @@ public class ParserSymbolTableTest extends TestCase { public void testFunctionResolution() throws Exception{ newTable(); - Declaration f1 = new Declaration("f"); - f1.setType( TypeInfo.t_function ); - f1.addParameter( TypeInfo.t_int, 0, "", false ); - table.addDeclaration( f1 ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration f2 = new Declaration("f"); - f2.setType( TypeInfo.t_function ); - f2.addParameter( TypeInfo.t_char, 0, "", true ); - table.addDeclaration( f2 ); + ParserSymbolTable.Declaration f1 = table.new Declaration("f"); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); + f1.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, "", false ); + compUnit.addDeclaration( f1 ); + + ParserSymbolTable.Declaration f2 = table.new Declaration("f"); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_char, 0, "", true ); + compUnit.addDeclaration( f2 ); LinkedList paramList = new LinkedList(); - TypeInfo p1 = new TypeInfo( TypeInfo.t_int, null, 0, "", false ); + ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_int, null, 0, "", false ); paramList.add( p1 ); - Declaration look = table.UnqualifiedFunctionLookup( "f", paramList ); + ParserSymbolTable.Declaration look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f1 ); paramList.clear(); - TypeInfo p2 = new TypeInfo( TypeInfo.t_char, null, 0, "", false ); + ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, null, 0, "", false ); paramList.add( p2 ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f2 ); paramList.clear(); - TypeInfo p3 = new TypeInfo( TypeInfo.t_bool, null, 0, "", false ); + ParserSymbolTable.TypeInfo p3 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_bool, null, 0, "", false ); paramList.add( p3 ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f1 ); - look = table.UnqualifiedFunctionLookup( "f", null ); + look = compUnit.UnqualifiedFunctionLookup( "f", null ); assertEquals( look, f2 ); } @@ -1627,50 +1517,52 @@ public class ParserSymbolTableTest extends TestCase { public void testFunctionResolution_PointersAndBaseClasses() throws Exception{ newTable(); - Declaration A = new Declaration( "A" ); - A.setType( TypeInfo.t_class ); - table.addDeclaration( A ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration B = new Declaration( "B" ); - B.setType( TypeInfo.t_class ); + ParserSymbolTable.Declaration A = table.new Declaration( "A" ); + A.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( A ); + + ParserSymbolTable.Declaration B = table.new Declaration( "B" ); + B.setType( ParserSymbolTable.TypeInfo.t_class ); B.addParent( A ); - table.addDeclaration( B ); + compUnit.addDeclaration( B ); - Declaration C = new Declaration( "C" ); - C.setType( TypeInfo.t_class ); + ParserSymbolTable.Declaration C = table.new Declaration( "C" ); + C.setType( ParserSymbolTable.TypeInfo.t_class ); C.addParent( B ); - table.addDeclaration( C ); + compUnit.addDeclaration( C ); - Declaration f1 = new Declaration( "f" ); - f1.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f1 = table.new Declaration( "f" ); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); f1.addParameter( A, 0, "*", false ); - table.addDeclaration( f1 ); + compUnit.addDeclaration( f1 ); - Declaration f2 = new Declaration( "f" ); - f2.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f2 = table.new Declaration( "f" ); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); f2.addParameter( B, 0, "*", false ); - table.addDeclaration( f2 ); + compUnit.addDeclaration( f2 ); - Declaration a = new Declaration( "a" ); - a.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration a = table.new Declaration( "a" ); + a.setType( ParserSymbolTable.TypeInfo.t_type ); a.setTypeDeclaration( A ); a.setPtrOperator( "*" ); - Declaration c = new Declaration( "c" ); - c.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration c = table.new Declaration( "c" ); + c.setType( ParserSymbolTable.TypeInfo.t_type ); c.setTypeDeclaration( C ); c.setPtrOperator( "*" ); LinkedList paramList = new LinkedList(); - TypeInfo p1 = new TypeInfo( TypeInfo.t_type, a, 0, null, false ); + ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, a, 0, null, false ); paramList.add( p1 ); - Declaration look = table.UnqualifiedFunctionLookup( "f", paramList ); + ParserSymbolTable.Declaration look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f1 ); paramList.clear(); - TypeInfo p2 = new TypeInfo( TypeInfo.t_type, c, 0, "", false ); + ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, c, 0, "", false ); paramList.add( p2 ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f2 ); } @@ -1697,64 +1589,66 @@ public class ParserSymbolTableTest extends TestCase { public void testFunctionResolution_TypedefsAndPointers() throws Exception{ newTable(); - Declaration A = new Declaration( "A" ); - A.setType( TypeInfo.t_class ); - table.addDeclaration( A ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration B = new Declaration( "B" ); - B.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration A = table.new Declaration( "A" ); + A.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( A ); + + ParserSymbolTable.Declaration B = table.new Declaration( "B" ); + B.setType( ParserSymbolTable.TypeInfo.t_type ); B.setTypeDeclaration( A ); B.setPtrOperator( "*" ); - table.addDeclaration( B ); + compUnit.addDeclaration( B ); - Declaration f1 = new Declaration( "f" ); - f1.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f1 = table.new Declaration( "f" ); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); f1.addParameter( A, 0, "*", false ); - table.addDeclaration( f1 ); + compUnit.addDeclaration( f1 ); - Declaration f2 = new Declaration( "f" ); - f2.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f2 = table.new Declaration( "f" ); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); f2.addParameter( A, 0, null, false ); - table.addDeclaration( f2 ); + compUnit.addDeclaration( f2 ); - Declaration a = new Declaration( "a" ); - a.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration a = table.new Declaration( "a" ); + a.setType( ParserSymbolTable.TypeInfo.t_type ); a.setTypeDeclaration( A ); - table.addDeclaration( a ); + compUnit.addDeclaration( a ); - Declaration b = new Declaration( "b" ); - b.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration b = table.new Declaration( "b" ); + b.setType( ParserSymbolTable.TypeInfo.t_type ); b.setTypeDeclaration( B ); - table.addDeclaration( b ); + compUnit.addDeclaration( b ); - Declaration array = new Declaration( "array" ); - array.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration array = table.new Declaration( "array" ); + array.setType( ParserSymbolTable.TypeInfo.t_type ); array.setTypeDeclaration( A ); array.setPtrOperator( "[]" ); LinkedList paramList = new LinkedList(); - TypeInfo p = new TypeInfo( TypeInfo.t_type, a, 0, null, false ); + ParserSymbolTable.TypeInfo p = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, a, 0, null, false ); paramList.add( p ); - Declaration look = table.UnqualifiedFunctionLookup( "f", paramList ); + ParserSymbolTable.Declaration look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f2 ); p.setPtrOperator( "&" ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f1 ); p.setTypeDeclaration( b ); p.setPtrOperator( null ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f1 ); p.setPtrOperator( "*" ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f2 ); p.setTypeDeclaration( array ); p.setPtrOperator( null ); - look = table.UnqualifiedFunctionLookup( "f", paramList ); + look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f1 ); } @@ -1778,39 +1672,37 @@ public class ParserSymbolTableTest extends TestCase { public void testUserDefinedConversionSequences() throws Exception{ newTable(); - Declaration A = new Declaration( "A" ); - A.setType( TypeInfo.t_class ); - table.addDeclaration( A ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - Declaration B = new Declaration( "B" ); - B.setType( TypeInfo.t_class ); - table.addDeclaration( B ); + ParserSymbolTable.Declaration A = table.new Declaration( "A" ); + A.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( A ); - table.push( B ); + ParserSymbolTable.Declaration B = table.new Declaration( "B" ); + B.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( B ); //12.1-1 "Constructors do not have names" - Declaration constructor = new Declaration(""); - constructor.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration constructor = table.new Declaration(""); + constructor.setType( ParserSymbolTable.TypeInfo.t_function ); constructor.addParameter( A, 0, null, false ); - table.addDeclaration( constructor ); + B.addDeclaration( constructor ); - table.pop(); - - Declaration f = new Declaration( "f" ); - f.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f = table.new Declaration( "f" ); + f.setType( ParserSymbolTable.TypeInfo.t_function ); f.addParameter( B, 0, null, false ); - table.addDeclaration( f ); + compUnit.addDeclaration( f ); - Declaration a = new Declaration( "a" ); - a.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration a = table.new Declaration( "a" ); + a.setType( ParserSymbolTable.TypeInfo.t_type ); a.setTypeDeclaration( A ); - table.addDeclaration( a ); + compUnit.addDeclaration( a ); LinkedList paramList = new LinkedList(); - TypeInfo p = new TypeInfo( TypeInfo.t_type, a, 0, null, false ); + ParserSymbolTable.TypeInfo p = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, a, 0, null, false ); paramList.add( p ); - Declaration look = table.UnqualifiedFunctionLookup( "f", paramList ); + ParserSymbolTable.Declaration look = compUnit.UnqualifiedFunctionLookup( "f", paramList ); assertEquals( look, f ); } @@ -1838,67 +1730,68 @@ public class ParserSymbolTableTest extends TestCase { public void testOverloadRanking() throws Exception{ newTable(); - Declaration f1 = new Declaration( "f" ); - f1.setType( TypeInfo.t_function ); - f1.addParameter( TypeInfo.t_int, TypeInfo.cvConst, "*", false ); - f1.addParameter( TypeInfo.t_int | TypeInfo.isShort, 0, null, false ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - table.addDeclaration( f1 ); + ParserSymbolTable.Declaration f1 = table.new Declaration( "f" ); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); + f1.addParameter( ParserSymbolTable.TypeInfo.t_int, ParserSymbolTable.TypeInfo.cvConst, "*", false ); + f1.addParameter( ParserSymbolTable.TypeInfo.t_int | ParserSymbolTable.TypeInfo.isShort, 0, null, false ); - Declaration f2 = new Declaration( "f" ); - f2.setType( TypeInfo.t_function ); - f2.addParameter( TypeInfo.t_int, 0, "*", false ); - f2.addParameter( TypeInfo.t_int, 0, null, false ); - table.addDeclaration( f2 ); + compUnit.addDeclaration( f1 ); - Declaration i = new Declaration( "i" ); - i.setType( TypeInfo.t_int ); - table.addDeclaration( i ); + ParserSymbolTable.Declaration f2 = table.new Declaration( "f" ); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, "*", false ); + f2.addParameter( ParserSymbolTable.TypeInfo.t_int, 0, null, false ); + compUnit.addDeclaration( f2 ); - Declaration s = new Declaration( "s" ); - s.setType( TypeInfo.t_int ); - s.getTypeInfo().setBit( true, TypeInfo.isShort ); - table.addDeclaration( s ); + ParserSymbolTable.Declaration i = table.new Declaration( "i" ); + i.setType( ParserSymbolTable.TypeInfo.t_int ); + compUnit.addDeclaration( i ); - Declaration main = new Declaration( "main" ); - main.setType( TypeInfo.t_function ); - table.addDeclaration( main ); - table.push( main ); + ParserSymbolTable.Declaration s = table.new Declaration( "s" ); + s.setType( ParserSymbolTable.TypeInfo.t_int ); + s.getTypeInfo().setBit( true, ParserSymbolTable.TypeInfo.isShort ); + compUnit.addDeclaration( s ); + + ParserSymbolTable.Declaration main = table.new Declaration( "main" ); + main.setType( ParserSymbolTable.TypeInfo.t_function ); + compUnit.addDeclaration( main ); LinkedList params = new LinkedList(); - TypeInfo p1 = new TypeInfo( TypeInfo.t_type, i, 0, "&", false ); - TypeInfo p2 = new TypeInfo( TypeInfo.t_type, s, 0, null, false ); + ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, i, 0, "&", false ); + ParserSymbolTable.TypeInfo p2 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, s, 0, null, false ); params.add( p1 ); params.add( p2 ); - Declaration look = null; + ParserSymbolTable.Declaration look = null; try{ - look = table.UnqualifiedFunctionLookup( "f", params ); + main = main.UnqualifiedFunctionLookup( "f", params ); assertTrue( false ); } catch ( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } params.clear(); - TypeInfo p3 = new TypeInfo( TypeInfo.t_int | TypeInfo.isLong, null, 0, null, false ); + ParserSymbolTable.TypeInfo p3 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_int | ParserSymbolTable.TypeInfo.isLong, null, 0, null, false ); params.add( p1 ); params.add( p3 ); - look = table.UnqualifiedFunctionLookup( "f", params ); + look = main.UnqualifiedFunctionLookup( "f", params ); assertEquals( look, f2 ); params.clear(); - TypeInfo p4 = new TypeInfo( TypeInfo.t_char, null, 0, null, false ); + ParserSymbolTable.TypeInfo p4 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_char, null, 0, null, false ); params.add( p1 ); params.add( p4 ); - look = table.UnqualifiedFunctionLookup( "f", params ); + look = main.UnqualifiedFunctionLookup( "f", params ); assertEquals( look, f2 ); params.clear(); - p1.setCVQualifier( TypeInfo.cvConst ); + p1.setCVQualifier( ParserSymbolTable.TypeInfo.cvConst ); params.add( p1 ); params.add( p3 ); - look = table.UnqualifiedFunctionLookup( "f", params ); + look = main.UnqualifiedFunctionLookup( "f", params ); assertEquals( look, f1 ); } @@ -1930,79 +1823,75 @@ public class ParserSymbolTableTest extends TestCase { public void testUserDefinedConversionByOperator() throws Exception{ newTable(); - Declaration B = new Declaration( "B" ); - B.setType( TypeInfo.t_class ); + ParserSymbolTable.Declaration compUnit = table.getCompilationUnit(); - table.addDeclaration( B ); + ParserSymbolTable.Declaration B = table.new Declaration( "B" ); + B.setType( ParserSymbolTable.TypeInfo.t_class ); - Declaration A = new Declaration( "A" ); - A.setType( TypeInfo.t_class ); - table.addDeclaration( A ); + compUnit.addDeclaration( B ); - table.push( A ); - Declaration constructA = new Declaration( "" ); - constructA.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration A = table.new Declaration( "A" ); + A.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( A ); + + ParserSymbolTable.Declaration constructA = table.new Declaration( "" ); + constructA.setType( ParserSymbolTable.TypeInfo.t_function ); constructA.addParameter( B, 0, "&", false ); - table.addDeclaration( constructA ); - table.pop(); + A.addDeclaration( constructA ); - table.push( B ); - Declaration operator = new Declaration( "operator A" ); - operator.setType( TypeInfo.t_function ); - table.addDeclaration( operator ); - table.pop(); + ParserSymbolTable.Declaration operator = table.new Declaration( "operator A" ); + operator.setType( ParserSymbolTable.TypeInfo.t_function ); + B.addDeclaration( operator ); - Declaration f1 = new Declaration( "f" ); - f1.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f1 = table.new Declaration( "f" ); + f1.setType( ParserSymbolTable.TypeInfo.t_function ); f1.addParameter( A, 0, null, false ); - table.addDeclaration( f1 ); + compUnit.addDeclaration( f1 ); - Declaration b = new Declaration( "b" ); - b.setType( TypeInfo.t_type ); + ParserSymbolTable.Declaration b = table.new Declaration( "b" ); + b.setType( ParserSymbolTable.TypeInfo.t_type ); b.setTypeDeclaration( B ); LinkedList params = new LinkedList(); - TypeInfo p1 = new TypeInfo( TypeInfo.t_type, b, 0, null, false ); + ParserSymbolTable.TypeInfo p1 = new ParserSymbolTable.TypeInfo( ParserSymbolTable.TypeInfo.t_type, b, 0, null, false ); params.add( p1 ); - Declaration look = null; + ParserSymbolTable.Declaration look = null; try{ - look = table.UnqualifiedFunctionLookup( "f", params ); + look = compUnit.UnqualifiedFunctionLookup( "f", params ); assertTrue( false ); } catch( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } - Declaration C = new Declaration("C"); - C.setType( TypeInfo.t_class ); - table.addDeclaration( C ); + ParserSymbolTable.Declaration C = table.new Declaration("C"); + C.setType( ParserSymbolTable.TypeInfo.t_class ); + compUnit.addDeclaration( C ); - table.push( C ); - Declaration constructC = new Declaration(""); - constructC.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration constructC = table.new Declaration(""); + constructC.setType( ParserSymbolTable.TypeInfo.t_function ); constructC.addParameter( B, 0, "&", false ); - table.addDeclaration( constructC ); - table.pop(); - - Declaration f2 = new Declaration( "f" ); - f2.setType( TypeInfo.t_function ); + C.addDeclaration( constructC ); + + ParserSymbolTable.Declaration f2 = table.new Declaration( "f" ); + f2.setType( ParserSymbolTable.TypeInfo.t_function ); f2.addParameter( C, 0, null, false ); - table.addDeclaration( f2 ); + compUnit.addDeclaration( f2 ); try{ - look = table.UnqualifiedFunctionLookup( "f", params ); + look = compUnit.UnqualifiedFunctionLookup( "f", params ); assertTrue( false ); } catch( ParserSymbolTableException e ){ assertEquals( e.reason, ParserSymbolTableException.r_Ambiguous ); } - Declaration f3 = new Declaration( "f" ); - f3.setType( TypeInfo.t_function ); + ParserSymbolTable.Declaration f3 = table.new Declaration( "f" ); + f3.setType( ParserSymbolTable.TypeInfo.t_function ); f3.addParameter( B, 0, null, false ); - table.addDeclaration( f3 ); + compUnit.addDeclaration( f3 ); - look = table.UnqualifiedFunctionLookup( "f", params ); + look = compUnit.UnqualifiedFunctionLookup( "f", params ); assertEquals( look, f3 ); } }