mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Patch for John C:
- Core Changes - Updated Scanner to work for Strings literals like L"this string" - Updated Scanner to work for floating points literals. - Updated Scanner to be more forgiving on errors in QuickScan mode. - Got template instantiation and specialization working (w/callbacks and DOM). - Updated Parser/Callbacks for handle pure virtual function declarations. - Added callback support for some template declarations (nested not included). - Test Changes - Added testWeirdStrings() and testNumerics() to ScannerTestCase. - Added testTemplateSpecialization(), testTemplateDeclaration(), testBug26467(), testTypedef() and testTemplateInstantiation() to DOMTests.
This commit is contained in:
parent
5d314c3772
commit
daa99a3066
16 changed files with 1182 additions and 52 deletions
|
@ -723,4 +723,115 @@ public class DOMBuilder implements IParserCallback
|
|||
ConstructorChainElementExpression exp = (ConstructorChainElementExpression)expression;
|
||||
exp.getOwnerElement().addExpression( exp );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitInstantiationBegin(Object container) {
|
||||
IScope scope = (IScope)container;
|
||||
ExplicitTemplateDeclaration etd = new ExplicitTemplateDeclaration( ExplicitTemplateDeclaration.k_instantiation );
|
||||
scope.addDeclaration(etd);
|
||||
return etd;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitInstantiationEnd(Object instantiation) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitSpecializationBegin(Object container) {
|
||||
IScope scope = (IScope)container;
|
||||
ExplicitTemplateDeclaration etd = new ExplicitTemplateDeclaration( ExplicitTemplateDeclaration.k_specialization);
|
||||
scope.addDeclaration(etd);
|
||||
return etd;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitSpecializationEnd(Object instantiation) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object)
|
||||
*/
|
||||
public void declaratorPureVirtual(Object declarator) {
|
||||
Declarator d = (Declarator)declarator;
|
||||
d.setPureVirtual(true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean)
|
||||
*/
|
||||
public Object templateDeclarationBegin(Object container, boolean exported) {
|
||||
return new TemplateDeclaration( (IScope)container, exported );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationAbort(Object templateDecl) {
|
||||
templateDecl = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationEnd(Object templateDecl) {
|
||||
TemplateDeclaration decl = (TemplateDeclaration)templateDecl;
|
||||
decl.getOwnerScope().addDeclaration(decl);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token)
|
||||
*/
|
||||
public Object templateTypeParameterBegin(Object templDecl, Token kind) {
|
||||
TemplateParameter.ITemplateParameterList list = (TemplateParameter.ITemplateParameterList)templDecl;
|
||||
int k;
|
||||
switch( kind.getType() )
|
||||
{
|
||||
case Token.t_class:
|
||||
k = TemplateParameter.k_class;
|
||||
break;
|
||||
case Token.t_typename:
|
||||
k= TemplateParameter.k_typename;
|
||||
break;
|
||||
default:
|
||||
k = 0;
|
||||
}
|
||||
return new TemplateParameter( list, k );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterName(Object typeParm) {
|
||||
((TemplateParameter)typeParm).setName( currName );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterInitialTypeId(Object typeParm) {
|
||||
((TemplateParameter)typeParm).setTypeId( currName );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterEnd(Object typeParm) {
|
||||
TemplateParameter parm = ((TemplateParameter)typeParm);
|
||||
parm.getContainer().addTemplateParameter(parm);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterAbort(Object typeParm) {
|
||||
typeParm = null;
|
||||
}
|
||||
}
|
|
@ -104,7 +104,8 @@ public class Declarator implements IExpressionOwner {
|
|||
}
|
||||
|
||||
boolean isConst = false;
|
||||
boolean isVolatile = false;
|
||||
boolean isVolatile = false;
|
||||
boolean isPureVirtual = false;
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -164,4 +165,19 @@ public class Declarator implements IExpressionOwner {
|
|||
this.ctorChain = ctorChain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPureVirtual() {
|
||||
return isPureVirtual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the isPureVirtual.
|
||||
* @param isPureVirtual The isPureVirtual to set
|
||||
*/
|
||||
public void setPureVirtual(boolean isPureVirtual) {
|
||||
this.isPureVirtual = isPureVirtual;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/**********************************************************************
|
||||
* Created on Mar 29, 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 ExplicitTemplateDeclaration extends Declaration implements IScope {
|
||||
|
||||
private final int kind;
|
||||
|
||||
public final static int k_specialization = 1;
|
||||
public final static int k_instantiation = 2;
|
||||
|
||||
public ExplicitTemplateDeclaration( int kind )
|
||||
{
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
|
||||
private List declarations = new ArrayList();
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.IScope#addDeclaration(org.eclipse.cdt.internal.core.dom.Declaration)
|
||||
*/
|
||||
public void addDeclaration(Declaration declaration) {
|
||||
declarations.add( declaration );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.IScope#getDeclarations()
|
||||
*/
|
||||
public List getDeclarations() {
|
||||
return Collections.unmodifiableList( declarations );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public int getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**********************************************************************
|
||||
* Created on Mar 30, 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 TemplateDeclaration extends Declaration implements IScope, TemplateParameter.ITemplateParameterList {
|
||||
|
||||
private final boolean exported;
|
||||
private IScope ownerScope;
|
||||
private List declarations = new ArrayList();
|
||||
|
||||
public TemplateDeclaration( IScope ownerScope, boolean exported )
|
||||
{
|
||||
this.ownerScope = ownerScope;
|
||||
this.exported = exported;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.IScope#addDeclaration(org.eclipse.cdt.internal.core.dom.Declaration)
|
||||
*/
|
||||
public void addDeclaration(Declaration declaration) {
|
||||
declarations.add( declaration );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.IScope#getDeclarations()
|
||||
*/
|
||||
public List getDeclarations() {
|
||||
return Collections.unmodifiableList( declarations );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isExported() {
|
||||
return exported;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IScope
|
||||
*/
|
||||
public IScope getOwnerScope() {
|
||||
return ownerScope;
|
||||
}
|
||||
|
||||
|
||||
private List templateParameters = new ArrayList();
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.TemplateParameter.ITemplateParameterList#getTemplateParameters()
|
||||
*/
|
||||
public List getTemplateParameters() {
|
||||
return Collections.unmodifiableList(templateParameters);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.dom.TemplateParameter.ITemplateParameterList#addTemplateParameter(org.eclipse.cdt.internal.core.dom.TemplateParameter)
|
||||
*/
|
||||
public void addTemplateParameter(TemplateParameter parm) {
|
||||
templateParameters.add( parm );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/**********************************************************************
|
||||
* Created on Mar 30, 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.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.util.Name;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class TemplateParameter {
|
||||
|
||||
public interface ITemplateParameterList {
|
||||
public List getTemplateParameters();
|
||||
public void addTemplateParameter( TemplateParameter parm );
|
||||
}
|
||||
|
||||
private ITemplateParameterList container;
|
||||
private final int kind;
|
||||
|
||||
public final static int k_class = 2;
|
||||
public final static int k_typename = 3;
|
||||
|
||||
|
||||
public TemplateParameter( ITemplateParameterList container, int kind )
|
||||
{
|
||||
this.container = container;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
private Name name = null;
|
||||
private Name typeId = null;
|
||||
/**
|
||||
* @return ITemplateParameterList
|
||||
*/
|
||||
public ITemplateParameterList getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public int getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name
|
||||
*/
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name
|
||||
*/
|
||||
public Name getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
* @param name The name to set
|
||||
*/
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the typeId.
|
||||
* @param typeId The typeId to set
|
||||
*/
|
||||
public void setTypeId(Name typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,11 @@
|
|||
2003-03-31 John Camelon
|
||||
Updated Scanner to work for Strings literals like L"this string"
|
||||
Updated Scanner to work for floating points literals.
|
||||
Updated Scanner to be more forgiving on errors in QuickScan mode.
|
||||
Got template instantiation and specialization working (w/callbacks and DOM).
|
||||
Updated Parser/Callbacks for handle pure virtual function declarations.
|
||||
Added callback support for some template declarations (not all branches).
|
||||
|
||||
2003-03-28 John Camelon
|
||||
Added AccessSpecifier and ClassKind to parser.util package and refactored callbacks.
|
||||
Better encapsulated ExceptionSpecification in the DOM.
|
||||
|
|
|
@ -709,4 +709,108 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
|
|||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitInstantiationBegin(Object container) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitInstantiationEnd(Object instantiation) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitSpecializationBegin(Object container) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitSpecializationEnd(Object instantiation) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object)
|
||||
*/
|
||||
public void declaratorPureVirtual(Object declarator) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean)
|
||||
*/
|
||||
public Object templateDeclarationBegin(Object container, boolean exported) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationAbort(Object templateDecl) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationEnd(Object templateDecl) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token)
|
||||
*/
|
||||
public Object templateTypeParameterBegin(Object templDecl, Token kind) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterName(Object typeParm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterInitialTypeId(Object typeParm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterEnd(Object typeParm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterAbort(Object typeParm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -622,4 +622,86 @@ public class ExpressionEvaluator implements IParserCallback {
|
|||
public void constructorChainElementExpressionListElementEnd(Object expression) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitInstantiationBegin(Object container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitInstantiationEnd(Object instantiation) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitSpecializationBegin(Object container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitSpecializationEnd(Object instantiation) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object)
|
||||
*/
|
||||
public void declaratorPureVirtual(Object declarator) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean)
|
||||
*/
|
||||
public Object templateDeclarationBegin(Object container, boolean exported) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationAbort(Object templateDecl) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationEnd(Object templateDecl) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token)
|
||||
*/
|
||||
public Object templateTypeParameterBegin(Object templDecl, Token kind) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterName(Object typeParm) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterInitialTypeId(Object typeParm) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterEnd(Object typeParm) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterAbort(Object typeParm) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ public interface IParserCallback {
|
|||
|
||||
public Object declaratorBegin(Object container);
|
||||
public void declaratorId(Object declarator);
|
||||
public void declaratorAbort( Object container, Object declarator );
|
||||
public void declaratorAbort( Object container, Object declarator );
|
||||
public void declaratorPureVirtual( Object declarator );
|
||||
public void declaratorCVModifier( Object declarator, Token modifier );
|
||||
public void declaratorThrowsException( Object declarator );
|
||||
public void declaratorThrowExceptionName( Object declarator );
|
||||
|
@ -116,4 +117,20 @@ public interface IParserCallback {
|
|||
public Object constructorChainElementExpressionListElementBegin( Object element );
|
||||
public void constructorChainElementExpressionListElementEnd( Object expression );
|
||||
|
||||
public Object explicitInstantiationBegin( Object container);
|
||||
public void explicitInstantiationEnd( Object instantiation );
|
||||
|
||||
public Object explicitSpecializationBegin( Object container );
|
||||
public void explicitSpecializationEnd( Object instantiation );
|
||||
|
||||
public Object templateDeclarationBegin( Object container, boolean exported );
|
||||
public void templateDeclarationAbort( Object templateDecl );
|
||||
public void templateDeclarationEnd( Object templateDecl );
|
||||
|
||||
public Object templateTypeParameterBegin( Object templDecl, Token kind );
|
||||
public void templateTypeParameterName( Object typeParm );
|
||||
public void templateTypeParameterAbort( Object typeParm );
|
||||
public void templateTypeParameterInitialTypeId( Object typeParm );
|
||||
public void templateTypeParameterEnd( Object typeParm );
|
||||
|
||||
}
|
||||
|
|
|
@ -523,4 +523,86 @@ public class NullParserCallback implements IParserCallback {
|
|||
public void constructorChainElementExpressionListElementEnd(Object expression) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitInstantiationBegin(Object container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitInstantiationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitInstantiationEnd(Object instantiation) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationBegin(java.lang.Object)
|
||||
*/
|
||||
public Object explicitSpecializationBegin(Object container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#explicitSpecializationEnd(java.lang.Object)
|
||||
*/
|
||||
public void explicitSpecializationEnd(Object instantiation) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#declaratorPureVirtual(java.lang.Object)
|
||||
*/
|
||||
public void declaratorPureVirtual(Object declarator) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean)
|
||||
*/
|
||||
public Object templateDeclarationBegin(Object container, boolean exported) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationAbort(Object templateDecl) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateDeclarationEnd(Object templateDecl) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterBegin(java.lang.Object, org.eclipse.cdt.internal.core.parser.Token)
|
||||
*/
|
||||
public Object templateTypeParameterBegin(Object templDecl, Token kind) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterName(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterName(Object typeParm) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeInitialTypeId(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterInitialTypeId(Object typeParm) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterEnd(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterEnd(Object typeParm) {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateTypeParameterAbort(java.lang.Object)
|
||||
*/
|
||||
public void templateTypeParameterAbort(Object typeParm) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -248,6 +248,151 @@ c, quick);
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* template-declaration: export? template <template-parameter-list> declaration
|
||||
* explicit-instantiation: template declaration
|
||||
* explicit-specialization: template <> declaration
|
||||
*
|
||||
* template-parameter-list: template-parameter
|
||||
* template-parameter-list , template-parameter
|
||||
* template-parameter: type-parameter
|
||||
* parameter-declaration
|
||||
* type-parameter: class identifier?
|
||||
* class identifier? = type-id
|
||||
* typename identifier?
|
||||
* typename identifier? = type-id
|
||||
* template < template-parameter-list > class identifier?
|
||||
* template < template-parameter-list > class identifier? = id-expression
|
||||
* template-id: template-name < template-argument-list?>
|
||||
* template-name: identifier
|
||||
* template-argument-list: template-argument
|
||||
* template-argument-list , template-argument
|
||||
* template-argument: assignment-expression
|
||||
* type-id
|
||||
* id-expression
|
||||
*
|
||||
* @param container
|
||||
*/
|
||||
protected void templateDeclaration( Object container ) throws Backtrack
|
||||
{
|
||||
boolean export = false;
|
||||
if( LT(1) == Token.t_export )
|
||||
{
|
||||
consume( Token.t_export );
|
||||
export = true;
|
||||
}
|
||||
|
||||
consume( Token.t_template );
|
||||
if( LT(1) != Token.tLT )
|
||||
{
|
||||
// explicit-instantiation
|
||||
Object instantiation = null;
|
||||
try { instantiation = callback.explicitInstantiationBegin( container ); } catch( Exception e ) { }
|
||||
declaration( instantiation );
|
||||
try { callback.explicitInstantiationEnd( instantiation ); } catch( Exception e ) { }
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
consume( Token.tLT );
|
||||
if( LT(1) == Token.tGT )
|
||||
{
|
||||
consume( Token.tGT );
|
||||
// explicit-specialization
|
||||
Object specialization = null;
|
||||
try{ specialization = callback.explicitSpecializationBegin( container ); } catch( Exception e ) { }
|
||||
declaration( specialization );
|
||||
try{ callback.explicitSpecializationEnd( specialization ); } catch( Exception e ) { }
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Object templateDeclaration = null;
|
||||
try
|
||||
{
|
||||
try{ templateDeclaration = callback.templateDeclarationBegin( container, export ); } catch ( Exception e ) {}
|
||||
templateParameterList( templateDeclaration );
|
||||
consume( Token.tGT );
|
||||
declaration( templateDeclaration );
|
||||
try{ callback.templateDeclarationEnd( templateDeclaration ); } catch( Exception e ) {}
|
||||
|
||||
} catch( Backtrack bt )
|
||||
{
|
||||
try { callback.templateDeclarationAbort( templateDeclaration ); } catch( Exception e ) {}
|
||||
}
|
||||
}
|
||||
|
||||
protected void templateParameterList( Object templateDeclaration ) throws EndOfFile, Backtrack {
|
||||
// if we have gotten this far then we have a true template-declaration
|
||||
// iterate through the template parameter list
|
||||
for ( ; ; )
|
||||
{
|
||||
if( LT(1) == Token.tGT ) return;
|
||||
Object currentTemplateParm = null;
|
||||
if( LT(1) == Token.t_class || LT(1) == Token.t_typename )
|
||||
{
|
||||
try
|
||||
{
|
||||
try{
|
||||
currentTemplateParm = callback.templateTypeParameterBegin(
|
||||
templateDeclaration, consume() );
|
||||
} catch( Exception e ) {}
|
||||
if( LT(1) == Token.tIDENTIFIER ) // optional identifier
|
||||
{
|
||||
identifier();
|
||||
try { callback.templateTypeParameterName( currentTemplateParm );} catch( Exception e ) {}
|
||||
if( LT(1) == Token.tASSIGN ) // optional = type-id
|
||||
{
|
||||
consume( Token.tASSIGN );
|
||||
identifier(); // type-id
|
||||
try{ callback.templateTypeParameterInitialTypeId( currentTemplateParm ); }catch( Exception e ) {}
|
||||
}
|
||||
}
|
||||
try{ callback.templateTypeParameterEnd( currentTemplateParm ); } catch( Exception e ) {}
|
||||
|
||||
} catch( Backtrack bt )
|
||||
{
|
||||
try{ callback.templateTypeParameterAbort( currentTemplateParm ); }catch( Exception e ) {}
|
||||
throw bt;
|
||||
}
|
||||
}
|
||||
else if( LT(1) == Token.t_template )
|
||||
{
|
||||
try
|
||||
{
|
||||
consume( Token.t_template );
|
||||
consume( Token.tLT );
|
||||
Object newTemplateDeclaration = null;
|
||||
templateParameterList( newTemplateDeclaration );
|
||||
consume( Token.tGT );
|
||||
consume( Token.t_class );
|
||||
if( LT(1) == Token.tIDENTIFIER ) // optional identifier
|
||||
{
|
||||
identifier();
|
||||
if( LT(1) == Token.tASSIGN ) // optional = type-id
|
||||
{
|
||||
consume( Token.tASSIGN );
|
||||
// id-expression()
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( Backtrack bt )
|
||||
{
|
||||
}
|
||||
}
|
||||
else if( LT(1) == Token.tCOMMA )
|
||||
{
|
||||
consume( Token.tCOMMA );
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
parameterDeclaration( templateDeclaration );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* declaration
|
||||
* : {"asm"} asmDefinition
|
||||
|
@ -286,8 +431,7 @@ c, quick);
|
|||
return;
|
||||
case Token.t_export:
|
||||
case Token.t_template:
|
||||
// templateDeclaration();
|
||||
consume();
|
||||
templateDeclaration( container );
|
||||
return;
|
||||
case Token.t_extern:
|
||||
if( LT(2) == Token.tSTRING )
|
||||
|
@ -575,9 +719,10 @@ c, quick);
|
|||
// this is an elaborated class specifier
|
||||
Object elab = null;
|
||||
try{ elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );} catch( Exception e ) {}
|
||||
name();
|
||||
className();
|
||||
try{ callback.elaboratedTypeSpecifierName( elab ); } catch( Exception e ) {}
|
||||
try{ callback.elaboratedTypeSpecifierEnd( elab );} catch( Exception e ) {}
|
||||
encounteredTypename = true;
|
||||
break;
|
||||
}
|
||||
case Token.t_enum:
|
||||
|
@ -612,6 +757,52 @@ c, quick);
|
|||
} catch( Exception e ) {}
|
||||
}
|
||||
|
||||
|
||||
/* class-name: identifier | template-id
|
||||
* template-id: template-name < template-argument-list opt >
|
||||
* template-name : identifier
|
||||
*/
|
||||
protected void className() throws Backtrack
|
||||
{
|
||||
Token first = LA(1);
|
||||
if( LT(1) == Token.tIDENTIFIER)
|
||||
{
|
||||
if( LT(2) == Token.tLT )
|
||||
{
|
||||
consume( Token.tIDENTIFIER );
|
||||
consume( Token.tLT );
|
||||
|
||||
// until we get all the names sorted out
|
||||
int depth = 1;
|
||||
Token last = null;
|
||||
|
||||
while (depth > 0) {
|
||||
last = consume();
|
||||
switch ( last.getType()) {
|
||||
case Token.tGT:
|
||||
--depth;
|
||||
break;
|
||||
case Token.tLT:
|
||||
++depth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
callback.nameBegin( first );
|
||||
callback.nameEnd( last );
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
identifier();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw backtrack;
|
||||
}
|
||||
|
||||
/**
|
||||
* name
|
||||
* : ("::")? name2 ("::" name2)*
|
||||
|
@ -822,7 +1013,7 @@ c, quick);
|
|||
// 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 )
|
||||
{
|
||||
|
@ -859,6 +1050,15 @@ c, quick);
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for optional pure virtual
|
||||
if( LT(1) == Token.tASSIGN && LT(2) == Token.tINTEGER && LA(2).getImage().equals( "0") )
|
||||
{
|
||||
consume( Token.tASSIGN);
|
||||
consume( Token.tINTEGER);
|
||||
try{ callback.declaratorPureVirtual( declarator ); } catch( Exception e ) { }
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case Token.tLBRACKET:
|
||||
|
@ -1044,7 +1244,7 @@ c, quick);
|
|||
|
||||
// class name
|
||||
if (LT(1) == Token.tIDENTIFIER) {
|
||||
name();
|
||||
className();
|
||||
try{ callback.classSpecifierName(classSpec);} catch( Exception e ){}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,6 @@ import java.util.Vector;
|
|||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* 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 Scanner implements IScanner {
|
||||
|
@ -345,9 +341,6 @@ public class Scanner implements IScanner {
|
|||
// these are scanner configuration aspects that we perhaps want to tweak
|
||||
// eventually, these should be configurable by the client, but for now
|
||||
// we can just leave it internal
|
||||
private boolean throwExceptionPPError = true;
|
||||
private boolean throwExceptionOnRedefinition = false;
|
||||
private boolean throwExceptionOnBadUndefinition = false;
|
||||
private boolean throwExceptionOnBadPreprocessorSyntax = true;
|
||||
private boolean throwExceptionOnInclusionNotFound = true;
|
||||
private boolean throwExceptionOnBadMacroExpansion = true;
|
||||
|
@ -450,7 +443,7 @@ public class Scanner implements IScanner {
|
|||
{
|
||||
|
||||
count++;
|
||||
|
||||
boolean madeMistake = false;
|
||||
int c = getChar();
|
||||
|
||||
while (c != NOCHAR) {
|
||||
|
@ -463,14 +456,59 @@ public class Scanner implements IScanner {
|
|||
if ((c == ' ') || (c == '\r') || (c == '\t') || (c == '\n')) {
|
||||
c = getChar();
|
||||
continue;
|
||||
} else if (c == '"' || ( c == 'L' && ! madeMistake ) ) {
|
||||
|
||||
boolean wideString = false;
|
||||
if( c == 'L' )
|
||||
{
|
||||
int oldChar =c;
|
||||
wideString = true;
|
||||
c = getChar();
|
||||
if( c != '"' )
|
||||
{
|
||||
// we have made a mistake
|
||||
ungetChar( c );
|
||||
c = oldChar;
|
||||
madeMistake = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// string
|
||||
StringBuffer buff = new StringBuffer();
|
||||
c = getChar();
|
||||
|
||||
while (c != '"' && c != '\n') {
|
||||
buff.append((char) c);
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
if (c != '\n')
|
||||
{
|
||||
int type = wideString ? Token.tLSTRING : Token.tSTRING;
|
||||
return newToken(
|
||||
type,
|
||||
buff.toString(),
|
||||
currentContext);
|
||||
|
||||
} else {
|
||||
if (throwExceptionOnUnboundedString)
|
||||
throw new ScannerException(
|
||||
"Unbounded string found at offset "
|
||||
+ currentContext.getOffset());
|
||||
}
|
||||
|
||||
} else if (
|
||||
((c >= 'a') && (c <= 'z'))
|
||||
|| ((c >= 'A') && (c <= 'Z')) | (c == '_')) {
|
||||
|
||||
if( madeMistake ) madeMistake = false;
|
||||
// String buffer is slow, we need a better way such as memory mapped files
|
||||
StringBuffer buff = new StringBuffer();
|
||||
StringBuffer buff = new StringBuffer();
|
||||
buff.append((char) c);
|
||||
|
||||
c = getChar();
|
||||
c = getChar();
|
||||
|
||||
while (((c >= 'a') && (c <= 'z'))
|
||||
|| ((c >= 'A') && (c <= 'Z'))
|
||||
|| ((c >= '0') && (c <= '9'))
|
||||
|
@ -525,29 +563,7 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
|
||||
return newToken(tokenType, ident, currentContext);
|
||||
} else if (c == '"') {
|
||||
// string
|
||||
StringBuffer buff = new StringBuffer();
|
||||
c = getChar();
|
||||
|
||||
while (c != '"' && c != '\n') {
|
||||
buff.append((char) c);
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
if (c != '\n') {
|
||||
return newToken(
|
||||
Token.tSTRING,
|
||||
buff.toString(),
|
||||
currentContext);
|
||||
} else {
|
||||
if (throwExceptionOnUnboundedString)
|
||||
throw new ScannerException(
|
||||
"Unbounded string found at offset "
|
||||
+ currentContext.getOffset());
|
||||
}
|
||||
|
||||
} else if ((c >= '0') && (c <= '9')) {
|
||||
} else if ((c >= '0') && (c <= '9') || c == '.' ) {
|
||||
StringBuffer buff;
|
||||
|
||||
if( pasting )
|
||||
|
@ -559,12 +575,20 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
else
|
||||
buff = new StringBuffer();
|
||||
|
||||
|
||||
boolean hex = false;
|
||||
boolean floatingPoint = ( c == '.' ) ? true : false;
|
||||
boolean firstCharZero = ( c== '0' )? true : false;
|
||||
|
||||
buff.append((char) c);
|
||||
|
||||
c = getChar();
|
||||
boolean hex = false;
|
||||
|
||||
if (c == 'x') {
|
||||
if( ! firstCharZero )
|
||||
throw new ScannerException( "Invalid Hexidecimal @ offset " + currentContext.getOffset() );
|
||||
|
||||
hex = true;
|
||||
c = getChar();
|
||||
}
|
||||
|
@ -575,8 +599,53 @@ public class Scanner implements IScanner {
|
|||
buff.append((char) c);
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
if( c == '.' )
|
||||
{
|
||||
buff.append( (char)c);
|
||||
if( floatingPoint || hex ) throw new ScannerException( "Invalid floating point @ offset " + currentContext.getOffset() );
|
||||
floatingPoint = true;
|
||||
c= getChar();
|
||||
while ((c >= '0' && c <= '9') )
|
||||
{
|
||||
buff.append((char) c);
|
||||
c = getChar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ungetChar(c);
|
||||
if( c == 'e' || c == 'E' )
|
||||
{
|
||||
if( ! floatingPoint ) floatingPoint = true;
|
||||
// exponent type for flaoting point
|
||||
buff.append((char)c);
|
||||
c = getChar();
|
||||
|
||||
// optional + or -
|
||||
if( c == '+' || c == '-' )
|
||||
{
|
||||
buff.append( (char)c );
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
// digit sequence of exponent part
|
||||
while ((c >= '0' && c <= '9') )
|
||||
{
|
||||
buff.append((char) c);
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
// optional suffix
|
||||
if( c == 'l' || c == 'L' || c == 'f' || c == 'F' )
|
||||
{
|
||||
buff.append( (char)c );
|
||||
c = getChar();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
ungetChar( c );
|
||||
|
||||
if( pasting )
|
||||
{
|
||||
|
@ -598,8 +667,10 @@ public class Scanner implements IScanner {
|
|||
}
|
||||
}
|
||||
|
||||
int tokenType = floatingPoint ? Token.tFLOATINGPT : Token.tINTEGER;
|
||||
|
||||
return newToken(
|
||||
Token.tINTEGER,
|
||||
tokenType,
|
||||
buff.toString(),
|
||||
currentContext);
|
||||
|
||||
|
@ -672,7 +743,7 @@ public class Scanner implements IScanner {
|
|||
// definition
|
||||
String toBeUndefined = getNextIdentifier();
|
||||
|
||||
if( ( definitions.remove(toBeUndefined) == null ) && throwExceptionOnBadUndefinition )
|
||||
if( ( definitions.remove(toBeUndefined) == null ) && ! quickScan )
|
||||
throw new ScannerException( "Attempt to #undef symbol " + toBeUndefined + " when it was never defined");
|
||||
|
||||
skipOverTextUntilNewline();
|
||||
|
@ -764,7 +835,7 @@ public class Scanner implements IScanner {
|
|||
|
||||
String error = getRestOfPreprocessorLine();
|
||||
|
||||
if (throwExceptionPPError) {
|
||||
if (!quickScan) {
|
||||
throw new ScannerException("#error " + error);
|
||||
}
|
||||
c = getChar();
|
||||
|
@ -1385,7 +1456,7 @@ public class Scanner implements IScanner {
|
|||
String key = getNextIdentifier();
|
||||
int offset = currentContext.getOffset() - key.length() - currentContext.undoStackSize();
|
||||
|
||||
if (throwExceptionOnRedefinition) {
|
||||
if (!quickScan) {
|
||||
String checkForRedefinition = (String) definitions.get(key);
|
||||
if (checkForRedefinition != null) {
|
||||
throw new ScannerException(
|
||||
|
|
|
@ -173,6 +173,8 @@ public class Token {
|
|||
static public final int t_xor = 127;
|
||||
static public final int t_xor_eq = 128;
|
||||
static public final int tSTRING = 129;
|
||||
static public final int tFLOATINGPT = 130;
|
||||
static public final int tLSTRING = 131;
|
||||
|
||||
static public final int tLAST = tSTRING;
|
||||
static public final int tLAST = tLSTRING;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
2003-03-31 John Camelon
|
||||
Added testWeirdStrings() and testNumerics() to ScannerTestCase.
|
||||
Added testTemplateSpecialization(), testTemplateDeclaration(), testBug26467(),
|
||||
testTypedef() and testTemplateInstantiation() to DOMTests.
|
||||
|
||||
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
|
||||
ICModel
|
||||
ICProject
|
||||
|
|
|
@ -16,9 +16,11 @@ 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.ElaboratedTypeSpecifier;
|
||||
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.ExplicitTemplateDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.Expression;
|
||||
import org.eclipse.cdt.internal.core.dom.LinkageSpecification;
|
||||
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
|
||||
|
@ -26,6 +28,8 @@ import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
|
|||
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
|
||||
import org.eclipse.cdt.internal.core.dom.PointerOperator;
|
||||
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.TemplateParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.UsingDeclaration;
|
||||
import org.eclipse.cdt.internal.core.dom.UsingDirective;
|
||||
|
@ -33,6 +37,7 @@ 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.ClassKey;
|
||||
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
|
||||
import org.eclipse.cdt.internal.core.parser.util.Name;
|
||||
|
||||
|
@ -115,6 +120,41 @@ public class DOMTests extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testTemplateSpecialization() throws Exception
|
||||
{
|
||||
TranslationUnit tu = parse( "template<> class stream<char> { /* ... */ };");
|
||||
assertEquals( tu.getDeclarations().size(), 1 );
|
||||
ExplicitTemplateDeclaration explicit = (ExplicitTemplateDeclaration)tu.getDeclarations().get( 0 );
|
||||
assertNotNull( explicit );
|
||||
assertEquals( explicit.getKind(), ExplicitTemplateDeclaration.k_specialization );
|
||||
assertEquals( explicit.getDeclarations().size(), 1 );
|
||||
SimpleDeclaration declaration = (SimpleDeclaration)explicit.getDeclarations().get(0);
|
||||
assertNotNull( declaration );
|
||||
ClassSpecifier classSpec = (ClassSpecifier)declaration.getTypeSpecifier();
|
||||
assertNotNull( classSpec );
|
||||
assertEquals( classSpec.getClassKey(), ClassKey.t_class );
|
||||
assertEquals( classSpec.getName().toString(), "stream<char>" );
|
||||
assertEquals( declaration.getDeclarators().size(), 0 );
|
||||
assertEquals( classSpec.getDeclarations().size(), 0 );
|
||||
|
||||
}
|
||||
|
||||
public void testTemplateInstantiation() throws Exception
|
||||
{
|
||||
TranslationUnit tu = parse( "template class Array<char>;");
|
||||
assertEquals( tu.getDeclarations().size(), 1 );
|
||||
ExplicitTemplateDeclaration explicit = (ExplicitTemplateDeclaration)tu.getDeclarations().get( 0 );
|
||||
assertNotNull( explicit );
|
||||
assertEquals( explicit.getKind(), ExplicitTemplateDeclaration.k_instantiation );
|
||||
assertEquals( explicit.getDeclarations().size(), 1 );
|
||||
SimpleDeclaration declaration = (SimpleDeclaration)explicit.getDeclarations().get(0);
|
||||
assertNotNull( declaration );
|
||||
ElaboratedTypeSpecifier classSpec = (ElaboratedTypeSpecifier)declaration.getTypeSpecifier();
|
||||
assertNotNull( classSpec );
|
||||
assertEquals( classSpec.getClassKey(), ClassKey.t_class );
|
||||
assertEquals( classSpec.getName().toString(), "Array<char>");
|
||||
}
|
||||
|
||||
public void testEnumSpecifier() throws Exception
|
||||
{
|
||||
Writer code = new StringWriter();
|
||||
|
@ -145,6 +185,28 @@ public class DOMTests extends TestCase {
|
|||
EnumerationSpecifier enumSpecifier2 = (EnumerationSpecifier)declaration2.getTypeSpecifier();
|
||||
assertEquals( enumSpecifier2.getName().toString(), "hasAName" );
|
||||
|
||||
}
|
||||
|
||||
public void testTypedef() throws Exception
|
||||
{
|
||||
TranslationUnit tu = parse( "typedef const struct A * const cpStructA;");
|
||||
assertEquals( tu.getDeclarations().size(), 1 );
|
||||
SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0);
|
||||
assertTrue( declaration.getDeclSpecifier().isTypedef() );
|
||||
assertTrue( declaration.getDeclSpecifier().isConst() );
|
||||
ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier) declaration.getTypeSpecifier();
|
||||
assertEquals( elab.getClassKey(), ClassKey.t_struct );
|
||||
assertEquals( elab.getName().toString(), "A" );
|
||||
List declarators = declaration.getDeclarators();
|
||||
assertEquals( declarators.size(), 1 );
|
||||
Declarator declarator = (Declarator)declarators.get(0);
|
||||
assertEquals( declarator.getName().toString(), "cpStructA");
|
||||
assertEquals( declarator.getPointerOperators().size(), 1 );
|
||||
PointerOperator po = (PointerOperator)declarator.getPointerOperators().get(0);
|
||||
assertEquals( po.getType(), PointerOperator.t_pointer);
|
||||
assertTrue( po.isConst() );
|
||||
assertFalse( po.isVolatile());
|
||||
|
||||
}
|
||||
public void testUsingClauses() throws Exception
|
||||
{
|
||||
|
@ -580,12 +642,13 @@ public class DOMTests extends TestCase {
|
|||
public void testFunctionModifiers() throws Exception
|
||||
{
|
||||
Writer code = new StringWriter();
|
||||
code.write( "void foo( void ) const throw ( yay, nay, we::dont::care );");
|
||||
code.write( "virtual void foo( void ) const throw ( yay, nay, we::dont::care ) = 0;");
|
||||
TranslationUnit translationUnit = parse( code.toString() );
|
||||
List tudeclarations = translationUnit.getDeclarations();
|
||||
assertEquals( 1, tudeclarations.size() );
|
||||
SimpleDeclaration decl1 = (SimpleDeclaration)tudeclarations.get(0);
|
||||
assertEquals( decl1.getDeclSpecifier().getType(), DeclSpecifier.t_void);
|
||||
assertTrue( decl1.getDeclSpecifier().isVirtual() );
|
||||
assertEquals( decl1.getDeclarators().size(), 1 );
|
||||
Declarator declarator = (Declarator)decl1.getDeclarators().get(0);
|
||||
assertEquals( declarator.getName().toString(), "foo");
|
||||
|
@ -600,6 +663,7 @@ public class DOMTests extends TestCase {
|
|||
assertEquals( n.toString(), "nay");
|
||||
n = (Name)typenames.get(2);
|
||||
assertEquals( n.toString(), "we::dont::care");
|
||||
assertTrue( declarator.isPureVirtual() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -694,6 +758,60 @@ public class DOMTests extends TestCase {
|
|||
assertEquals( po5.getType(), PointerOperator.t_pointer );
|
||||
}
|
||||
|
||||
public void testBug26467() throws Exception
|
||||
{
|
||||
StringWriter code = new StringWriter();
|
||||
code.write( "struct foo { int fooInt; char fooChar; };\n" );
|
||||
code.write( "typedef struct foo fooStruct;\n" );
|
||||
code.write( "typedef struct { int anonInt; char anonChar; } anonStruct;\n" );
|
||||
|
||||
TranslationUnit tu = parse( code.toString() );
|
||||
List tuDeclarations = tu.getDeclarations();
|
||||
assertEquals( tuDeclarations.size(), 3 );
|
||||
|
||||
SimpleDeclaration declaration = (SimpleDeclaration)tuDeclarations.get(0);
|
||||
ClassSpecifier classSpec = (ClassSpecifier)declaration.getTypeSpecifier();
|
||||
assertEquals( declaration.getDeclarators().size(), 0 );
|
||||
assertEquals( classSpec.getClassKey(), ClassKey.t_struct);
|
||||
assertEquals( classSpec.getName().toString(), "foo");
|
||||
List subDeclarations = classSpec.getDeclarations();
|
||||
assertEquals( subDeclarations.size(), 2 );
|
||||
SimpleDeclaration subDeclaration = (SimpleDeclaration)subDeclarations.get(0);
|
||||
assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_int);
|
||||
assertEquals( subDeclaration.getDeclarators().size(), 1 );
|
||||
assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "fooInt" );
|
||||
subDeclaration = (SimpleDeclaration)subDeclarations.get(1);
|
||||
assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_char);
|
||||
assertEquals( subDeclaration.getDeclarators().size(), 1 );
|
||||
assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "fooChar" );
|
||||
|
||||
declaration = (SimpleDeclaration)tuDeclarations.get(1);
|
||||
assertEquals( declaration.getDeclSpecifier().isTypedef(), true );
|
||||
ElaboratedTypeSpecifier elab = (ElaboratedTypeSpecifier)declaration.getTypeSpecifier();
|
||||
assertEquals( elab.getClassKey(), ClassKey.t_struct);
|
||||
assertEquals( elab.getName().toString(), "foo" );
|
||||
assertEquals( declaration.getDeclarators().size(), 1 );
|
||||
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getName().toString(), "fooStruct" );
|
||||
|
||||
declaration = (SimpleDeclaration)tuDeclarations.get(2);
|
||||
assertEquals( declaration.getDeclSpecifier().isTypedef(), true );
|
||||
classSpec = (ClassSpecifier) declaration.getTypeSpecifier();
|
||||
assertEquals( classSpec.getClassKey(), ClassKey.t_struct );
|
||||
assertNull( classSpec.getName() );
|
||||
subDeclarations = classSpec.getDeclarations();
|
||||
assertEquals( subDeclarations.size(), 2 );
|
||||
subDeclaration = (SimpleDeclaration)subDeclarations.get(0);
|
||||
assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_int);
|
||||
assertEquals( subDeclaration.getDeclarators().size(), 1 );
|
||||
assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "anonInt" );
|
||||
subDeclaration = (SimpleDeclaration)subDeclarations.get(1);
|
||||
assertEquals( subDeclaration.getDeclSpecifier().getType(), DeclSpecifier.t_char);
|
||||
assertEquals( subDeclaration.getDeclarators().size(), 1 );
|
||||
assertEquals( ((Declarator)subDeclaration.getDeclarators().get(0)).getName().toString(), "anonChar" );
|
||||
assertEquals( declaration.getDeclarators().size(), 1 );
|
||||
assertEquals( ((Declarator)declaration.getDeclarators().get(0)).getName().toString(), "anonStruct" );
|
||||
}
|
||||
|
||||
public void testASMDefinition() throws Exception
|
||||
{
|
||||
TranslationUnit tu = parse( "asm( \"mov ep1 ds2\");" );
|
||||
|
@ -773,5 +891,34 @@ public class DOMTests extends TestCase {
|
|||
fail( "IOException thrown");
|
||||
}
|
||||
}
|
||||
|
||||
public void testTemplateDeclaration() throws Exception {
|
||||
TranslationUnit tu = parse( "template<class T, typename Tibor = junk, class, typename> class myarray { /* ... */ };");
|
||||
assertEquals( tu.getDeclarations().size(), 1 );
|
||||
TemplateDeclaration declaration = (TemplateDeclaration)tu.getDeclarations().get(0);
|
||||
assertEquals( declaration.getTemplateParameters().size(), 4 );
|
||||
TemplateParameter parameter = (TemplateParameter)declaration.getTemplateParameters().get(0);
|
||||
assertEquals( parameter.getKind(), TemplateParameter.k_class);
|
||||
assertEquals( parameter.getName().toString(), "T" );
|
||||
assertNull( parameter.getTypeId());
|
||||
parameter = (TemplateParameter)declaration.getTemplateParameters().get(1);
|
||||
assertEquals( parameter.getKind(), TemplateParameter.k_typename);
|
||||
assertEquals( parameter.getName().toString(), "Tibor" );
|
||||
assertEquals( parameter.getTypeId().toString(), "junk");
|
||||
parameter = (TemplateParameter)declaration.getTemplateParameters().get(2);
|
||||
assertEquals( parameter.getKind(), TemplateParameter.k_class);
|
||||
assertNull( parameter.getName() );
|
||||
assertNull( parameter.getTypeId());
|
||||
parameter = (TemplateParameter)declaration.getTemplateParameters().get(3);
|
||||
assertEquals( parameter.getKind(), TemplateParameter.k_typename);
|
||||
assertNull( parameter.getName() );
|
||||
assertNull( parameter.getTypeId());
|
||||
assertEquals( declaration.getDeclarations().size(), 1 );
|
||||
SimpleDeclaration myArray = (SimpleDeclaration)declaration.getDeclarations().get(0);
|
||||
ClassSpecifier classSpec = (ClassSpecifier)myArray.getTypeSpecifier();
|
||||
assertEquals( classSpec.getClassKey(), ClassKey.t_class );
|
||||
assertEquals( classSpec.getName().toString(), "myarray");
|
||||
assertEquals( 0, classSpec.getDeclarations().size() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -197,6 +197,45 @@ public class ScannerTestCase extends TestCase
|
|||
return scanner.getCount();
|
||||
}
|
||||
|
||||
public void testWeirdStrings()
|
||||
{
|
||||
try
|
||||
{
|
||||
initializeScanner( "Living Life L\"LONG\"");
|
||||
validateIdentifier( "Living" );
|
||||
validateIdentifier( "Life" );
|
||||
validateString("LONG", true);
|
||||
validateEOF();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail(EXCEPTION_THROWN + se.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testNumerics()
|
||||
{
|
||||
try
|
||||
{
|
||||
initializeScanner("3.0 0.9 .5 3. 4E5 2.01E-03");
|
||||
validateFloatingPointLiteral( "3.0");
|
||||
validateFloatingPointLiteral( "0.9");
|
||||
validateFloatingPointLiteral( ".5");
|
||||
validateFloatingPointLiteral( "3.");
|
||||
validateFloatingPointLiteral( "4E5");
|
||||
validateFloatingPointLiteral( "2.01E-03" );
|
||||
validateEOF();
|
||||
}
|
||||
catch( ScannerException se )
|
||||
{
|
||||
fail(EXCEPTION_THROWN + se.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Scanner scanner;
|
||||
|
||||
/**
|
||||
|
@ -993,12 +1032,32 @@ public class ScannerTestCase extends TestCase
|
|||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateString(String expectedImage) throws ScannerException
|
||||
|
||||
public void validateFloatingPointLiteral(String expectedImage) throws ScannerException
|
||||
{
|
||||
try {
|
||||
Token t= scanner.nextToken();
|
||||
assertTrue(t.type == Token.tSTRING);
|
||||
assertTrue(t.type == Token.tFLOATINGPT);
|
||||
assertTrue(t.image.equals(expectedImage));
|
||||
} catch (Parser.EndOfFile e) {
|
||||
assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void validateString( String expectedImage ) throws ScannerException
|
||||
{
|
||||
validateString( expectedImage, false );
|
||||
}
|
||||
|
||||
public void validateString(String expectedImage, boolean lString ) throws ScannerException
|
||||
{
|
||||
try {
|
||||
Token t= scanner.nextToken();
|
||||
if( lString )
|
||||
assertTrue(t.type == Token.tLSTRING);
|
||||
else
|
||||
assertTrue(t.type == Token.tSTRING);
|
||||
assertTrue(t.image.equals(expectedImage));
|
||||
} catch (Parser.EndOfFile e) {
|
||||
assertTrue(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue