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:
parent
d64897da7a
commit
04f59699f5
9 changed files with 130 additions and 16 deletions
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.parser.Token;
|
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 AccessSpecifier access = new AccessSpecifier( AccessSpecifier.v_private );
|
||||||
private ClassKey key = new ClassKey();
|
private ClassKey key = new ClassKey();
|
||||||
|
@ -42,7 +42,7 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public int getCurrentVisibility() {
|
public int getVisibility() {
|
||||||
return access.getAccess();
|
return access.getAccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsetable
|
||||||
* Sets the currentVisiblity.
|
* Sets the currentVisiblity.
|
||||||
* @param currentVisiblity The currentVisiblity to set
|
* @param currentVisiblity The currentVisiblity to set
|
||||||
*/
|
*/
|
||||||
public void setCurrentVisibility(int currentVisiblity) {
|
public void setVisibility(int currentVisiblity) {
|
||||||
access.setAccess(currentVisiblity);
|
access.setAccess(currentVisiblity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class DOMBuilder implements IParserCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl);
|
ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl);
|
||||||
classSpecifier.setCurrentVisibility( visibility );
|
classSpecifier.setVisibility( visibility );
|
||||||
classSpecifier.setStartingOffset( classKey.getOffset() );
|
classSpecifier.setStartingOffset( classKey.getOffset() );
|
||||||
classSpecifier.setClassKeyToken( classKey );
|
classSpecifier.setClassKeyToken( classKey );
|
||||||
decl.setTypeSpecifier(classSpecifier);
|
decl.setTypeSpecifier(classSpecifier);
|
||||||
|
@ -175,8 +175,8 @@ public class DOMBuilder implements IParserCallback
|
||||||
public Object simpleDeclarationBegin(Object container, Token firstToken) {
|
public Object simpleDeclarationBegin(Object container, Token firstToken) {
|
||||||
SimpleDeclaration decl = new SimpleDeclaration();
|
SimpleDeclaration decl = new SimpleDeclaration();
|
||||||
((IScope)container).addDeclaration(decl);
|
((IScope)container).addDeclaration(decl);
|
||||||
if( container instanceof ClassSpecifier )
|
if( container instanceof IAccessable )
|
||||||
decl.setAccessSpecifier(new AccessSpecifier( ((ClassSpecifier)container).getCurrentVisibility() ));
|
decl.setAccessSpecifier(new AccessSpecifier( ((IAccessable)container).getVisibility() ));
|
||||||
((IOffsetable)decl).setStartingOffset( firstToken.getOffset() );
|
((IOffsetable)decl).setStartingOffset( firstToken.getOffset() );
|
||||||
return decl;
|
return decl;
|
||||||
}
|
}
|
||||||
|
@ -381,13 +381,13 @@ public class DOMBuilder implements IParserCallback
|
||||||
switch( visibility.getType() )
|
switch( visibility.getType() )
|
||||||
{
|
{
|
||||||
case Token.t_public:
|
case Token.t_public:
|
||||||
spec.setCurrentVisibility( AccessSpecifier.v_public );
|
spec.setVisibility( AccessSpecifier.v_public );
|
||||||
break;
|
break;
|
||||||
case Token.t_protected:
|
case Token.t_protected:
|
||||||
spec.setCurrentVisibility( AccessSpecifier.v_protected );
|
spec.setVisibility( AccessSpecifier.v_protected );
|
||||||
break;
|
break;
|
||||||
case Token.t_private:
|
case Token.t_private:
|
||||||
spec.setCurrentVisibility( AccessSpecifier.v_private );
|
spec.setVisibility( AccessSpecifier.v_private );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return spec;
|
return spec;
|
||||||
|
@ -814,7 +814,10 @@ public class DOMBuilder implements IParserCallback
|
||||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean)
|
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#templateDeclarationBegin(java.lang.Object, boolean)
|
||||||
*/
|
*/
|
||||||
public Object templateDeclarationBegin(Object container, Token exported) {
|
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)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -22,9 +22,10 @@ import org.eclipse.cdt.internal.core.parser.Token;
|
||||||
* @author jcamelon
|
* @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 final boolean exported;
|
||||||
|
private AccessSpecifier visibility = null;
|
||||||
private Token firstToken, lastToken;
|
private Token firstToken, lastToken;
|
||||||
private IScope ownerScope;
|
private IScope ownerScope;
|
||||||
private List declarations = new ArrayList();
|
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)
|
* @see org.eclipse.cdt.internal.core.dom.IOffsetable#setStartingOffset(int)
|
||||||
*/
|
*/
|
||||||
public void setStartingOffset(int i) {
|
public void setStartingOffset(int i) {
|
||||||
throw new Error( "Sorry, not implemented bucko!");
|
throw new Error( "Offset should not be set");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.dom.IOffsetable#setTotalLength(int)
|
* @see org.eclipse.cdt.internal.core.dom.IOffsetable#setTotalLength(int)
|
||||||
*/
|
*/
|
||||||
public void setTotalLength(int i) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
2003-04-10 John Camelon
|
||||||
Updated callbacks and parser to add offset information to template declarations,
|
Updated callbacks and parser to add offset information to template declarations,
|
||||||
thus making TemplateDeclaration implement IOffsetable.
|
thus making TemplateDeclaration implement IOffsetable.
|
||||||
|
|
|
@ -1151,8 +1151,7 @@ c, quick);
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case Token.tLPAREN:
|
case Token.tLPAREN:
|
||||||
// temporary fix for initializer/function declaration ambiguity
|
// 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 &&
|
if( ! LA(2).looksLikeExpression() )
|
||||||
LT(2) != Token.tLSTRING )
|
|
||||||
{
|
{
|
||||||
// parameterDeclarationClause
|
// parameterDeclarationClause
|
||||||
Object clause = null;
|
Object clause = null;
|
||||||
|
@ -1894,13 +1893,19 @@ c, quick);
|
||||||
*/
|
*/
|
||||||
protected void castExpression( Object expression ) throws Backtrack {
|
protected void castExpression( Object expression ) throws Backtrack {
|
||||||
// TO DO: we need proper symbol checkint to ensure type name
|
// 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();
|
Token mark = mark();
|
||||||
consume();
|
consume();
|
||||||
|
|
||||||
// If this isn't a type name, then we shouldn't be here
|
// If this isn't a type name, then we shouldn't be here
|
||||||
try {
|
try {
|
||||||
|
if( LT(1) == Token.t_const ) consume();
|
||||||
typeId();
|
typeId();
|
||||||
|
while( LT(1) == Token.tSTAR )
|
||||||
|
{
|
||||||
|
consume( Token.tSTAR );
|
||||||
|
if( LT(1) == Token.t_const || LT(1) == Token.t_volatile ) consume();
|
||||||
|
}
|
||||||
consume(Token.tRPAREN);
|
consume(Token.tRPAREN);
|
||||||
castExpression( expression );
|
castExpression( expression );
|
||||||
return;
|
return;
|
||||||
|
@ -1917,6 +1922,33 @@ c, quick);
|
||||||
name();
|
name();
|
||||||
return;
|
return;
|
||||||
} catch (Backtrack b) {
|
} 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,29 @@ public class Token {
|
||||||
public Token getNext() { return next; }
|
public Token getNext() { return next; }
|
||||||
public void setNext(Token t) { next = t; }
|
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()
|
public boolean isOperator()
|
||||||
{
|
{
|
||||||
switch( getType() )
|
switch( getType() )
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
2003-04-10 John Camelon
|
||||||
|
Added DOMTests::testBug36237().
|
||||||
|
|
||||||
2003-04-09 John Camelon
|
2003-04-09 John Camelon
|
||||||
Removed all the old Code Model Builder source that was no longer being used (NewModelBuilder.java, etc.).
|
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.
|
Moved all the files in parser.util directory to the dom.
|
||||||
|
|
|
@ -1225,5 +1225,12 @@ public class DOMTests extends TestCase {
|
||||||
assertEquals( parmDeclarator.getName().toString(), "p1");
|
assertEquals( parmDeclarator.getName().toString(), "p1");
|
||||||
assertNotNull( parmDeclarator.getExpression());
|
assertNotNull( parmDeclarator.getExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBug36237() throws Exception
|
||||||
|
{
|
||||||
|
TranslationUnit tu = parse( "A::A():B( (char *)0 ){}", true );
|
||||||
|
assertEquals( tu.getDeclarations().size(), 1 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue