diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java index 411fae358b1..c0ec0b6e566 100644 --- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java @@ -6,7 +6,7 @@ import java.util.List; import org.eclipse.cdt.internal.core.parser.Token; -public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable { +public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable, IAccessable { private AccessSpecifier access = new AccessSpecifier( AccessSpecifier.v_private ); private ClassKey key = new ClassKey(); @@ -42,7 +42,7 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable /** * @return int */ - public int getCurrentVisibility() { + public int getVisibility() { return access.getAccess(); } @@ -50,7 +50,7 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable * Sets the currentVisiblity. * @param currentVisiblity The currentVisiblity to set */ - public void setCurrentVisibility(int currentVisiblity) { + public void setVisibility(int currentVisiblity) { access.setAccess(currentVisiblity); } 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 1893d29eec8..1daaa0a4627 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 @@ -53,7 +53,7 @@ public class DOMBuilder implements IParserCallback } ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl); - classSpecifier.setCurrentVisibility( visibility ); + classSpecifier.setVisibility( visibility ); classSpecifier.setStartingOffset( classKey.getOffset() ); classSpecifier.setClassKeyToken( classKey ); decl.setTypeSpecifier(classSpecifier); @@ -175,8 +175,8 @@ public class DOMBuilder implements IParserCallback public Object simpleDeclarationBegin(Object container, Token firstToken) { SimpleDeclaration decl = new SimpleDeclaration(); ((IScope)container).addDeclaration(decl); - if( container instanceof ClassSpecifier ) - decl.setAccessSpecifier(new AccessSpecifier( ((ClassSpecifier)container).getCurrentVisibility() )); + if( container instanceof IAccessable ) + decl.setAccessSpecifier(new AccessSpecifier( ((IAccessable)container).getVisibility() )); ((IOffsetable)decl).setStartingOffset( firstToken.getOffset() ); return decl; } @@ -381,13 +381,13 @@ public class DOMBuilder implements IParserCallback switch( visibility.getType() ) { case Token.t_public: - spec.setCurrentVisibility( AccessSpecifier.v_public ); + spec.setVisibility( AccessSpecifier.v_public ); break; case Token.t_protected: - spec.setCurrentVisibility( AccessSpecifier.v_protected ); + spec.setVisibility( AccessSpecifier.v_protected ); break; case Token.t_private: - spec.setCurrentVisibility( AccessSpecifier.v_private ); + spec.setVisibility( AccessSpecifier.v_private ); break; } return spec; @@ -814,7 +814,10 @@ public class DOMBuilder implements IParserCallback * @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean) */ public Object templateDeclarationBegin(Object container, Token exported) { - return new TemplateDeclaration( (IScope)container, exported ); + TemplateDeclaration d = new TemplateDeclaration( (IScope)container, exported ); + if( container instanceof IAccessable ) + d.setVisibility( ((IAccessable)container).getVisibility() ); + return d; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/IAccessable.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/IAccessable.java new file mode 100644 index 00000000000..cb6246bf099 --- /dev/null +++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/IAccessable.java @@ -0,0 +1,25 @@ +/* + * Created on Apr 10, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.cdt.internal.core.dom; + +/** + * @author jcamelon + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public interface IAccessable { + /** + * @return int + */ + public abstract int getVisibility(); + /** + * Sets the currentVisiblity. + * @param currentVisiblity The currentVisiblity to set + */ + public abstract void setVisibility(int currentVisiblity); +} \ No newline at end of file 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 b7322fe2438..98db4c6735c 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 @@ -22,9 +22,10 @@ import org.eclipse.cdt.internal.core.parser.Token; * @author jcamelon * */ -public class TemplateDeclaration extends Declaration implements IScope, ITemplateParameterListOwner, IOffsetable { +public class TemplateDeclaration extends Declaration implements IScope, IAccessable, ITemplateParameterListOwner, IOffsetable { private final boolean exported; + private AccessSpecifier visibility = null; private Token firstToken, lastToken; private IScope ownerScope; private List declarations = new ArrayList(); @@ -125,14 +126,30 @@ public class TemplateDeclaration extends Declaration implements IScope, ITemplat * @see org.eclipse.cdt.internal.core.dom.IOffsetable#setStartingOffset(int) */ public void setStartingOffset(int i) { - throw new Error( "Sorry, not implemented bucko!"); + throw new Error( "Offset should not be set"); } /* (non-Javadoc) * @see org.eclipse.cdt.internal.core.dom.IOffsetable#setTotalLength(int) */ public void setTotalLength(int i) { - throw new Error( "Sorry, not implemented bucko!"); + throw new Error( "Offset should not be set"); + } + + /** + * @return + */ + public int getVisibility() { + if( visibility == null ) return AccessSpecifier.v_unknown; + return visibility.getAccess(); + } + + /** + * @param specifier + */ + public void setVisibility(int visibility) { + if( this.visibility == null ) this.visibility = new AccessSpecifier(visibility); + else this.visibility.setAccess(visibility); } } diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog index 0aa81a0ccf8..9325e1f20cb 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 + Fixed Bug36237 Parser fails on casts in ctor initializer. + Added AccessSpecifier to TemplateDeclaration. + 2003-04-10 John Camelon Updated callbacks and parser to add offset information to template declarations, thus making TemplateDeclaration implement IOffsetable. 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 ba887683c7b..cfdd22f490a 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 @@ -1151,8 +1151,7 @@ c, quick); switch (LT(1)) { case Token.tLPAREN: // temporary fix for initializer/function declaration ambiguity - if( LT(2) != Token.tINTEGER && LT(2) != Token.t_false && LT(2) != Token.t_true && LT(2) != Token.tSTRING && - LT(2) != Token.tLSTRING ) + if( ! LA(2).looksLikeExpression() ) { // parameterDeclarationClause Object clause = null; @@ -1894,13 +1893,19 @@ c, quick); */ protected void castExpression( Object expression ) throws Backtrack { // TO DO: we need proper symbol checkint to ensure type name - if (false && LT(1) == Token.tLPAREN) { + if (LT(1) == Token.tLPAREN) { Token mark = mark(); consume(); // If this isn't a type name, then we shouldn't be here try { + if( LT(1) == Token.t_const ) consume(); typeId(); + while( LT(1) == Token.tSTAR ) + { + consume( Token.tSTAR ); + if( LT(1) == Token.t_const || LT(1) == Token.t_volatile ) consume(); + } consume(Token.tRPAREN); castExpression( expression ); return; @@ -1917,6 +1922,33 @@ c, quick); name(); return; } catch (Backtrack b) { + boolean encountered = false; + simpleMods: + for( ; ; ) + { + switch( LT(1) ) + { + case Token.t_short: + case Token.t_unsigned: + case Token.t_long: + encountered = true; + consume(); + break; + case Token.t_int: + case Token.t_char: + case Token.t_bool: + case Token.t_double: + case Token.t_float: + case Token.t_wchar_t: + case Token.t_void: + encountered = true; + consume(); + default: + break simpleMods; + } + } + if( encountered ) + return; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java index 88efd08693c..d29cd49f367 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java @@ -49,6 +49,29 @@ public class Token { public Token getNext() { return next; } public void setNext(Token t) { next = t; } + public boolean looksLikeExpression() + { + switch( getType() ) + { + case tINTEGER: + case t_false: + case t_true: + case tSTRING: + case tLSTRING: + case tFLOATINGPT: + case tCHAR: + case tAMPER: + case tDOT: + case tLPAREN: + return true; + default: + break; + } + + + return false; + } + public boolean isOperator() { switch( getType() ) diff --git a/core/org.eclipse.cdt.ui.tests/ChangeLog b/core/org.eclipse.cdt.ui.tests/ChangeLog index 39b8d658164..67741941ec8 100644 --- a/core/org.eclipse.cdt.ui.tests/ChangeLog +++ b/core/org.eclipse.cdt.ui.tests/ChangeLog @@ -1,3 +1,6 @@ +2003-04-10 John Camelon + Added DOMTests::testBug36237(). + 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.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java index 62fe96a3dd4..1eda36e1fa8 100644 --- a/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java +++ b/core/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java @@ -1225,5 +1225,12 @@ public class DOMTests extends TestCase { assertEquals( parmDeclarator.getName().toString(), "p1"); assertNotNull( parmDeclarator.getExpression()); } + + public void testBug36237() throws Exception + { + TranslationUnit tu = parse( "A::A():B( (char *)0 ){}", true ); + assertEquals( tu.getDeclarations().size(), 1 ); + } + }