1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Patch for John Camelon:

- Added AccessSpecifier and ClassKind to parser.util package and refactored callbacks. 
- Better encapsulated ExceptionSpecification in the DOM.
- Updated DOM structures to return unmodifiable collections.
- Added callback support for asmdefinitions.  
- Added callback support for constructor initializer chains.
- Fixed bug 35781 and updated parser to catch all exceptions from callbacks to ensure best-effort parsing. 
- Removed Main.java from Parser package.
- Updated tests.
This commit is contained in:
Doug Schaefer 2003-03-29 05:35:50 +00:00
parent b6bc4d280b
commit 53b11edee4
33 changed files with 1055 additions and 383 deletions

View file

@ -0,0 +1,34 @@
/**********************************************************************
* Created on Mar 26, 2003
*
* 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.dom;
/**
* @author jcamelon
*
*/
public class ASMDefinition extends Declaration {
final private String assemblyCode;
public ASMDefinition( String code )
{
assemblyCode = code;
}
/**
* @return String
*/
public String getAssemblyCode() {
return assemblyCode;
}
}

View file

@ -1,5 +1,7 @@
package org.eclipse.cdt.internal.core.dom;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.ClassKey;
import org.eclipse.cdt.internal.core.parser.util.Name;
/**
@ -17,11 +19,12 @@ public class BaseSpecifier {
classSpecifier.addBaseSpecifier(this);
switch (classSpecifier.getClassKey()) {
case ClassSpecifier.t_class:
access = t_private;
case ClassKey.t_class:
access.setAccess(AccessSpecifier.v_private);
break;
case ClassSpecifier.t_struct:
access = t_public;
case ClassKey.t_struct:
default:
access.setAccess(AccessSpecifier.v_public);
break;
}
}
@ -33,12 +36,10 @@ public class BaseSpecifier {
public void setVirtual(boolean isVirtual) { this.isVirtual = isVirtual; }
public boolean isVirtual() { return isVirtual; }
public static final int t_private = 0;
public static final int t_protected = 1;
public static final int t_public = 2;
private int access;
public void setAccess(int access) { this.access = access; }
public int getAccess() { return access; }
private AccessSpecifier access = new AccessSpecifier();
public void setAccess(int access) { this.access.setAccess(access); }
public int getAccess() { return access.getAccess(); }
private Name name;
public void setName(Name name) { this.name = name; }

View file

@ -1,28 +1,23 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.ClassKey;
import org.eclipse.cdt.internal.core.parser.util.Name;
public class ClassSpecifier extends TypeSpecifier implements IScope {
public static final int t_class = 0;
public static final int t_struct = 1;
public static final int t_union = 2;
AccessSpecifier access = new AccessSpecifier();
ClassKey key = new ClassKey();
public static final int v_public = 0;
public static final int v_protected = 1;
public static final int v_private = 3;
private int currentVisibility;
private final int classKey;
public int getClassKey() { return classKey; }
public int getClassKey() { return key.getClassKey(); }
public ClassSpecifier(int classKey, SimpleDeclaration declaration) {
super(declaration);
this.classKey = classKey;
this.key.setClassKey(classKey);
}
private Name name;
@ -33,7 +28,7 @@ public class ClassSpecifier extends TypeSpecifier implements IScope {
public void addBaseSpecifier(BaseSpecifier baseSpecifier) {
baseSpecifiers.add(baseSpecifier);
}
public List getBaseSpecifiers() { return baseSpecifiers; }
public List getBaseSpecifiers() { return Collections.unmodifiableList(baseSpecifiers); }
private List declarations = new LinkedList();
@ -42,13 +37,13 @@ public class ClassSpecifier extends TypeSpecifier implements IScope {
}
public List getDeclarations() {
return declarations;
return Collections.unmodifiableList( declarations );
}
/**
* @return int
*/
public int getCurrentVisibility() {
return currentVisibility;
return access.getAccess();
}
/**
@ -56,7 +51,7 @@ public class ClassSpecifier extends TypeSpecifier implements IScope {
* @param currentVisiblity The currentVisiblity to set
*/
public void setCurrentVisibility(int currentVisiblity) {
this.currentVisibility = currentVisiblity;
access.setAccess(currentVisiblity);
}
}

View file

@ -0,0 +1,52 @@
/**********************************************************************
* Created on Mar 28, 2003
*
* 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.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author jcamelon
*
*/
public class ConstructorChain {
private List chainElements = new ArrayList();
/**
* @return List
*/
public List getChainElements() {
return Collections.unmodifiableList( chainElements );
}
public void addChainElement( ConstructorChainElement chainElement )
{
chainElements.add( chainElement );
}
public ConstructorChain( Declarator declarator )
{
this.ownerDeclarator = declarator;
}
private final Declarator ownerDeclarator;
/**
* @return Declarator
*/
public Declarator getOwnerDeclarator() {
return ownerDeclarator;
}
}

View file

@ -0,0 +1,69 @@
/**********************************************************************
* Created on Mar 28, 2003
*
* 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.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.util.Name;
/**
* @author jcamelon
*
*/
public class ConstructorChainElement {
private Name name;
private List expressionList = new ArrayList();
private final ConstructorChain ownerChain;
ConstructorChainElement( ConstructorChain chain )
{
ownerChain = chain;
}
/**
* @return Name
*/
public Name getName() {
return name;
}
/**
* Sets the name.
* @param name The name to set
*/
public void setName(Name name) {
this.name = name;
}
/**
* @return List
*/
public List getExpressionList() {
return Collections.unmodifiableList( expressionList );
}
public void addExpression( ConstructorChainElementExpression expression )
{
expressionList.add( expression );
}
/**
* @return ConstructorChain
*/
public ConstructorChain getOwnerChain() {
return ownerChain;
}
}

View file

