diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java index 75d0d188654..1893d29eec8 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java @@ -813,7 +813,7 @@ public class DOMBuilder implements IParserCallback /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) */ - public Object templateDeclarationBegin(Object container, boolean exported) { + public Object templateDeclarationBegin(Object container, Token exported) { return new TemplateDeclaration( (IScope)container, exported ); } @@ -827,8 +827,9 @@ public class DOMBuilder implements IParserCallback /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object) */ - public void templateDeclarationEnd(Object templateDecl) { + public void templateDeclarationEnd(Object templateDecl, Token lastToken) { TemplateDeclaration decl = (TemplateDeclaration)templateDecl; + decl.setLastToken(lastToken); decl.getOwnerScope().addDeclaration(decl); } diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java index 562276933bb..b7322fe2438 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java @@ -16,21 +16,25 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.eclipse.cdt.internal.core.parser.Token; + /** * @author jcamelon * */ -public class TemplateDeclaration extends Declaration implements IScope, ITemplateParameterListOwner { +public class TemplateDeclaration extends Declaration implements IScope, ITemplateParameterListOwner, IOffsetable { - private final boolean exported; + private final boolean exported; + private Token firstToken, lastToken; private IScope ownerScope; private List declarations = new ArrayList(); private TemplateParameterList templateParms = null; - public TemplateDeclaration( IScope ownerScope, boolean exported ) + public TemplateDeclaration( IScope ownerScope, Token exported ) { this.ownerScope = ownerScope; - this.exported = exported; + this.firstToken = exported; + this.exported = exported.getType() == Token.t_export ? true : false; } /* (non-Javadoc) @@ -75,4 +79,60 @@ public class TemplateDeclaration extends Declaration implements IScope, ITemplat templateParms = list; } + /** + * @return + */ + public Token getFirstToken() { + return firstToken; + } + + /** + * @return + */ + public Token getLastToken() { + return lastToken; + } + + /** + * @param token + */ + public void setFirstToken(Token token) { + firstToken = token; + } + + /** + * @param token + */ + public void setLastToken(Token token) { + lastToken = token; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.IOffsetable#getStartingOffset() + */ + public int getStartingOffset() { + return getFirstToken().getOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.IOffsetable#getTotalLength() + */ + public int getTotalLength() { + return getLastToken().getOffset() + getLastToken().getLength() - getStartingOffset(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.IOffsetable#setStartingOffset(int) + */ + public void setStartingOffset(int i) { + throw new Error( "Sorry, not implemented bucko!"); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.internal.core.dom.IOffsetable#setTotalLength(int) + */ + public void setTotalLength(int i) { + throw new Error( "Sorry, not implemented bucko!"); + } + } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 97148b30d86..0aa81a0ccf8 100644 --- a/core/org.eclipse.cdt.core/parser/ChangeLog +++ b/core/org.eclipse.cdt.core/parser/ChangeLog @@ -1,3 +1,7 @@ +2003-04-10 John Camelon + Updated callbacks and parser to add offset information to template declarations, + thus making TemplateDeclaration implement IOffsetable. + 2003-04-09 John Camelon Removed all the old Code Model Builder source that was no longer being used (NewModelBuilder.java, etc.). Moved all the files in parser.util directory to the dom. diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java index fb88289a58d..45991a54daf 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java @@ -680,7 +680,7 @@ public class ExpressionEvaluator implements IParserCallback { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) */ - public Object templateDeclarationBegin(Object container, boolean exported) { + public Object templateDeclarationBegin(Object container, Token exported) { return null; } @@ -693,7 +693,7 @@ public class ExpressionEvaluator implements IParserCallback { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object) */ - public void templateDeclarationEnd(Object templateDecl) { + public void templateDeclarationEnd(Object templateDecl, Token lastToken) { } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java index 347049dfbf5..6cb6843b1c6 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java @@ -124,9 +124,9 @@ public interface IParserCallback { public Object explicitSpecializationBegin( Object container ); public void explicitSpecializationEnd( Object instantiation ); - public Object templateDeclarationBegin( Object container, boolean exported ); + public Object templateDeclarationBegin( Object container, Token firstToken ); public void templateDeclarationAbort( Object templateDecl ); - public void templateDeclarationEnd( Object templateDecl ); + public void templateDeclarationEnd( Object templateDecl, Token lastToken ); public Object templateParameterListBegin( Object declaration ); public void templateParameterListEnd( Object parameterList ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java index 30d7175edc1..6992f790753 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java @@ -569,7 +569,7 @@ public class NullParserCallback implements IParserCallback { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) */ - public Object templateDeclarationBegin(Object container, boolean exported) { + public Object templateDeclarationBegin(Object container, Token exported) { return null; } @@ -582,7 +582,7 @@ public class NullParserCallback implements IParserCallback { /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationEnd(java.lang.Object) */ - public void templateDeclarationEnd(Object templateDecl) { + public void templateDeclarationEnd(Object templateDecl, Token lastToken) { } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java index cd4c59b4d85..ba887683c7b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java @@ -283,14 +283,16 @@ c, quick); */ protected void templateDeclaration( Object container ) throws Backtrack { - boolean export = false; + Token firstToken = null; if( LT(1) == Token.t_export ) { - consume( Token.t_export ); - export = true; + firstToken = consume( Token.t_export ); + consume( Token.t_template ); } + else + firstToken = consume( Token.t_template ); + - consume( Token.t_template ); if( LT(1) != Token.tLT ) { // explicit-instantiation @@ -318,11 +320,11 @@ c, quick); Object templateDeclaration = null; try { - try{ templateDeclaration = callback.templateDeclarationBegin( container, export ); } catch ( Exception e ) {} + try{ templateDeclaration = callback.templateDeclarationBegin( container, firstToken ); } catch ( Exception e ) {} templateParameterList( templateDeclaration ); consume( Token.tGT ); declaration( templateDeclaration ); - try{ callback.templateDeclarationEnd( templateDeclaration ); } catch( Exception e ) {} + try{ callback.templateDeclarationEnd( templateDeclaration, lastToken ); } catch( Exception e ) {} } catch( Backtrack bt ) {