1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for John Camelon:

CORE
		 Fixed Bug36237  Parser fails on casts in ctor initializer.
		 Added AccessSpecifier to TemplateDeclaration.

TESTS
		 Added DOMTests::testBug36237().
This commit is contained in:
Doug Schaefer 2003-04-11 14:42:29 +00:00
parent d64897da7a
commit 04f59699f5
9 changed files with 130 additions and 16 deletions

View file

@ -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);
}

View file

@ -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)

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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.

View file

@ -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;
}
}

View file

@ -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() )

View file

@ -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.

View file

@ -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 );
}
}