@ -0,0 +1,51 @@
/**********************************************************************
* Created on Mar 28, 2003
*
* 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.dom;
/**
* @author jcamelon
*
*/
public class ConstructorChainElementExpression implements IExpressionOwner {
Expression exp;
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression()
*/
public Expression getExpression() {
return exp;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#setExpression(org.eclipse.cdt.internal.core.dom.Expression)
*/
public void setExpression(Expression exp) {
this.exp = exp;
}
ConstructorChainElementExpression( ConstructorChainElement element )
{
this.ownerElement = element;
}
private final ConstructorChainElement ownerElement;
/**
* @return ConstructorChainElement
*/
public ConstructorChainElement getOwnerElement() {
return ownerElement;
}
}

View file

@ -3,6 +3,8 @@ package org.eclipse.cdt.internal.core.dom;
import org.eclipse.cdt.internal.core.parser.IParserCallback;
import org.eclipse.cdt.internal.core.parser.Token;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.ClassKey;
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
import org.eclipse.cdt.internal.core.parser.util.Name;
@ -38,19 +40,19 @@ public class DOMBuilder implements IParserCallback
public Object classSpecifierBegin(Object container, Token classKey) {
SimpleDeclaration decl = (SimpleDeclaration)container;
int kind = ClassSpecifier.t_struct;
int visibility = ClassSpecifier.v_public;
int kind = ClassKey.t_struct;
int visibility = AccessSpecifier.v_public;
switch (classKey.getType()) {
case Token.t_class:
kind = ClassSpecifier.t_class;
visibility = ClassSpecifier.v_private;
kind = ClassKey.t_class;
visibility = AccessSpecifier.v_private;
break;
case Token.t_struct:
kind = ClassSpecifier.t_struct;
kind = ClassKey.t_struct;
break;
case Token.t_union:
kind = ClassSpecifier.t_union;
kind = ClassKey.t_union;
break;
}
@ -225,17 +227,17 @@ public class DOMBuilder implements IParserCallback
public void baseSpecifierVisibility( Object baseSpecifier, Token visibility )
{
int access = BaseSpecifier.t_public;
int access = AccessSpecifier.v_public;
switch( visibility.type )
{
case Token.t_public:
access = BaseSpecifier.t_public;
access = AccessSpecifier.v_public;
break;
case Token.t_protected:
access = BaseSpecifier.t_protected;
access = AccessSpecifier.v_protected;
break;
case Token.t_private:
access = BaseSpecifier.t_private;
access = AccessSpecifier.v_private;
break;
default:
break;
@ -305,17 +307,17 @@ public class DOMBuilder implements IParserCallback
*/
public Object elaboratedTypeSpecifierBegin(Object container, Token classKey) {
SimpleDeclaration declaration = (SimpleDeclaration)container;
int kind = ClassSpecifier.t_struct;
int kind = ClassKey.t_struct;
switch (classKey.getType()) {
case Token.t_class:
kind = ClassSpecifier.t_class;
kind = ClassKey.t_class;
break;
case Token.t_struct:
kind = ClassSpecifier.t_struct;
kind = ClassKey.t_struct;
break;
case Token.t_union:
kind = ClassSpecifier.t_union;
kind = ClassKey.t_union;
break;
}
@ -357,13 +359,13 @@ public class DOMBuilder implements IParserCallback
switch( visibility.getType() )
{
case Token.t_public:
spec.setCurrentVisibility( ClassSpecifier.v_public );
spec.setCurrentVisibility( AccessSpecifier.v_public );
break;
case Token.t_protected:
spec.setCurrentVisibility( ClassSpecifier.v_protected );
spec.setCurrentVisibility( AccessSpecifier.v_protected );
break;
case Token.t_private:
spec.setCurrentVisibility( ClassSpecifier.v_private );
spec.setCurrentVisibility( AccessSpecifier.v_private );
break;
}
}
@ -472,7 +474,7 @@ public class DOMBuilder implements IParserCallback
*/
public void declaratorThrowExceptionName(Object declarator ) {
Declarator decl = (Declarator)declarator;
decl.addExceptionSpecifierTypeName( currName );
decl.getExceptionSpecifier().addTypeName( currName );
}
/* (non-Javadoc)
@ -480,7 +482,7 @@ public class DOMBuilder implements IParserCallback
*/
public void declaratorThrowsException(Object declarator) {
Declarator decl = (Declarator)declarator;
decl.throwsExceptions();
decl.getExceptionSpecifier().setThrowsException(true);
}
/* (non-Javadoc)
@ -650,4 +652,75 @@ public class DOMBuilder implements IParserCallback
*/
public void enumDefinitionEnd(Object enumDefn) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#asmDefinition(java.lang.String)
*/
public void asmDefinition(Object container, String assemblyCode) {
IScope scope = (IScope)container;
ASMDefinition definition = new ASMDefinition( assemblyCode );
scope.addDeclaration( definition );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object)
*/
public Object constructorChainBegin(Object declarator) {
Declarator d = (Declarator)declarator;
ConstructorChain chain = new ConstructorChain(d);
return chain;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainAbort(java.lang.Object)
*/
public void constructorChainAbort(Object ctor) {
ctor = null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object)
*/
public void constructorChainEnd(Object ctor) {
ConstructorChain chain = (ConstructorChain)ctor;
chain.getOwnerDeclarator().setCtorChain(chain);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object)
*/
public Object constructorChainElementBegin(Object ctor) {
return new ConstructorChainElement( (ConstructorChain)ctor );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object)
*/
public void constructorChainElementEnd(Object element) {
ConstructorChainElement ele = (ConstructorChainElement)element;
ele.getOwnerChain().addChainElement( ele );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object)
*/
public void constructorChainElementId(Object element) {
ConstructorChainElement ele = (ConstructorChainElement)element;
ele.setName(currName);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementBegin(java.lang.Object)
*/
public Object constructorChainElementExpressionListElementBegin(Object element) {
return new ConstructorChainElementExpression( (ConstructorChainElement)element );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementEnd(java.lang.Object)
*/
public void constructorChainElementExpressionListElementEnd(Object expression) {
ConstructorChainElementExpression exp = (ConstructorChainElementExpression)expression;
exp.getOwnerElement().addExpression( exp );
}
}

View file

@ -1,6 +1,7 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
@ -80,44 +81,27 @@ public class Declarator implements IExpressionOwner {
initialExpression = exp;
}
List pointerOperators = null;
List arrayQualifiers = null;
List pointerOperators = new ArrayList();
List arrayQualifiers = new ArrayList();
/**
* @return List
*/
public List getPointerOperators() {
return pointerOperators;
return Collections.unmodifiableList(pointerOperators);
}
public void addPointerOperator( PointerOperator po )
{
if( pointerOperators == null )
{
pointerOperators = new ArrayList();
}
pointerOperators.add(po);
}
List exceptionSpecifier = null;
ExceptionSpecifier exceptionSpecifier = new ExceptionSpecifier();
public List getExceptionSpecifier()
public ExceptionSpecifier getExceptionSpecifier()
{
return exceptionSpecifier;
}
public void throwsExceptions()
{
if( exceptionSpecifier == null )
exceptionSpecifier = new ArrayList();
}
public void addExceptionSpecifierTypeName( Name name )
{
exceptionSpecifier.add( name );
}
boolean isConst = false;
boolean isVolatile = false;
@ -155,16 +139,29 @@ public class Declarator implements IExpressionOwner {
* @return List
*/
public List getArrayQualifiers() {
return arrayQualifiers;
return Collections.unmodifiableList( arrayQualifiers );
}
public void addArrayQualifier( ArrayQualifier q )
{
if( arrayQualifiers == null )
{
arrayQualifiers = new ArrayList();
}
arrayQualifiers.add(q);
}
private ConstructorChain ctorChain = null;
/**
* @return ConstructorChain
*/
public ConstructorChain getCtorChain() {
return ctorChain;
}
/**
* Sets the ctorChain.
* @param ctorChain The ctorChain to set
*/
public void setCtorChain(ConstructorChain ctorChain) {
this.ctorChain = ctorChain;
}
}

View file

@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.dom;
import org.eclipse.cdt.internal.core.parser.util.ClassKey;
import org.eclipse.cdt.internal.core.parser.util.Name;
/**
@ -13,14 +14,13 @@ import org.eclipse.cdt.internal.core.parser.util.Name;
*/
public class ElaboratedTypeSpecifier extends TypeSpecifier {
public static final int t_class = 0;
public static final int t_struct = 1;
public static final int t_union = 2;
public static final int t_enum = 3;
private final int classKey;
public int getClassKey() { return classKey; }
ClassKey classKey = new ClassKey();
public int getClassKey() { return classKey.getClassKey(); }
public void setClassKey( int classKey )
{
this.classKey.setClassKey( classKey );
}
/**
* @see org.eclipse.cdt.internal.core.dom.TypeSpecifier#getDeclaration()
@ -38,7 +38,7 @@ public class ElaboratedTypeSpecifier extends TypeSpecifier {
public ElaboratedTypeSpecifier(int classKey, SimpleDeclaration declaration) {
super(declaration);
this.classKey = classKey;
this.classKey.setClassKey( classKey );
}
private Name name;

View file

@ -12,6 +12,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -40,7 +41,7 @@ public class EnumerationSpecifier extends TypeSpecifier {
* @return List
*/
public List getEnumeratorDefinitions() {
return enumeratorDefinitions;
return Collections.unmodifiableList( enumeratorDefinitions );
}
/**

View file

@ -0,0 +1,57 @@
/**********************************************************************
* Created on Mar 26, 2003
*
* 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.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.util.Name;
/**
* @author jcamelon
*
*/
public class ExceptionSpecifier {
private List typeNames = new LinkedList();
private boolean throwsException = false;
/**
* @return List
*/
public List getTypeNames() {
return Collections.unmodifiableList( typeNames );
}
public void addTypeName( Name name )
{
typeNames.add( name );
}
/**
* Sets the throwsException.
* @param throwsException The throwsException to set
*/
public void setThrowsException(boolean throwsException) {
this.throwsException = throwsException;
}
/**
* @return boolean
*/
public boolean throwsException() {
return throwsException;
}
}

View file

@ -12,6 +12,7 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.cdt.internal.core.parser.Token;
@ -31,7 +32,7 @@ public class Expression {
public List tokens()
{
return tokens;
return Collections.unmodifiableList( tokens );
}
}

View file

@ -12,6 +12,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -42,7 +43,7 @@ public class LinkageSpecification extends Declaration implements IScope {
* @see org.eclipse.cdt.internal.core.dom.IScope#getDeclarations()
*/
public List getDeclarations() {
return declarations;
return Collections.unmodifiableList( declarations );
}
/**

View file

@ -1,5 +1,7 @@
package org.eclipse.cdt.internal.core.dom;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
/**
* @author dschaefe
*
@ -9,17 +11,14 @@ package org.eclipse.cdt.internal.core.dom;
* Window>Preferences>Java>Code Generation.
*/
public class MemberDeclaration {
public static final int t_private = 0;
public static final int t_protected = 1;
public static final int t_public = 2;
public MemberDeclaration(int access, Declaration declaration) {
this.access = access;
this.access.setAccess( access );
this.declaration = declaration;
}
private int access;
public int getAccess() { return access; }
private AccessSpecifier access = new AccessSpecifier();
public int getAccess() { return access.getAccess(); }
private Declaration declaration;
public Declaration getDeclaration() { return declaration; }

View file

@ -12,6 +12,7 @@
***********************************************************************/
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -44,7 +45,7 @@ public class NamespaceDefinition extends Declaration implements IScope {
* @see org.eclipse.cdt.internal.core.dom.IScope#getDeclarations()
*/
public List getDeclarations() {
return declarations;
return Collections.unmodifiableList( declarations );
}

View file

@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -41,7 +42,7 @@ public class ParameterDeclaration extends Declaration implements DeclSpecifier.C
}
public List getDeclarators() {
return declarators;
return Collections.unmodifiableList( declarators );
}
/**

View file

@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -25,7 +26,7 @@ public class ParameterDeclarationClause implements IScope {
* @see org.eclipse.cdt.core.dom.IScope#getDeclarations()
*/
public List getDeclarations() {
return declarations;
return Collections.unmodifiableList( declarations );
}
private List declarations = new LinkedList();

View file

@ -21,7 +21,6 @@ public class PointerOperator {
public final static int t_undefined = 0;
public final static int t_pointer = 1;
public final static int t_reference = 2;
private int type = t_undefined;
/**

View file

@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -51,7 +52,7 @@ public class SimpleDeclaration extends Declaration implements DeclSpecifier.Cont
}
public List getDeclarators() {
return declarators;
return Collections.unmodifiableList( declarators );
}
/**

View file

@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.dom;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -15,6 +16,6 @@ public class TranslationUnit implements IScope {
}
public List getDeclarations() {
return declarations;
return Collections.unmodifiableList( declarations );
}
}

View file

@ -1,3 +1,12 @@
2003-03-28 John Camelon
Added AccessSpecifier and ClassKind to parser.util package and refactored callbacks.
Better encapsulated ExceptionSpecification in the DOM.
Updated DOM structures to return unmodifiable collections.
Added callback support for asmdefinitions.
Added callback support for constructor initializer chains.
Fixed bug 35781 and updated parser to catch all exceptions from callbacks to ensure best-effort parsing.
Removed Main.java from Parser package.
2003-03-26 Andrew Niefer
Moved type information and ParameterInfo from Declaration into util.TypeInfo
Initial implementation of standard conversion sequences for function resolution

View file

@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.core.parser.IParserCallback;
import org.eclipse.cdt.internal.core.parser.Token;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
import org.eclipse.cdt.internal.core.parser.util.Name;
@ -39,26 +40,30 @@ public class NewModelBuilder implements IParserCallback {
* @see org.eclipse.cdt.core.newparser.IParserCallback#beginClass(String, String)
*/
public Object classSpecifierBegin(Object container, Token classKey) {
SimpleDeclarationWrapper c = (SimpleDeclarationWrapper)container;
int kind;
switch (classKey.getType()) {
case Token.t_class:
kind = ICElement.C_CLASS;
break;
case Token.t_struct:
kind = ICElement.C_STRUCT;
break;
default:
kind = ICElement.C_UNION;
if( container instanceof SimpleDeclarationWrapper )
{
SimpleDeclarationWrapper c = (SimpleDeclarationWrapper)container;
int kind;
switch (classKey.getType()) {
case Token.t_class:
kind = ICElement.C_CLASS;
break;
case Token.t_struct:
kind = ICElement.C_STRUCT;
break;
default:
kind = ICElement.C_UNION;
}
SimpleDeclarationWrapper wrapper = new SimpleDeclarationWrapper();
wrapper.setKind( kind );
wrapper.setParent( c.getParent() );
return wrapper;
}
SimpleDeclarationWrapper wrapper = new SimpleDeclarationWrapper();
wrapper.setKind( kind );
wrapper.setParent( c.getParent() );
return wrapper;
else
return null;
}
/**
@ -66,8 +71,11 @@ public class NewModelBuilder implements IParserCallback {
*/
public void classSpecifierName(Object classSpecifier)
{
SimpleDeclarationWrapper wrapper = (SimpleDeclarationWrapper)classSpecifier;
wrapper.setName( currName );
if( classSpecifier instanceof SimpleDeclarationWrapper )
{
SimpleDeclarationWrapper wrapper = (SimpleDeclarationWrapper)classSpecifier;
wrapper.setName( currName );
}
}
/**
@ -376,13 +384,13 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
switch( visibility.getType() )
{
case Token.t_public:
spec.setCurrentVisibility( SimpleDeclarationWrapper.v_public );
spec.setCurrentVisibility( AccessSpecifier.v_public );
break;
case Token.t_protected:
spec.setCurrentVisibility( SimpleDeclarationWrapper.v_protected );
spec.setCurrentVisibility( AccessSpecifier.v_protected );
break;
case Token.t_private:
spec.setCurrentVisibility( SimpleDeclarationWrapper.v_private );
spec.setCurrentVisibility( AccessSpecifier.v_private );
break;
}
}
@ -471,48 +479,42 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationBegin(java.lang.Object)
*/
public Object namespaceDefinitionBegin(Object container) {
// TODO Auto-generated method stub
return null;
// until Namespaces are made part of the code model, just return the container object
return container;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationId(java.lang.Object)
*/
public void namespaceDefinitionId(Object namespace) {
// TODO Auto-generated method stub
// until namespaceDefinitionBegin is updated to do more than return its container, do nothing
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationAbort(java.lang.Object)
*/
public void namespaceDefinitionAbort(Object namespace) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationEnd(java.lang.Object)
*/
public void namespaceDefinitionEnd(Object namespace) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#linkageSpecificationBegin(java.lang.Object, java.lang.String)
*/
public Object linkageSpecificationBegin(Object container, String literal) {
// TODO Auto-generated method stub
return null;
// until linkageSpecs are part of the code model (do they need to be?) just return the container object
return container;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#linkageSpecificationEnd(java.lang.Object)
*/
public void linkageSpecificationEnd(Object linkageSpec) {
// TODO Auto-generated method stub
// do not implement anything unless linkageSpecificationBegin does more than just return its container
}
/* (non-Javadoc)
@ -635,4 +637,76 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#asmDefinition(java.lang.String)
*/
public void asmDefinition(Object container, String assemblyCode) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object)
*/
public Object constructorChainBegin(Object declarator) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainAbort(java.lang.Object)
*/
public void constructorChainAbort(Object ctor) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object)
*/
public void constructorChainEnd(Object ctor) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object)
*/
public Object constructorChainElementBegin(Object ctor) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object)
*/
public void constructorChainElementEnd(Object element) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object)
*/
public void constructorChainElementId(Object ctor) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementBegin(java.lang.Object)
*/
public Object constructorChainElementExpressionListElementBegin(Object element) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementEnd(java.lang.Object)
*/
public void constructorChainElementExpressionListElementEnd(Object expression) {
// TODO Auto-generated method stub
}
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
import org.eclipse.cdt.internal.core.parser.util.Name;
@ -228,16 +229,12 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
this.functionDefinition = functionDefinition;
}
public static final int v_public = 0;
public static final int v_protected = 1;
public static final int v_private = 2;
private int currentVisibility;
private AccessSpecifier currentVisibility = new AccessSpecifier();
/**
* @return int
*/
public int getCurrentVisibility() {
return currentVisibility;
return currentVisibility.getAccess();
}
/**
@ -245,7 +242,7 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
* @param currentVisibility The currentVisibility to set
*/
public void setCurrentVisibility(int currentVisibility) {
this.currentVisibility = currentVisibility;
this.currentVisibility.setAccess( currentVisibility );
}
/**

View file

@ -565,4 +565,61 @@ public class ExpressionEvaluator implements IParserCallback {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#asmDefinition(java.lang.String)
*/
public void asmDefinition(Object container, String assemblyCode) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object)
*/
public Object constructorChainBegin(Object declarator) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainAbort(java.lang.Object)
*/
public void constructorChainAbort(Object ctor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object)
*/
public void constructorChainEnd(Object ctor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object)
*/
public Object constructorChainElementBegin(Object ctor) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object)
*/
public void constructorChainElementEnd(Object element) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object)
*/
public void constructorChainElementId(Object ctor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementBegin(java.lang.Object)
*/
public Object constructorChainElementExpressionListElementBegin(Object element) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementEnd(java.lang.Object)
*/
public void constructorChainElementExpressionListElementEnd(Object expression) {
}
}

View file

@ -103,4 +103,17 @@ public interface IParserCallback {
public void enumDefinitionId( Object enumDefn );
public void enumDefinitionEnd( Object enumDefn );
public void asmDefinition( Object container, String assemblyCode );
public Object constructorChainBegin( Object declarator );
public void constructorChainAbort( Object ctor );
public void constructorChainEnd( Object ctor );
public Object constructorChainElementBegin( Object ctor );
public void constructorChainElementId( Object element );
public void constructorChainElementEnd( Object element );
public Object constructorChainElementExpressionListElementBegin( Object element );
public void constructorChainElementExpressionListElementEnd( Object expression );
}

View file

@ -1,82 +0,0 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. 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 implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.parser;
import java.io.FileReader;
import java.io.Reader;
public class Main {
public static void main(String[] args) {
String fileName = null;
// Find the file
for (int i = 0; i < args.length; ++i) {
if (!args[i].startsWith("-"))
fileName = args[i];
}
if (fileName == null) {
System.out.println("Error: no files.");
return;
}
Reader reader;
try {
reader = new FileReader(fileName);
} catch (Exception e) {
System.err.println(e);
return;
}
Scanner scanner = new Scanner();
scanner.initialize( reader, fileName );
// Now pass on the preprocessing options
for (int i = 0; i < args.length; ++i) {
if (args[i].startsWith("-I")) {
String dir = args[i].substring(2);
scanner.addIncludePath(dir);
} else if (args[i].startsWith("-D")) {
int pos = args[i].indexOf('=');
String name;
String value = "";
if (pos < 0) {
name = args[i].substring(2);
} else {
name = args[i].substring(2, pos);
value = args[i].substring(pos + 1);
}
scanner.addDefinition(name, value);
}
}
Parser parser = null;
try {
parser = new Parser(scanner);
} catch (Exception e) {
System.out.println(e);
return;
}
long startTime = System.currentTimeMillis();
try {
parser.parse();
} catch (Exception e) {
System.err.println(e);
}
long time = System.currentTimeMillis() - startTime;
System.out.println("done " + scanner.getCount() + " tokens in " + time + "ms.");
}
}

View file

@ -466,4 +466,61 @@ public class NullParserCallback implements IParserCallback {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#asmDefinition(java.lang.String)
*/
public void asmDefinition(Object container, String assemblyCode) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainBegin(java.lang.Object)
*/
public Object constructorChainBegin(Object declarator) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainAbort(java.lang.Object)
*/
public void constructorChainAbort(Object ctor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainEnd(java.lang.Object)
*/
public void constructorChainEnd(Object ctor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementBegin(java.lang.Object)
*/
public Object constructorChainElementBegin(Object ctor) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementEnd(java.lang.Object)
*/
public void constructorChainElementEnd(Object element) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainId(java.lang.Object)
*/
public void constructorChainElementId(Object ctor) {
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementBegin(java.lang.Object)
*/
public Object constructorChainElementExpressionListElementBegin(Object element) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#constructorChainElementExpressionListElementEnd(java.lang.Object)
*/
public void constructorChainElementExpressionListElementEnd(Object expression) {
}
}

View file

@ -75,7 +75,8 @@ c, quick);
*
*/
protected void translationUnit() throws Backtrack {
Object translationUnit = callback.translationUnitBegin();
Object translationUnit = null;
try{ translationUnit = callback.translationUnitBegin();} catch( Exception e ) {}
Token lastBacktrack = null;
Token lastToken;
while (true) {
@ -101,7 +102,7 @@ c, quick);
}
}
}
callback.translationUnitEnd(translationUnit);
try{ callback.translationUnitEnd(translationUnit);} catch( Exception e ) {}
}
protected void consumeToNextSemicolon() throws EndOfFile {
@ -132,7 +133,8 @@ c, quick);
if( LT(1) == Token.t_namespace )
{
Object directive = callback.usingDirectiveBegin( container );
Object directive = null;
try{ directive = callback.usingDirectiveBegin( container );} catch( Exception e ) {}
// using-directive
consume( Token.t_namespace );
@ -140,29 +142,30 @@ c, quick);
if( LT(1) == Token.tIDENTIFIER || LT(1) == Token.tCOLONCOLON )
{
name();
callback.usingDirectiveNamespaceId( directive );
try{ callback.usingDirectiveNamespaceId( directive );} catch( Exception e ) {}
}
else
{
callback.usingDirectiveAbort(directive);
try{ callback.usingDirectiveAbort(directive);} catch( Exception e ) {}
throw backtrack;
}
if( LT(1) == Token.tSEMI )
{
consume( Token.tSEMI );
callback.usingDirectiveEnd( directive );
try{ callback.usingDirectiveEnd( directive );} catch( Exception e ) {}
return;
}
else
{
callback.usingDirectiveAbort(directive);
try{ callback.usingDirectiveAbort(directive);} catch( Exception e ) {}
throw backtrack;
}
}
else
{
Object usingDeclaration = callback.usingDeclarationBegin( container );
Object usingDeclaration = null;
try{ usingDeclaration = callback.usingDeclarationBegin( container );} catch( Exception e ) {}
boolean typeName = false;
if( LT(1) == Token.t_typename )
@ -175,22 +178,22 @@ c, quick);
{
// optional :: and nested classes handled in name
name();
callback.usingDeclarationMapping( usingDeclaration, typeName );
try{ callback.usingDeclarationMapping( usingDeclaration, typeName ); } catch( Exception e ) {}
}
else
{
callback.usingDeclarationAbort( usingDeclaration );
try{ callback.usingDeclarationAbort( usingDeclaration );} catch( Exception e ) {}
throw backtrack;
}
if( LT(1) == Token.tSEMI )
{
consume( Token.tSEMI );
callback.usingDeclarationEnd( usingDeclaration );
try{ callback.usingDeclarationEnd( usingDeclaration );} catch( Exception e ) {}
}
else
{
callback.usingDeclarationAbort( usingDeclaration );
try{ callback.usingDeclarationAbort( usingDeclaration );} catch( Exception e ) {}
throw backtrack;
}
@ -215,7 +218,8 @@ c, quick);
if( LT(1) != Token.tSTRING )
throw backtrack;
Object linkageSpec = callback.linkageSpecificationBegin( container, consume( Token.tSTRING ).getImage() );
Object linkageSpec = null;
try{ linkageSpec = callback.linkageSpecificationBegin( container, consume( Token.tSTRING ).getImage() );} catch( Exception e ) {}
if( LT(1) == Token.tLBRACE )
{
@ -235,12 +239,12 @@ c, quick);
}
// consume the }
consume();
callback.linkageSpecificationEnd( linkageSpec );
try{ callback.linkageSpecificationEnd( linkageSpec );} catch( Exception e ) {}
}
else // single declaration
{
declaration( linkageSpec );
callback.linkageSpecificationEnd( linkageSpec );
try{ callback.linkageSpecificationEnd( linkageSpec );} catch( Exception e ) {}
}
}
@ -265,8 +269,14 @@ c, quick);
protected void declaration( Object container ) throws Backtrack {
switch (LT(1)) {
case Token.t_asm:
// asmDefinition( );
consume();
consume( Token.t_asm );
consume( Token.tLPAREN );
String assembly = consume( Token.tSTRING ).getImage();
consume( Token.tRPAREN );
consume( Token.tSEMI );
// if we made it this far, then we have all we need
// do the callback
try{ callback.asmDefinition( container, assembly );} catch( Exception e ) {}
return;
case Token.t_namespace:
namespaceDefinition( container );
@ -280,8 +290,11 @@ c, quick);
consume();
return;
case Token.t_extern:
linkageSpecification( container );
return;
if( LT(2) == Token.tSTRING )
{
linkageSpecification( container );
return;
}
default:
simpleDeclaration( container );
}
@ -300,13 +313,14 @@ c, quick);
protected void namespaceDefinition( Object container ) throws Backtrack
{
consume( Token.t_namespace);
Object namespace = callback.namespaceDefinitionBegin( container );
Object namespace = null;
try{ namespace = callback.namespaceDefinitionBegin( container );} catch( Exception e ) {}
// optional name
if( LT(1) == Token.tIDENTIFIER )
{
name();
callback.namespaceDefinitionId( namespace );
try{ callback.namespaceDefinitionId( namespace );} catch( Exception e ) {}
}
if( LT(1) == Token.tLBRACE )
@ -327,11 +341,11 @@ c, quick);
}
// consume the }
consume();
callback.namespaceDefinitionEnd( namespace );
try{ callback.namespaceDefinitionEnd( namespace );} catch( Exception e ) {}
}
else
{
callback.namespaceDefinitionAbort( namespace );
try{ callback.namespaceDefinitionAbort( namespace );} catch( Exception e ) {}
throw backtrack;
}
}
@ -349,12 +363,14 @@ c, quick);
* - work in ctorInitializer and functionTryBlock
*/
protected void simpleDeclaration( Object container ) throws Backtrack {
Object simpleDecl = callback.simpleDeclarationBegin( container);
Object simpleDecl = null;
try{ simpleDecl = callback.simpleDeclarationBegin( container);} catch( Exception e ) {}
declSpecifierSeq(simpleDecl, false);
Object declarator = null;
if (LT(1) != Token.tSEMI)
try {
initDeclarator(simpleDecl);
declarator = initDeclarator(simpleDecl);
while (LT(1) == Token.tCOMMA) {
consume();
@ -374,19 +390,15 @@ c, quick);
consume();
break;
case Token.tCOLON:
// TODO - Initializer for constructor, for now consume
// and look for the left brace;
consume();
while (LT(1) != Token.tLBRACE) {
consume();
}
ctorInitializer(declarator);
// Falling through on purpose
case Token.tLBRACE:
Object function = callback.functionBodyBegin(simpleDecl );
Object function = null;
try{ function = callback.functionBodyBegin(simpleDecl ); } catch( Exception e ) {}
if (quickParse) {
// speed up the parser by skiping the body
// simply look for matching brace and return
consume();
consume(Token.tLBRACE);
int depth = 1;
while (depth > 0) {
switch (consume().getType()) {
@ -401,30 +413,79 @@ c, quick);
} else {
functionBody();
}
callback.functionBodyEnd(function);
try{ callback.functionBodyEnd(function);} catch( Exception e ) {}
break;
default:
break;
}
callback.simpleDeclarationEnd(simpleDecl);
try{ callback.simpleDeclarationEnd(simpleDecl);} catch( Exception e ) {}
}
protected void ctorInitializer(Object declarator) throws Backtrack {
consume( Token.tCOLON );
Object constructorChain = null;
try { constructorChain = callback.constructorChainBegin(declarator);} catch( Exception e ) {}
try {
for( ; ; ) {
if( LT(1) == Token.tLBRACE ) break;
Object constructorChainElement = null;
try{ constructorChainElement = callback.constructorChainElementBegin( constructorChain );} catch( Exception e ) {}
name();
try{ callback.constructorChainElementId(constructorChainElement);} catch( Exception e) {}
consume( Token.tLPAREN );
while( LT(1) != Token.tRPAREN )
{
//handle expression list here
Object item = null;
try{ item = callback.constructorChainElementExpressionListElementBegin(constructorChainElement );} catch( Exception e ) {}
Object expression = null;
try{ expression = callback.expressionBegin( item );} catch( Exception e) {}
assignmentExpression( expression );
try{ callback.expressionEnd( item );} catch( Exception e) {}
try{ callback.constructorChainElementExpressionListElementEnd( item );} catch( Exception e) {}
if( LT(1) == Token.tRPAREN ) break;
consume( Token.tCOMMA );
}
consume( Token.tRPAREN );
try{ callback.constructorChainElementEnd(constructorChainElement );} catch( Exception e) {}
if( LT(1) == Token.tLBRACE ) break;
if( LT(1) == Token.tCOMMA ) consume( Token.tCOMMA );
}
}
catch( Backtrack bt )
{
try { callback.constructorChainAbort( constructorChain );} catch( Exception e ) {}
if( ! quickParse )
throw backtrack;
}
try { callback.constructorChainEnd( constructorChain ); } catch( Exception e ) {}
}
protected void parameterDeclaration( Object containerObject ) throws Backtrack
{
Object parameterDecl = callback.parameterDeclarationBegin( containerObject );
Object parameterDecl = null;
try{ parameterDecl = callback.parameterDeclarationBegin( containerObject );} catch( Exception e ) {}
declSpecifierSeq( parameterDecl, true );
if (LT(1) != Token.tSEMI)
try {
initDeclarator(parameterDecl);
Object declarator = initDeclarator(parameterDecl);
} catch (Backtrack b) {
// allowed to be empty
}
callback.parameterDeclarationEnd( parameterDecl );
try{ callback.parameterDeclarationEnd( parameterDecl );} catch( Exception e ) {}
}
@ -466,7 +527,7 @@ c, quick);
case Token.t_signed:
case Token.t_unsigned:
case Token.t_short:
callback.simpleDeclSpecifier(decl, consume());
try{ callback.simpleDeclSpecifier(decl, consume());} catch( Exception e ) {}
break;
case Token.t_char:
case Token.t_wchar_t:
@ -477,14 +538,14 @@ c, quick);
case Token.t_double:
case Token.t_void:
encounteredRawType = true;
callback.simpleDeclSpecifier(decl, consume());
try{ callback.simpleDeclSpecifier(decl, consume());} catch( Exception e ) {}
break;
case Token.t_typename:
consume();
consume( Token.t_typename );
name();
break;
case Token.tCOLONCOLON:
consume();
consume( Token.tCOLONCOLON );
// handle nested later:
case Token.tIDENTIFIER:
// TODO - Kludgy way to handle constructors/destructors
@ -493,9 +554,9 @@ c, quick);
{
if( ! encounteredTypename )
{
callback.simpleDeclSpecifier(decl,LA(1));
try{ callback.simpleDeclSpecifier(decl,LA(1));} catch( Exception e ) {}
name();
callback.simpleDeclSpecifierName( decl );
try{ callback.simpleDeclSpecifierName( decl );} catch( Exception e ) {}
encounteredTypename = true;
break;
}
@ -512,10 +573,11 @@ c, quick);
catch( Backtrack bt )
{
// this is an elaborated class specifier
Object elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );
Object elab = null;
try{ elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );} catch( Exception e ) {}
name();
callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab );
try{ callback.elaboratedTypeSpecifierName( elab ); } catch( Exception e ) {}
try{ callback.elaboratedTypeSpecifierEnd( elab );} catch( Exception e ) {}
break;
}
case Token.t_enum:
@ -527,10 +589,11 @@ c, quick);
catch( Backtrack bt )
{
// this is an elaborated class specifier
Object elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );
Object elab = null;
try{ elab = callback.elaboratedTypeSpecifierBegin( decl, consume() ); } catch( Exception e ) {}
name();
callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab );
try{ callback.elaboratedTypeSpecifierName( elab );} catch( Exception e ) {}
try{ callback.elaboratedTypeSpecifierEnd( elab );} catch( Exception e ) {}
}
break;
default:
@ -542,8 +605,11 @@ c, quick);
protected void identifier() throws Backtrack {
Token first = consume(Token.tIDENTIFIER); // throws backtrack if its not that
callback.nameBegin(first);
callback.nameEnd(first);
try
{
callback.nameBegin(first);
callback.nameEnd(first);
} catch( Exception e ) {}
}
/**
@ -561,7 +627,7 @@ c, quick);
Token first = LA(1);
Token last = null;
callback.nameBegin(first);
try{ callback.nameBegin(first); } catch( Exception e ) {}
if (LT(1) == Token.tCOLONCOLON)
last = consume();
@ -590,7 +656,7 @@ c, quick);
}
}
callback.nameEnd(last);
try{ callback.nameEnd(last);} catch( Exception e ) {}
}
@ -602,7 +668,7 @@ c, quick);
switch (LT(1)) {
case Token.t_const:
case Token.t_volatile:
callback.pointerOperatorCVModifier( ptrOp, consume() );
try{ callback.pointerOperatorCVModifier( ptrOp, consume() ); } catch( Exception e ) {}
return;
default:
throw backtrack;
@ -616,7 +682,7 @@ c, quick);
* To Do:
* - handle initializers
*/
protected void initDeclarator( Object owner ) throws Backtrack {
protected Object initDeclarator( Object owner ) throws Backtrack {
Object declarator = declarator( owner );
// handle = initializerClause
@ -627,14 +693,14 @@ c, quick);
Object expression = null;
try
{
expression = callback.expressionBegin( declarator );
try{ expression = callback.expressionBegin( declarator ); } catch( Exception e ) {}
assignmentExpression( expression );
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression );} catch( Exception e ) {}
}
catch( Backtrack b )
{
if( expression != null )
callback.expressionAbort( expression );
try{ callback.expressionAbort( expression );} catch( Exception e ) {}
}
if (LT(1) == Token.tLBRACE) {
@ -655,19 +721,19 @@ c, quick);
}
else if( LT(1) == Token.tLPAREN )
{
consume(); // EAT IT!
consume(Token.tLPAREN); // EAT IT!
Object expression = null;
try
{
expression = callback.expressionBegin( declarator );
try{ expression = callback.expressionBegin( declarator ); } catch( Exception e ) {}
constantExpression( expression );
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression ); } catch( Exception e ) {}
}
catch( Backtrack b )
{
if( expression != null )
callback.expressionAbort( expression );
try{ callback.expressionAbort( expression );} catch( Exception e ) {}
}
if( LT(1) == Token.tRPAREN )
@ -675,7 +741,8 @@ c, quick);
}
callback.declaratorEnd( declarator );
try{ callback.declaratorEnd( declarator );} catch( Exception e ) {}
return declarator;
}
/**
@ -696,7 +763,8 @@ c, quick);
do
{
Object declarator = callback.declaratorBegin( container );
Object declarator = null;
try{ declarator = callback.declaratorBegin( container );} catch( Exception e ) {}
for (;;) {
try {
@ -714,7 +782,7 @@ c, quick);
}
name();
callback.declaratorId(declarator);
try{ callback.declaratorId(declarator);} catch( Exception e ) {}
for (;;) {
switch (LT(1)) {
@ -723,7 +791,8 @@ c, quick);
if( LT(2) != Token.tINTEGER )
{
// parameterDeclarationClause
Object clause = callback.argumentsBegin(declarator);
Object clause = null;
try { clause = callback.argumentsBegin(declarator);} catch( Exception e ) {}
consume();
boolean seenParameter = false;
parameterDeclarationLoop:
@ -746,18 +815,24 @@ c, quick);
seenParameter = true;
}
}
callback.argumentsEnd(clause);
try{ callback.argumentsEnd(clause);} catch( Exception e ) {}
if( LT(1) == Token.tCOLON )
{
// this is most likely the definition of the constructor
return declarator;
}
// const-volatile marker on the method
if( LT(1) == Token.t_const || LT(1) == Token.t_volatile )
{
callback.declaratorCVModifier( declarator, consume() );
try{ callback.declaratorCVModifier( declarator, consume() );} catch( Exception e ) {}
}
//check for throws clause here
if( LT(1) == Token.t_throw )
{
callback.declaratorThrowsException( declarator );
try{ callback.declaratorThrowsException( declarator );} catch( Exception e ) {}
consume(); // throw
consume( Token.tLPAREN );// (
boolean done = false;
@ -772,7 +847,7 @@ c, quick);
case Token.tIDENTIFIER:
//TODO this is not exactly right - should be type-id rather than just a name
name();
callback.declaratorThrowExceptionName( declarator );
try{ callback.declaratorThrowExceptionName( declarator );} catch( Exception e ) {}
break;
case Token.tCOMMA:
consume();
@ -790,15 +865,17 @@ c, quick);
while( LT(1) == Token.tLBRACKET )
{
consume(); // eat the '['
Object array = callback.arrayDeclaratorBegin( declarator );
Object array = null;
try{ array = callback.arrayDeclaratorBegin( declarator ); } catch( Exception e ) {}
if( LT(1) != Token.tRBRACKET )
{
Object expression = callback.expressionBegin( array );
Object expression = null;
try{ expression = callback.expressionBegin( array );} catch( Exception e ) {}
constantExpression(expression);
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression ); } catch( Exception e ) {}
}
consume(Token.tRBRACKET);
callback.arrayDeclaratorEnd( array );
try{ callback.arrayDeclaratorEnd( array );} catch( Exception e ) {}
}
continue;
}
@ -807,11 +884,12 @@ c, quick);
if( LA(1).getType() == Token.tIDENTIFIER )
{
callback.declaratorAbort( container, declarator );
try{ callback.declaratorAbort( container, declarator ); } catch( Exception e ) {}
declarator = null;
}
else
return declarator;
} while( true );
}
@ -823,23 +901,29 @@ c, quick);
*/
protected void ptrOperator(Object owner) throws Backtrack {
int t = LT(1);
Object ptrOp = callback.pointerOperatorBegin( owner );
Object ptrOp = null;
try{ ptrOp = callback.pointerOperatorBegin( owner );} catch( Exception e ) {}
if (t == Token.tAMPER) {
callback.pointerOperatorType( ptrOp, consume() );
callback.pointerOperatorEnd( ptrOp );
try{ callback.pointerOperatorType( ptrOp, consume() ); } catch( Exception e ) {}
try{ callback.pointerOperatorEnd( ptrOp );} catch( Exception e ) {}
return;
}
Token mark = mark();
boolean hasName = false;
if (t == Token.tIDENTIFIER || t == Token.tCOLONCOLON)
{
name();
callback.pointerOperatorName( ptrOp );
hasName = true;
}
if (t == Token.tSTAR) {
callback.pointerOperatorType( ptrOp, consume());
if( hasName )
try{ callback.pointerOperatorName( ptrOp );} catch( Exception e ) {}
try{ callback.pointerOperatorType( ptrOp, consume());} catch( Exception e ) {}
for (;;) {
try {
@ -850,7 +934,7 @@ c, quick);
}
}
callback.pointerOperatorEnd( ptrOp );
try{ callback.pointerOperatorEnd( ptrOp );} catch( Exception e ) {}
return;
}
@ -874,12 +958,13 @@ c, quick);
{
consume( Token.t_enum );
Object enumSpecifier = callback.enumSpecifierBegin( owner );
Object enumSpecifier = null;
try{ enumSpecifier = callback.enumSpecifierBegin( owner );} catch( Exception e ) {}
if( LT(1) == Token.tIDENTIFIER )
{
identifier();
callback.enumSpecifierId( enumSpecifier );
try{ callback.enumSpecifierId( enumSpecifier );} catch( Exception e ) {}
}
if( LT(1) == Token.tLBRACE )
@ -891,39 +976,41 @@ c, quick);
Object defn;
if( LT(1) == Token.tIDENTIFIER )
{
defn = callback.enumDefinitionBegin( enumSpecifier );
defn = null;
try{ defn = callback.enumDefinitionBegin( enumSpecifier );} catch( Exception e ) {}
identifier();
callback.enumDefinitionId( defn );
try{ callback.enumDefinitionId( defn ); } catch( Exception e ) {}
}
else
{
callback.enumSpecifierAbort( enumSpecifier );
try{ callback.enumSpecifierAbort( enumSpecifier );} catch( Exception e ) {}
throw backtrack;
}
if( LT(1) == Token.tASSIGN )
{
consume( Token.tASSIGN );
Object expression = callback.expressionBegin( defn );
Object expression = null;
try{ expression = callback.expressionBegin( defn );} catch( Exception e ) {}
constantExpression( expression );
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression );} catch( Exception e ) {}
}
callback.enumDefinitionEnd( defn );
try{ callback.enumDefinitionEnd( defn );} catch( Exception e ) {}
if( LT(1) == Token.tRBRACE )
break;
if( LT(1) != Token.tCOMMA )
{
callback.enumSpecifierAbort( enumSpecifier );
try{ callback.enumSpecifierAbort( enumSpecifier );} catch( Exception e ) {}
throw backtrack;
}
consume(Token.tCOMMA); // if we made it this far
}
consume( Token.tRBRACE );
callback.enumSpecifierEnd( enumSpecifier );
try{ callback.enumSpecifierEnd( enumSpecifier );} catch( Exception e ) {}
}
else
{
@ -952,24 +1039,25 @@ c, quick);
throw backtrack;
}
Object classSpec = callback.classSpecifierBegin( owner, classKey);
Object classSpec = null;
try{ classSpec = callback.classSpecifierBegin( owner, classKey);} catch( Exception e ){}
// class name
if (LT(1) == Token.tIDENTIFIER) {
name();
callback.classSpecifierName(classSpec);
try{ callback.classSpecifierName(classSpec);} catch( Exception e ){}
}
if( LT(1) != Token.tCOLON && LT(1) != Token.tLBRACE )
{
// this is not a classSpecification
callback.classSpecifierAbort( classSpec );
try{ callback.classSpecifierAbort( classSpec );} catch( Exception e ){}
classSpec = null;
backup( mark );
throw backtrack;
}
else
callback.classSpecifierSafe( classSpec );
try{ callback.classSpecifierSafe( classSpec ); } catch( Exception e ){}
// base clause
if (LT(1) == Token.tCOLON) {
@ -989,7 +1077,7 @@ c, quick);
case Token.t_public:
case Token.t_protected:
case Token.t_private:
callback.classMemberVisibility( classSpec, consume() );
try{ callback.classMemberVisibility( classSpec, consume() );} catch( Exception e ){}
consume(Token.tCOLON);
break;
case Token.tRBRACE:
@ -1005,40 +1093,44 @@ c, quick);
consume();
}
callback.classSpecifierEnd(classSpec);
try{ callback.classSpecifierEnd(classSpec); } catch( Exception e ) {}
}
protected void baseSpecifier( Object classSpecOwner ) throws Backtrack {
Object baseSpecifier = callback.baseSpecifierBegin( classSpecOwner );
Object baseSpecifier = null;
try { baseSpecifier = callback.baseSpecifierBegin( classSpecOwner ); } catch( Exception e ) {}
baseSpecifierLoop:
for (;;) {
switch (LT(1)) {
case Token.t_virtual:
callback.baseSpecifierVirtual( baseSpecifier, true );
consume();
consume(Token.t_virtual);
try{ callback.baseSpecifierVirtual( baseSpecifier, true ); } catch( Exception e ){}
break;
case Token.t_public:
case Token.t_protected:
case Token.t_private:
callback.baseSpecifierVisibility( baseSpecifier, consume() );
try { callback.baseSpecifierVisibility( baseSpecifier, consume() );} catch( Exception e ){}
break;
case Token.tCOLONCOLON:
case Token.tIDENTIFIER:
name();
callback.baseSpecifierName( baseSpecifier );
try { callback.baseSpecifierName( baseSpecifier ); } catch( Exception e ){}
break;
case Token.tCOMMA:
callback.baseSpecifierEnd( baseSpecifier );
baseSpecifier = callback.baseSpecifierBegin( classSpecOwner );
try {
callback.baseSpecifierEnd( baseSpecifier );
baseSpecifier = callback.baseSpecifierBegin( classSpecOwner );
} catch( Exception e ){}
consume();
continue baseSpecifierLoop;
default:
break baseSpecifierLoop;
}
}
callback.baseSpecifierEnd( baseSpecifier );
try { callback.baseSpecifierEnd( baseSpecifier ); } catch( Exception e ){}
}
protected void functionBody() throws Backtrack {
@ -1051,9 +1143,10 @@ c, quick);
switch (LT(1)) {
case Token.t_case:
consume();
expression = callback.expressionBegin( null ); //TODO regarding this null
// TODO regarding this null
try{ expression = callback.expressionBegin( null ); } catch( Exception e ) {}
constantExpression(expression);
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression ); } catch( Exception e ) {}
consume(Token.tCOLON);
statement();
return;
@ -1107,9 +1200,10 @@ c, quick);
consume(Token.tSEMI);
if (LT(1) != Token.tRPAREN)
{
expression = callback.expressionBegin( null ); //TODO get rid of NULL
try{ expression = callback.expressionBegin( null ); } catch( Exception e ) {}
//TODO get rid of NULL
expression(expression);
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression );} catch( Exception e ) {}
}
consume(Token.tRPAREN);
statement();
@ -1126,9 +1220,10 @@ c, quick);
consume();
if (LT(1) != Token.tSEMI)
{
expression = callback.expressionBegin( null ); //TODO get rid of NULL
try{ expression = callback.expressionBegin( null );} catch( Exception e ) {}
//TODO get rid of NULL
expression(expression);
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression );} catch( Exception e ) {}
}
consume(Token.tSEMI);
return;
@ -1165,9 +1260,10 @@ c, quick);
// Note: the function style cast ambiguity is handled in expression
// Since it only happens when we are in a statement
try {
expression = callback.expressionBegin( null ); //TODO get rid of NULL
try{ expression = callback.expressionBegin( null ); } catch( Exception e ) {}
//TODO get rid of NULL
expression(expression);
callback.expressionEnd( expression );
try{ callback.expressionEnd( expression );} catch( Exception e ) {}
consume(Token.tSEMI);
return;
} catch (Backtrack b) {
@ -1204,7 +1300,7 @@ c, quick);
while (LT(1) == Token.tCOMMA) {
Token t = consume();
assignmentExpression( expression );
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
}
}
@ -1230,7 +1326,7 @@ c, quick);
case Token.tBITORASSIGN:
Token t = consume();
conditionalExpression(expression);
callback.expressionOperator(expression, t);
try { callback.expressionOperator(expression, t); } catch( Exception e ) {}
break;
}
}
@ -1264,7 +1360,7 @@ c, quick);
while (LT(1) == Token.tOR) {
Token t = consume();
logicalAndExpression( expression );
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
}
}
@ -1274,7 +1370,7 @@ c, quick);
while (LT(1) == Token.tAND) {
Token t = consume();
inclusiveOrExpression(expression );
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
}
}
@ -1284,7 +1380,7 @@ c, quick);
while (LT(1) == Token.tBITOR) {
Token t = consume();
exclusiveOrExpression(expression);
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
}
}
@ -1294,7 +1390,8 @@ c, quick);
while (LT(1) == Token.tXOR) {
Token t = consume();
andExpression(expression);
callback.expressionOperator(expression, t);
try { callback.expressionOperator(expression, t);} catch( Exception e ) {}
}
}
@ -1304,7 +1401,9 @@ c, quick);
while (LT(1) == Token.tAMPER) {
Token t = consume();
equalityExpression(expression);
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t); } catch( Exception e ) {}
}
}
@ -1317,7 +1416,7 @@ c, quick);
case Token.tNOTEQUAL:
Token t = consume();
relationalExpression(expression);
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
break;
default:
return;
@ -1339,7 +1438,7 @@ c, quick);
case Token.tGTEQUAL:
Token t = consume();
shiftExpression(expression);
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
break;
default:
return;
@ -1356,7 +1455,7 @@ c, quick);
case Token.tSHIFTR:
Token t = consume();
additiveExpression(expression);
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
break;
default:
return;
@ -1373,7 +1472,7 @@ c, quick);
case Token.tMINUS:
Token t = consume();
multiplicativeExpression(expression);
callback.expressionOperator(expression, t);
try { callback.expressionOperator(expression, t); } catch( Exception e ) {}
break;
default:
return;
@ -1391,7 +1490,7 @@ c, quick);
case Token.tMOD:
Token t = consume();
pmExpression(expression );
callback.expressionOperator(expression , t);
try{ callback.expressionOperator(expression , t);} catch( Exception e ) {}
break;
default:
return;
@ -1408,7 +1507,7 @@ c, quick);
case Token.tARROWSTAR:
Token t = consume();
castExpression( expression );
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
break;
default:
return;
@ -1489,7 +1588,7 @@ c, quick);
case Token.tDECR:
Token t = consume();
castExpression(expression);
callback.expressionOperator(expression, t);
try{ callback.expressionOperator(expression, t);} catch( Exception e ) {}
return;
case Token.t_sizeof:
if (LT(1) == Token.tLPAREN) {
@ -1595,13 +1694,13 @@ c, quick);
switch (type) {
// TO DO: we need more literals...
case Token.tINTEGER:
callback.expressionTerminal(expression, consume());
try{ callback.expressionTerminal(expression, consume());} catch( Exception e ) {}
return;
case Token.tSTRING:
callback.expressionTerminal(expression, consume());
try{ callback.expressionTerminal(expression, consume());} catch( Exception e ) {}
return;
case Token.tIDENTIFIER:
callback.expressionTerminal(expression, consume());
try{ callback.expressionTerminal(expression, consume());} catch( Exception e ) {}
return;
case Token.t_this:
consume();
@ -1732,24 +1831,4 @@ c, quick);
currToken = mark;
}
// Utility routines that require a knowledge of the grammar
protected static String generateName(Token startToken) throws ParserException {
Token currToken = startToken.getNext();
if (currToken == null || currToken.getType() != Token.tCOLONCOLON)
return startToken.getImage();
StringBuffer buff = new StringBuffer(startToken.getImage());
while (currToken != null && currToken.getType() == Token.tCOLONCOLON) {
currToken = currToken.getNext();
if (currToken == null || currToken.getType() != Token.tIDENTIFIER)
// Not good
throw new ParserException(startToken);
buff.append("::");
buff.append(currToken.getImage());
currToken = currToken.getNext();
}
return buff.toString();
}
}

View file

@ -762,7 +762,7 @@ public class ParserSymbolTable {
//HashSet.add returns false if wrapper.parent is already in the set
//this means we have circular inheritance
if( data.inheritanceChain.add( wrapper.parent ) ){
if( ! data.inheritanceChain.contains( wrapper.parent ) ){
//is this name define in this scope?
temp = LookupInContained( data, wrapper.parent );
@ -771,7 +771,7 @@ public class ParserSymbolTable {
temp = LookupInParents( data, wrapper.parent );
}
data.inheritanceChain.remove( wrapper.parent );
//data.inheritanceChain.remove( wrapper.parent );
} else {
throw new ParserSymbolTableException( ParserSymbolTableException.r_CircularInheritance );
@ -799,7 +799,7 @@ public class ParserSymbolTable {
temp = null; //reset temp for next iteration
}
}
data.inheritanceChain.remove( lookIn);
return decl;
}

View file

@ -0,0 +1,29 @@
/**********************************************************************
* Created on Mar 26, 2003
*
* 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.util;
/**
* @author jcamelon
*
*/
public class AccessSpecifier {
public static final int v_private = 0;
public static final int v_protected = 1;
public static final int v_public = 2;
private int access;
public void setAccess(int access) { this.access = access; }
public int getAccess() { return access; }
}

View file

@ -0,0 +1,44 @@
/**********************************************************************
* Created on Mar 26, 2003
*
* 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.util;
/**
* @author jcamelon
*
*/
public class ClassKey {
public static final int t_class = 0;
public static final int t_struct = 1;
public static final int t_union = 2;
public static final int t_enum = 3;
private int classKey = t_class;
/**
* @return int
*/
public int getClassKey() {
return classKey;
}
/**
* Sets the classKey.
* @param classKey The classKey to set
*/
public void setClassKey(int classKey) {
this.classKey = classKey;
}
}

View file

@ -1,3 +1,6 @@
2003-03-28 John Camelon
Added testConstructorChain() and testASMDefinition() to DOMTests.
2003-03-27 Alain Magloire
Changes were done in the Core Model API, the hierarchy is now

View file

@ -7,13 +7,18 @@ import java.util.List;
import junit.framework.TestCase;
import org.eclipse.cdt.internal.core.dom.ASMDefinition;
import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
import org.eclipse.cdt.internal.core.dom.BaseSpecifier;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
import org.eclipse.cdt.internal.core.dom.ConstructorChain;
import org.eclipse.cdt.internal.core.dom.ConstructorChainElement;
import org.eclipse.cdt.internal.core.dom.ConstructorChainElementExpression;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.Declarator;
import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
import org.eclipse.cdt.internal.core.dom.EnumeratorDefinition;
import org.eclipse.cdt.internal.core.dom.ExceptionSpecifier;
import org.eclipse.cdt.internal.core.dom.Expression;
import org.eclipse.cdt.internal.core.dom.LinkageSpecification;
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
@ -27,6 +32,7 @@ import org.eclipse.cdt.internal.core.dom.UsingDirective;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.core.parser.Token;
import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
import org.eclipse.cdt.internal.core.parser.util.Name;
@ -402,17 +408,17 @@ public class DOMTests extends TestCase {
List baseClasses = classSpecifier.getBaseSpecifiers();
assertEquals( 3, baseClasses.size() );
BaseSpecifier bs = (BaseSpecifier)baseClasses.get( 0 );
assertEquals( bs.getAccess(), BaseSpecifier.t_public );
assertEquals( bs.getAccess(), AccessSpecifier.v_public );
assertEquals( bs.isVirtual(), false );
assertEquals( bs.getName().toString(), "B" );
bs = (BaseSpecifier)baseClasses.get( 1 );
assertEquals( bs.getAccess(), BaseSpecifier.t_private );
assertEquals( bs.getAccess(), AccessSpecifier.v_private );
assertEquals( bs.isVirtual(), false );
assertEquals( bs.getName().toString(), "C" );
bs = (BaseSpecifier)baseClasses.get( 2 );
assertEquals( bs.getAccess(), BaseSpecifier.t_protected );
assertEquals( bs.getAccess(), AccessSpecifier.v_protected );
assertEquals( bs.isVirtual(), true );
assertEquals( bs.getName().toString(), "D" );
@ -585,13 +591,14 @@ public class DOMTests extends TestCase {
assertEquals( declarator.getName().toString(), "foo");
assertTrue( declarator.isConst() );
assertFalse( declarator.isVolatile() );
List exceptions = declarator.getExceptionSpecifier();
assertEquals( exceptions.size(), 3 );
Name n = (Name)exceptions.get(0);
ExceptionSpecifier exceptions = declarator.getExceptionSpecifier();
List typenames = exceptions.getTypeNames();
assertEquals( typenames.size(), 3 );
Name n = (Name)typenames.get(0);
assertEquals( n.toString(), "yay");
n = (Name)exceptions.get(1);
n = (Name)typenames.get(1);
assertEquals( n.toString(), "nay");
n = (Name)exceptions.get(2);
n = (Name)typenames.get(2);
assertEquals( n.toString(), "we::dont::care");
}
@ -687,6 +694,56 @@ public class DOMTests extends TestCase {
assertEquals( po5.getType(), PointerOperator.t_pointer );
}
public void testASMDefinition() throws Exception
{
TranslationUnit tu = parse( "asm( \"mov ep1 ds2\");" );
assertEquals( tu.getDeclarations().size(), 1 );
ASMDefinition asm = (ASMDefinition)tu.getDeclarations().get(0);
assertEquals( asm.getAssemblyCode(), "mov ep1 ds2" );
}
public void testConstructorChain() throws Exception
{
TranslationUnit tu = parse( "TrafficLight_Actor::TrafficLight_Actor( RTController * rtg_rts, RTActorRef * rtg_ref ) : RTActor( rtg_rts, rtg_ref ), myId( 0 ) {}" );
List tuDeclarations = tu.getDeclarations();
assertEquals( tuDeclarations.size(), 1 );
SimpleDeclaration decl1 = (SimpleDeclaration)tuDeclarations.get(0);
List declarators1 = decl1.getDeclarators();
assertEquals( declarators1.size(), 1 );
Declarator declarator1 = (Declarator)declarators1.get(0);
assertEquals( declarator1.getName().toString(), "TrafficLight_Actor::TrafficLight_Actor");
ConstructorChain chain1 = declarator1.getCtorChain();
List chainElements1 = chain1.getChainElements();
assertEquals( chainElements1.size(), 2 );
ConstructorChainElement element1_1 = (ConstructorChainElement) chainElements1.get(0);
assertEquals( element1_1.getName().toString(), "RTActor");
List expressions1_1 = element1_1.getExpressionList();
assertEquals( expressions1_1.size(), 2 );
ConstructorChainElementExpression expression1_1_1 = (ConstructorChainElementExpression)expressions1_1.get(0);
assertEquals( expression1_1_1.getExpression().tokens().size(), 1 );
Token t1_1_1 = (Token)expression1_1_1.getExpression().tokens().get(0);
ConstructorChainElementExpression expression1_1_2 = (ConstructorChainElementExpression)expressions1_1.get(1);
assertEquals( expression1_1_2.getExpression().tokens().size(), 1 );
Token t1_1_2 = (Token)expression1_1_2.getExpression().tokens().get(0);
assertEquals( t1_1_1.getType(), Token.tIDENTIFIER );
assertEquals( t1_1_1.getImage(), "rtg_rts");
assertEquals( t1_1_2.getType(), Token.tIDENTIFIER );
assertEquals( t1_1_2.getImage(), "rtg_ref");
ConstructorChainElement element1_2 = (ConstructorChainElement) chainElements1.get(1);
assertEquals( element1_2.getName().toString(), "myId" );
List expressions1_2 = element1_2.getExpressionList();
assertEquals( expressions1_2.size(), 1 );
ConstructorChainElementExpression expression = (ConstructorChainElementExpression) expressions1_2.get(0);
assertEquals( expression.getExpression().tokens().size(), 1 );
Token t = (Token)expression.getExpression().tokens().get(0);
assertEquals( t.getImage(), "0");
assertEquals( t.getType(), Token.tINTEGER );
}
// public void testErrors()
// {