[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Another Parser Patch
|
CORE
Fixed Bug36237 Parser fails on casts in ctor initializer.
Added AccessSpecifier to TemplateDeclaration.
TESTS
Added DOMTests::testBug36237().
JohnC
Index: dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java,v
retrieving revision 1.8
diff -u -r1.8 ClassSpecifier.java
--- dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java 9 Apr 2003 21:11:59 -0000 1.8
+++ dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java 10 Apr 2003 21:20:18 -0000
@@ -6,7 +6,7 @@
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 @@
/**
* @return int
*/
- public int getCurrentVisibility() {
+ public int getVisibility() {
return access.getAccess();
}
@@ -50,7 +50,7 @@
* Sets the currentVisiblity.
* @param currentVisiblity The currentVisiblity to set
*/
- public void setCurrentVisibility(int currentVisiblity) {
+ public void setVisibility(int currentVisiblity) {
access.setAccess(currentVisiblity);
}
Index: dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java,v
retrieving revision 1.19
diff -u -r1.19 DOMBuilder.java
--- dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java 10 Apr 2003 17:25:06 -0000 1.19
+++ dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java 10 Apr 2003 21:20:19 -0000
@@ -53,7 +53,7 @@
}
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 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 @@
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 @@
* @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)
Index: dom/org/eclipse/cdt/internal/core/dom/IAccessable.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/IAccessable.java
diff -N dom/org/eclipse/cdt/internal/core/dom/IAccessable.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/IAccessable.java 10 Apr 2003 21:20:19 -0000
@@ -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
Index: dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java,v
retrieving revision 1.3
diff -u -r1.3 TemplateDeclaration.java
--- dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java 10 Apr 2003 17:25:06 -0000 1.3
+++ dom/org/eclipse/cdt/internal/core/dom/TemplateDeclaration.java 10 Apr 2003 21:20:19 -0000
@@ -22,9 +22,10 @@
* @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 @@
* @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);
}
}
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.25
diff -u -r1.25 ChangeLog
--- parser/ChangeLog 10 Apr 2003 17:25:06 -0000 1.25
+++ parser/ChangeLog 10 Apr 2003 21:20:20 -0000
@@ -1,4 +1,8 @@
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.
Index: parser/org/eclipse/cdt/internal/core/parser/Parser.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java,v
retrieving revision 1.26
diff -u -r1.26 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 10 Apr 2003 17:25:06 -0000 1.26
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 10 Apr 2003 21:20:22 -0000
@@ -1151,8 +1151,7 @@
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 @@
*/
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 @@
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;
}
}
Index: parser/org/eclipse/cdt/internal/core/parser/Token.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Token.java,v
retrieving revision 1.8
diff -u -r1.8 Token.java
--- parser/org/eclipse/cdt/internal/core/parser/Token.java 4 Apr 2003 18:45:09 -0000 1.8
+++ parser/org/eclipse/cdt/internal/core/parser/Token.java 10 Apr 2003 21:20:23 -0000
@@ -49,6 +49,29 @@
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() )
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/ChangeLog,v
retrieving revision 1.23
diff -u -r1.23 ChangeLog
--- ChangeLog 9 Apr 2003 21:12:09 -0000 1.23
+++ ChangeLog 10 Apr 2003 21:20:46 -0000
@@ -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.
Index: parser/org/eclipse/cdt/core/parser/tests/DOMTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/DOMTests.java,v
retrieving revision 1.17
diff -u -r1.17 DOMTests.java
--- parser/org/eclipse/cdt/core/parser/tests/DOMTests.java 9 Apr 2003 21:12:09 -0000 1.17
+++ parser/org/eclipse/cdt/core/parser/tests/DOMTests.java 10 Apr 2003 21:20:48 -0000
@@ -1225,5 +1225,12 @@
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 );
+ }
+
}