[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Parser upgrades - Refactoring for better use of our DOM
|
CORE
Brought DOM up to par wrt functionality with Code Model.
Added isFunctionDefinition() to SimpleDeclaration.
Added visiblity indicators for member declarations.
Added offset information that was previously unavailable.
Added preprocessor statements (inclusions, macros) to DOM.
Updated TypeSpecifier hierarchy to allow for parameter declarations
to own elaborated types.
Added new constructor to parser to aid testing.
Fixed bug36065.
TESTS
Added testMemberDeclarations(), testPreprocessor(),
testElaboratedParms() to DOMTests.
JohnC
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/ChangeLog,v
retrieving revision 1.20
diff -u -r1.20 ChangeLog
--- ChangeLog 6 Apr 2003 00:33:54 -0000 1.20
+++ ChangeLog 8 Apr 2003 01:07:55 -0000
@@ -1,3 +1,6 @@
+2003-04-07 John Camelon
+ Added testMemberDeclarations(), testPreprocessor(), testElaboratedParms() to DOMTests.
+
2003-04-04 Alain Magloire
* src/org/eclipse/cdt/testplugin/util/VerifyDialog.java:
Remove some warnings.
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.14
diff -u -r1.14 DOMTests.java
--- parser/org/eclipse/cdt/core/parser/tests/DOMTests.java 6 Apr 2003 03:06:22 -0000 1.14
+++ parser/org/eclipse/cdt/core/parser/tests/DOMTests.java 8 Apr 2003 01:07:56 -0000
@@ -22,7 +22,9 @@
import org.eclipse.cdt.internal.core.dom.ExceptionSpecifier;
import org.eclipse.cdt.internal.core.dom.ExplicitTemplateDeclaration;
import org.eclipse.cdt.internal.core.dom.Expression;
+import org.eclipse.cdt.internal.core.dom.Inclusion;
import org.eclipse.cdt.internal.core.dom.LinkageSpecification;
+import org.eclipse.cdt.internal.core.dom.Macro;
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.ParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
@@ -51,9 +53,14 @@
super( arg );
}
- public TranslationUnit parse(String code) throws Exception {
+ public TranslationUnit parse( String code ) throws Exception
+ {
+ return parse( code, false );
+ }
+
+ public TranslationUnit parse(String code, boolean quickParse ) throws Exception {
DOMBuilder domBuilder = new DOMBuilder();
- Parser parser = new Parser(code, domBuilder);
+ Parser parser = new Parser(code, domBuilder, quickParse );
if( ! parser.parse() ) throw new ParserException( "Parse failure" );
return domBuilder.getTranslationUnit();
@@ -689,6 +696,93 @@
ArrayQualifier q2 =(ArrayQualifier)arrayQualifiers.get(1);
assertNull( q2.getExpression() );
}
+
+ public void testElaboratedParms() throws Exception
+ {
+ TranslationUnit tu = parse( "int x( struct A myA ) { /* junk */ }", true);
+ assertEquals( tu.getDeclarations().size(), 1 );
+ SimpleDeclaration declaration = (SimpleDeclaration)tu.getDeclarations().get(0);
+ assertEquals( declaration.getDeclSpecifier().getType(), DeclSpecifier.t_int );
+ assertEquals( declaration.getDeclarators().size(), 1 );
+ Declarator declarator = (Declarator)declaration.getDeclarators().get(0);
+ assertEquals( declarator.getName().toString(), "x" );
+ assertTrue( declaration.isFunctionDefinition() );
+ assertEquals( declarator.getParms().getDeclarations().size(), 1 );
+ ParameterDeclaration parm = (ParameterDeclaration)declarator.getParms().getDeclarations().get(0);
+ ElaboratedTypeSpecifier typeSpec = (ElaboratedTypeSpecifier)parm.getTypeSpecifier();
+ assertEquals( typeSpec.getClassKey(), ClassKey.t_struct );
+ assertEquals( typeSpec.getName().toString(), "A" );
+ assertEquals( parm.getDeclarators().size(), 1 );
+ Declarator subDeclarator = (Declarator)parm.getDeclarators().get(0);
+ assertEquals( subDeclarator.getName().toString(), "myA" );
+
+ }
+
+ public void testPreprocessor() throws Exception
+ {
+ Writer code = new StringWriter();
+ code.write( "#include <stdio.h>\n#define DEF VALUE\n");
+ TranslationUnit tu = parse( code.toString(), true );
+ assertEquals( tu.getInclusions().size(), 1 );
+ Inclusion i = (Inclusion)tu.getInclusions().get(0);
+ assertEquals( i.getName(), "stdio.h");
+ assertEquals( i.getStartingOffset(), 0 );
+ assertEquals( i.getNameLength(), 7 );
+ assertEquals( i.getNameOffset(), 10 );
+ assertEquals( i.getTotalLength(), 18 );
+
+ assertEquals( tu.getMacros().size(), 1 );
+ Macro m = (Macro)tu.getMacros().get(0);
+ assertEquals( m.getName(), "DEF" );
+ assertEquals( m.getStartingOffset(), 19 );
+ assertEquals( m.getNameLength(), 3 );
+ assertEquals( m.getNameOffset(), 27 );
+ assertEquals( m.getTotalLength(), 18 );
+ }
+
+ public void testMemberDeclarations() throws Exception
+ {
+ Writer code = new StringWriter();
+ code.write( "class A {\n" );
+ code.write( "public:\n");
+ code.write( " int isPublic;\n" );
+ code.write( "private:\n");
+ code.write( " int isPrivate;\n" );
+ code.write( "protected:\n");
+ code.write( " int isProtected;\n" );
+ code.write( "};");
+ TranslationUnit translationUnit = parse( code.toString() );
+ assertEquals( translationUnit.getDeclarations().size(), 1 );
+ SimpleDeclaration classDeclaration = (SimpleDeclaration)
+ translationUnit.getDeclarations().get(0);
+ assertEquals( classDeclaration.getDeclarators().size(), 0 );
+ ClassSpecifier classSpec = (ClassSpecifier)classDeclaration.getTypeSpecifier();
+ assertEquals( "A", classSpec.getName().toString() );
+ assertEquals( 3, classSpec.getDeclarations().size());
+ for( int i = 0; i < 3; ++i )
+ {
+ SimpleDeclaration subDecl = (SimpleDeclaration)classSpec.getDeclarations().get( i );
+ int visibility = AccessSpecifier.v_unknown;
+
+ switch( i )
+ {
+ case 0:
+ visibility = AccessSpecifier.v_public;
+ break;
+ case 1:
+ visibility = AccessSpecifier.v_private;
+ break;
+ case 2:
+ visibility = AccessSpecifier.v_protected;
+ break;
+ default:
+ break;
+ }
+
+ assertEquals( visibility, subDecl.getAccessSpecifier().getAccess() );
+ }
+
+ }
public void testPointerOperators() throws Exception
{
Index: parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java,v
retrieving revision 1.9
diff -u -r1.9 ScannerTestCase.java
--- parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java 4 Apr 2003 14:05:22 -0000 1.9
+++ parser/org/eclipse/cdt/core/parser/tests/ScannerTestCase.java 8 Apr 2003 01:07:57 -0000
@@ -1,7 +1,6 @@
package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
-import java.io.StringWriter;
import java.util.List;
import junit.framework.Test;
Index: dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java,v
retrieving revision 1.4
diff -u -r1.4 BaseSpecifier.java
--- dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java 29 Mar 2003 05:35:47 -0000 1.4
+++ dom/org/eclipse/cdt/internal/core/dom/BaseSpecifier.java 8 Apr 2003 01:07:26 -0000
@@ -37,7 +37,7 @@
public boolean isVirtual() { return isVirtual; }
- private AccessSpecifier access = new AccessSpecifier();
+ private AccessSpecifier access = new AccessSpecifier( AccessSpecifier.v_unknown );
public void setAccess(int access) { this.access.setAccess(access); }
public int getAccess() { return access.getAccess(); }
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.5
diff -u -r1.5 ClassSpecifier.java
--- dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java 29 Mar 2003 05:35:47 -0000 1.5
+++ dom/org/eclipse/cdt/internal/core/dom/ClassSpecifier.java 8 Apr 2003 01:07:26 -0000
@@ -8,14 +8,15 @@
import org.eclipse.cdt.internal.core.parser.util.ClassKey;
import org.eclipse.cdt.internal.core.parser.util.Name;
-public class ClassSpecifier extends TypeSpecifier implements IScope {
+public class ClassSpecifier extends TypeSpecifier implements IScope, IOffsettable {
- AccessSpecifier access = new AccessSpecifier();
- ClassKey key = new ClassKey();
+ private AccessSpecifier access = new AccessSpecifier( AccessSpecifier.v_private );
+ private ClassKey key = new ClassKey();
+ private int startingOffset = 0, totalLength = 0;
public int getClassKey() { return key.getClassKey(); }
- public ClassSpecifier(int classKey, SimpleDeclaration declaration) {
+ public ClassSpecifier(int classKey, TypeSpecifier.IOwner declaration) {
super(declaration);
this.key.setClassKey(classKey);
}
@@ -52,6 +53,34 @@
*/
public void setCurrentVisibility(int currentVisiblity) {
access.setAccess(currentVisiblity);
+ }
+
+ /**
+ * @return
+ */
+ public int getStartingOffset() {
+ return startingOffset;
+ }
+
+ /**
+ * @return
+ */
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+ /**
+ * @param i
+ */
+ public void setStartingOffset(int i) {
+ startingOffset = i;
+ }
+
+ /**
+ * @param i
+ */
+ public void setTotalLength(int i) {
+ totalLength = i;
}
}
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.15
diff -u -r1.15 DOMBuilder.java
--- dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java 6 Apr 2003 03:06:16 -0000 1.15
+++ dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java 8 Apr 2003 01:07:26 -0000
@@ -38,7 +38,7 @@
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classBegin(java.lang.String, org.eclipse.cdt.internal.core.newparser.Token)
*/
public Object classSpecifierBegin(Object container, Token classKey) {
- SimpleDeclaration decl = (SimpleDeclaration)container;
+ TypeSpecifier.IOwner decl = (TypeSpecifier.IOwner)container;
int kind = ClassKey.t_struct;
int visibility = AccessSpecifier.v_public;
@@ -58,6 +58,7 @@
ClassSpecifier classSpecifier = new ClassSpecifier(kind, decl);
classSpecifier.setCurrentVisibility( visibility );
+ classSpecifier.setStartingOffset( classKey.getOffset() );
decl.setTypeSpecifier(classSpecifier);
return classSpecifier;
}
@@ -74,6 +75,8 @@
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classEnd()
*/
public void classSpecifierEnd(Object classSpecifier, Token closingBrace) {
+ ClassSpecifier c = (ClassSpecifier)classSpecifier;
+ c.setTotalLength( closingBrace.getOffset() + closingBrace.getLength() - c.getStartingOffset() );
}
/**
@@ -138,6 +141,8 @@
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#functionBodyBegin()
*/
public Object functionBodyBegin(Object declaration) {
+ SimpleDeclaration simpleDec = (SimpleDeclaration)declaration;
+ simpleDec.setFunctionDefinition(true);
return null;
}
@@ -151,6 +156,7 @@
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#inclusionBegin(java.lang.String)
*/
public void inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) {
+ translationUnit.addInclusion( new Inclusion( includeFile, offset, inclusionBeginOffset, offset + includeFile.length() + 1 ) );
}
/**
@@ -163,6 +169,7 @@
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#macro(java.lang.String)
*/
public void macro(String macroName, int offset, int macroBeginOffset, int macroEndOffset) {
+ translationUnit.addMacro( new Macro( macroName, offset, macroBeginOffset, macroEndOffset - macroBeginOffset));
}
/**
@@ -171,6 +178,9 @@
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() ));
+ ((IOffsettable)decl).setStartingOffset( firstToken.getOffset() );
return decl;
}
@@ -178,6 +188,8 @@
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#simpleDeclarationEnd(org.eclipse.cdt.internal.core.newparser.Token)
*/
public void simpleDeclarationEnd(Object declaration, Token lastToken) {
+ IOffsettable offsetable = (IOffsettable)declaration;
+ offsetable.setTotalLength( lastToken.getOffset() + lastToken.getLength() - offsetable.getStartingOffset());
}
/**
@@ -299,7 +311,7 @@
*/
public void classSpecifierAbort(Object classSpecifier) {
ClassSpecifier cs = (ClassSpecifier)classSpecifier;
- cs.getDeclaration().setTypeSpecifier(null);
+ cs.getOwner().setTypeSpecifier(null);
}
/**
@@ -313,7 +325,6 @@
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
*/
public Object elaboratedTypeSpecifierBegin(Object container, Token classKey) {
- SimpleDeclaration declaration = (SimpleDeclaration)container;
int kind = ClassKey.t_struct;
switch (classKey.getType()) {
@@ -328,7 +339,9 @@
break;
}
- ElaboratedTypeSpecifier elab = new ElaboratedTypeSpecifier( kind, declaration );
+ ElaboratedTypeSpecifier elab = null;
+ TypeSpecifier.IOwner declaration = (TypeSpecifier.IOwner)container;
+ elab = new ElaboratedTypeSpecifier( kind, declaration );
declaration.setTypeSpecifier( elab );
return elab;
}
@@ -507,6 +520,7 @@
public Object namespaceDefinitionBegin(Object container, Token namespace) {
IScope ownerScope = (IScope)container;
NamespaceDefinition namespaceDef = new NamespaceDefinition(ownerScope);
+ ((IOffsettable)namespaceDef).setStartingOffset( namespace.getOffset() );
return namespaceDef;
}
@@ -531,6 +545,7 @@
*/
public void namespaceDefinitionEnd(Object namespace, Token closingBrace) {
NamespaceDefinition ns = (NamespaceDefinition)namespace;
+ ns.setTotalLength( closingBrace.getOffset() + closingBrace.getLength() - ns.getStartingOffset() );
ns.getOwnerScope().addDeclaration(ns);
}
@@ -622,7 +637,8 @@
public Object enumSpecifierBegin(Object container, Token enumKey) {
SimpleDeclaration decl = (SimpleDeclaration)container;
EnumerationSpecifier es = new EnumerationSpecifier( decl );
- decl.setTypeSpecifier(es);
+ decl.setTypeSpecifier(es);
+ ((IOffsettable)decl).setStartingOffset( enumKey.getOffset() );
return es;
}
@@ -640,13 +656,15 @@
*/
public void enumSpecifierAbort(Object enumSpec) {
EnumerationSpecifier es = (EnumerationSpecifier)enumSpec;
- es.getDeclaration().setTypeSpecifier(null);
+ es.getOwner().setTypeSpecifier(null);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumSpecifierEnd(java.lang.Object)
*/
public void enumSpecifierEnd(Object enumSpec, Token closingBrace) {
+ IOffsettable offsetable = (IOffsettable)enumSpec;
+ offsetable.setTotalLength( closingBrace.getOffset() + closingBrace.getLength() - offsetable.getStartingOffset());
}
/* (non-Javadoc)
@@ -665,6 +683,7 @@
public Object enumeratorId(Object enumDefn) {
EnumeratorDefinition definition = (EnumeratorDefinition)enumDefn;
definition.setName( currName );
+ ((IOffsettable)enumDefn).setStartingOffset( currName.getStartOffset() );
return definition;
}
@@ -672,6 +691,8 @@
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#enumDefinitionEnd(java.lang.Object)
*/
public void enumeratorEnd(Object enumDefn, Token lastToken) {
+ IOffsettable offsetable = (IOffsettable)enumDefn;
+ offsetable.setTotalLength( lastToken.getOffset() + lastToken.getLength() - offsetable.getStartingOffset());
}
/* (non-Javadoc)
Index: dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java,v
retrieving revision 1.2
diff -u -r1.2 ElaboratedTypeSpecifier.java
--- dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java 29 Mar 2003 05:35:47 -0000 1.2
+++ dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java 8 Apr 2003 01:07:27 -0000
@@ -21,23 +21,9 @@
{
this.classKey.setClassKey( classKey );
}
-
- /**
- * @see org.eclipse.cdt.internal.core.dom.TypeSpecifier#getDeclaration()
- */
- public SimpleDeclaration getDeclaration() {
- return super.getDeclaration();
- }
-
- /**
- * @see org.eclipse.cdt.internal.core.dom.TypeSpecifier#setDeclaration(org.eclipse.cdt.internal.core.dom.SimpleDeclaration)
- */
- public void setDeclaration(SimpleDeclaration declaration) {
- super.setDeclaration(declaration);
- }
- public ElaboratedTypeSpecifier(int classKey, SimpleDeclaration declaration) {
- super(declaration);
+ public ElaboratedTypeSpecifier(int classKey, TypeSpecifier.IOwner owner) {
+ super(owner);
this.classKey.setClassKey( classKey );
}
Index: dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java,v
retrieving revision 1.3
diff -u -r1.3 EnumerationSpecifier.java
--- dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java 31 Mar 2003 21:04:30 -0000 1.3
+++ dom/org/eclipse/cdt/internal/core/dom/EnumerationSpecifier.java 8 Apr 2003 01:07:27 -0000
@@ -22,7 +22,7 @@
* @author jcamelon
*
*/
-public class EnumerationSpecifier extends TypeSpecifier {
+public class EnumerationSpecifier extends TypeSpecifier implements IOffsettable {
public EnumerationSpecifier(SimpleDeclaration declaration) {
super(declaration);
@@ -30,6 +30,7 @@
private Name name = null;
private List enumeratorDefinitions = new ArrayList();
+ private int startingOffset = 0, totalLength = 0;
public void addEnumeratorDefinition( EnumeratorDefinition def )
{
@@ -57,6 +58,34 @@
*/
public void setName(Name name) {
this.name = name;
+ }
+
+ /**
+ * @return
+ */
+ public int getStartingOffset() {
+ return startingOffset;
+ }
+
+ /**
+ * @return
+ */
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+ /**
+ * @param i
+ */
+ public void setStartingOffset(int i) {
+ startingOffset = i;
+ }
+
+ /**
+ * @param i
+ */
+ public void setTotalLength(int i) {
+ totalLength = i;
}
}
Index: dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java,v
retrieving revision 1.1
diff -u -r1.1 EnumeratorDefinition.java
--- dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java 26 Mar 2003 16:27:44 -0000 1.1
+++ dom/org/eclipse/cdt/internal/core/dom/EnumeratorDefinition.java 8 Apr 2003 01:07:27 -0000
@@ -18,10 +18,11 @@
* @author jcamelon
*
*/
-public class EnumeratorDefinition implements IExpressionOwner {
+public class EnumeratorDefinition implements IExpressionOwner, IOffsettable {
private Expression initialValue = null;
private Name name = null;
+ private int startingOffset = 0, totalLength = 0;
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.IExpressionOwner#getExpression()
@@ -50,6 +51,34 @@
*/
public void setName(Name name) {
this.name = name;
+ }
+
+ /**
+ * @return
+ */
+ public int getStartingOffset() {
+ return startingOffset;
+ }
+
+ /**
+ * @return
+ */
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+ /**
+ * @param i
+ */
+ public void setStartingOffset(int i) {
+ startingOffset = i;
+ }
+
+ /**
+ * @param i
+ */
+ public void setTotalLength(int i) {
+ totalLength = i;
}
}
Index: dom/org/eclipse/cdt/internal/core/dom/IOffsettable.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/IOffsettable.java
diff -N dom/org/eclipse/cdt/internal/core/dom/IOffsettable.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/IOffsettable.java 8 Apr 2003 01:07:27 -0000
@@ -0,0 +1,38 @@
+/**********************************************************************
+ * Created on Apr 7, 2003
+ *
+ * Copyright (c) 2002,2003 IBM/Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Ltd. - Rational Software - Initial API and implementation
+************************************************************************/
+package org.eclipse.cdt.internal.core.dom;
+
+
+/**
+ * @author jcamelon
+ *
+ */
+public interface IOffsettable {
+
+ /**
+ * @return
+ */
+ public abstract int getStartingOffset();
+ /**
+ * @return
+ */
+ public abstract int getTotalLength();
+ /**
+ * @param i
+ */
+ public abstract void setStartingOffset(int i);
+ /**
+ * @param i
+ */
+ public abstract void setTotalLength(int i);
+}
\ No newline at end of file
Index: dom/org/eclipse/cdt/internal/core/dom/Inclusion.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/Inclusion.java
diff -N dom/org/eclipse/cdt/internal/core/dom/Inclusion.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/Inclusion.java 8 Apr 2003 01:07:27 -0000
@@ -0,0 +1,25 @@
+/**********************************************************************
+ * Created on Apr 7, 2003
+ *
+ * Copyright (c) 2002,2003 IBM/Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Ltd. - Rational Software - Initial API and implementation
+************************************************************************/
+package org.eclipse.cdt.internal.core.dom;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class Inclusion extends PreprocessorStatement {
+
+ public Inclusion( String name, int nameOffset, int startingOffset, int totalLength )
+ {
+ super( name, nameOffset, startingOffset, totalLength );
+ }
+}
Index: dom/org/eclipse/cdt/internal/core/dom/Macro.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/Macro.java
diff -N dom/org/eclipse/cdt/internal/core/dom/Macro.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/Macro.java 8 Apr 2003 01:07:27 -0000
@@ -0,0 +1,26 @@
+/**********************************************************************
+ * Created on Apr 7, 2003
+ *
+ * Copyright (c) 2002,2003 IBM/Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Ltd. - Rational Software - Initial API and implementation
+************************************************************************/
+package org.eclipse.cdt.internal.core.dom;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class Macro extends PreprocessorStatement {
+
+ public Macro( String name, int nameOffset, int startingOffset, int totalLength )
+ {
+ super( name, nameOffset, startingOffset, totalLength );
+ }
+
+}
Index: dom/org/eclipse/cdt/internal/core/dom/MemberDeclaration.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/MemberDeclaration.java
diff -N dom/org/eclipse/cdt/internal/core/dom/MemberDeclaration.java
--- dom/org/eclipse/cdt/internal/core/dom/MemberDeclaration.java 29 Mar 2003 05:35:47 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,25 +0,0 @@
-package org.eclipse.cdt.internal.core.dom;
-
-import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
-
-/**
- * @author dschaefe
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
-public class MemberDeclaration {
-
- public MemberDeclaration(int access, Declaration declaration) {
- this.access.setAccess( access );
- this.declaration = declaration;
- }
-
- private AccessSpecifier access = new AccessSpecifier();
- public int getAccess() { return access.getAccess(); }
-
- private Declaration declaration;
- public Declaration getDeclaration() { return declaration; }
-}
Index: dom/org/eclipse/cdt/internal/core/dom/NamespaceDefinition.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/NamespaceDefinition.java,v
retrieving revision 1.2
diff -u -r1.2 NamespaceDefinition.java
--- dom/org/eclipse/cdt/internal/core/dom/NamespaceDefinition.java 29 Mar 2003 05:35:47 -0000 1.2
+++ dom/org/eclipse/cdt/internal/core/dom/NamespaceDefinition.java 8 Apr 2003 01:07:27 -0000
@@ -22,11 +22,12 @@
* @author jcamelon
*
*/
-public class NamespaceDefinition extends Declaration implements IScope {
+public class NamespaceDefinition extends Declaration implements IScope, IOffsettable {
private List declarations = new LinkedList();
private IScope ownerScope;
private Name name = null;
+ private int startingOffset = 0, totalLength = 0;
public NamespaceDefinition( IScope owner )
{
@@ -69,6 +70,34 @@
*/
public void setName(Name name) {
this.name = name;
+ }
+
+ /**
+ * @return
+ */
+ public int getStartingOffset() {
+ return startingOffset;
+ }
+
+ /**
+ * @return
+ */
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+ /**
+ * @param i
+ */
+ public void setStartingOffset(int i) {
+ startingOffset = i;
+ }
+
+ /**
+ * @param i
+ */
+ public void setTotalLength(int i) {
+ totalLength = i;
}
}
Index: dom/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java,v
retrieving revision 1.4
diff -u -r1.4 ParameterDeclaration.java
--- dom/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java 29 Mar 2003 05:35:47 -0000 1.4
+++ dom/org/eclipse/cdt/internal/core/dom/ParameterDeclaration.java 8 Apr 2003 01:07:27 -0000
@@ -15,10 +15,28 @@
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
-public class ParameterDeclaration extends Declaration implements DeclSpecifier.Container {
+public class ParameterDeclaration extends Declaration implements DeclSpecifier.Container, TypeSpecifier.IOwner {
DeclSpecifier declSpec = null;
+ private TypeSpecifier typeSpecifier;
+
+ /**
+ * Returns the typeSpecifier.
+ * @return TypeSpecifier
+ */
+ public TypeSpecifier getTypeSpecifier() {
+ return typeSpecifier;
+ }
+ /**
+ * Sets the typeSpecifier.
+ * @param typeSpecifier The typeSpecifier to set
+ */
+ public void setTypeSpecifier(TypeSpecifier typeSpecifier) {
+ getDeclSpecifier().setType(DeclSpecifier.t_type);
+ this.typeSpecifier = typeSpecifier;
+ }
+
/**
* @see org.eclipse.cdt.internal.core.dom.DeclarationSpecifier.CElementWrapper#getDeclSpecifier()
*/
Index: dom/org/eclipse/cdt/internal/core/dom/PreprocessorStatement.java
===================================================================
RCS file: dom/org/eclipse/cdt/internal/core/dom/PreprocessorStatement.java
diff -N dom/org/eclipse/cdt/internal/core/dom/PreprocessorStatement.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ dom/org/eclipse/cdt/internal/core/dom/PreprocessorStatement.java 8 Apr 2003 01:07:27 -0000
@@ -0,0 +1,66 @@
+/**********************************************************************
+ * Created on Apr 7, 2003
+ *
+ * Copyright (c) 2002,2003 IBM/Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Ltd. - Rational Software - Initial API and implementation
+************************************************************************/
+package org.eclipse.cdt.internal.core.dom;
+
+/**
+ * @author jcamelon
+ *
+ */
+public class PreprocessorStatement {
+
+ private final int startingOffset, totalLength;
+ final private int nameOffset;
+ final private String name;
+
+ public PreprocessorStatement( String name, int nameOffset, int startingOffset, int totalLength )
+ {
+ this.name =name;
+ this.nameOffset = nameOffset;
+ this.startingOffset = startingOffset;
+ this.totalLength = totalLength;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.IOffsettable#getStartingOffset()
+ */
+ public int getStartingOffset() {
+ return startingOffset;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.IOffsettable#getTotalLength()
+ */
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return
+ */
+ public int getNameOffset() {
+ return nameOffset;
+ }
+
+ public int getNameLength() {
+ return name.length();
+ }
+
+}
Index: dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java,v
retrieving revision 1.4
diff -u -r1.4 SimpleDeclaration.java
--- dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java 29 Mar 2003 05:35:47 -0000 1.4
+++ dom/org/eclipse/cdt/internal/core/dom/SimpleDeclaration.java 8 Apr 2003 01:07:27 -0000
@@ -4,11 +4,15 @@
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
-public class SimpleDeclaration extends Declaration implements DeclSpecifier.Container {
+public class SimpleDeclaration extends Declaration implements DeclSpecifier.Container, IOffsettable, TypeSpecifier.IOwner {
+ private int startingOffset = 0, totalLength = 0;
+ private AccessSpecifier accessSpecifier = null;
private DeclSpecifier declSpec = null;
+ private boolean isFunctionDefinition = false;
public DeclSpecifier getDeclSpecifier()
{
@@ -61,4 +65,60 @@
public void removeDeclarator(Object declarator) {
declarators.remove( declarator );
}
+ /**
+ * @return
+ */
+ public AccessSpecifier getAccessSpecifier() {
+ return accessSpecifier;
+ }
+
+ /**
+ * @param specifier
+ */
+ public void setAccessSpecifier(AccessSpecifier specifier) {
+ accessSpecifier = specifier;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isFunctionDefinition() {
+ return isFunctionDefinition;
+ }
+
+ /**
+ * @param b
+ */
+ public void setFunctionDefinition(boolean b) {
+ isFunctionDefinition = b;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.IOffsettable#getStartingOffset()
+ */
+ public int getStartingOffset() {
+ return startingOffset;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.IOffsettable#getTotalLength()
+ */
+ public int getTotalLength() {
+ return totalLength;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.IOffsettable#setStartingOffset(int)
+ */
+ public void setStartingOffset(int i) {
+ startingOffset = i;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.dom.IOffsettable#setTotalLength(int)
+ */
+ public void setTotalLength(int i) {
+ totalLength = i;
+ }
+
}
Index: dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java,v
retrieving revision 1.4
diff -u -r1.4 TranslationUnit.java
--- dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java 29 Mar 2003 05:35:47 -0000 1.4
+++ dom/org/eclipse/cdt/internal/core/dom/TranslationUnit.java 8 Apr 2003 01:07:28 -0000
@@ -1,5 +1,6 @@
package org.eclipse.cdt.internal.core.dom;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -10,6 +11,8 @@
public class TranslationUnit implements IScope {
private List declarations = new LinkedList();
+ private List macros = new ArrayList();
+ private List inclusions = new ArrayList();
public void addDeclaration(Declaration declaration) {
declarations.add(declaration);
@@ -18,4 +21,28 @@
public List getDeclarations() {
return Collections.unmodifiableList( declarations );
}
+
+ /**
+ * @return
+ */
+ public List getInclusions() {
+ return Collections.unmodifiableList( inclusions );
+ }
+
+ /**
+ * @return
+ */
+ public List getMacros() {
+ return Collections.unmodifiableList( macros );
+ }
+
+ public void addMacro(Macro macro) {
+ macros.add(macro);
+ }
+
+ public void addInclusion(Inclusion inclusion) {
+ inclusions.add(inclusion);
+ }
+
+
}
Index: dom/org/eclipse/cdt/internal/core/dom/TypeSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/TypeSpecifier.java,v
retrieving revision 1.2
diff -u -r1.2 TypeSpecifier.java
--- dom/org/eclipse/cdt/internal/core/dom/TypeSpecifier.java 4 Mar 2003 18:25:40 -0000 1.2
+++ dom/org/eclipse/cdt/internal/core/dom/TypeSpecifier.java 8 Apr 2003 01:07:28 -0000
@@ -2,29 +2,28 @@
public class TypeSpecifier {
- public TypeSpecifier(SimpleDeclaration declaration) {
- this.declaration = declaration;
+ interface IOwner
+ {
+ public TypeSpecifier getTypeSpecifier();
+ public void setTypeSpecifier( TypeSpecifier typespec );
+ }
+
+ public TypeSpecifier(IOwner owner) {
+ this.owner = owner;
}
/**
* Owner declaration.
*/
- private SimpleDeclaration declaration;
+ private IOwner owner;
/**
* Returns the declaration.
* @return SimpleDeclaration
*/
- public SimpleDeclaration getDeclaration() {
- return declaration;
+ public IOwner getOwner() {
+ return owner;
}
- /**
- * Sets the declaration.
- * @param declaration The declaration to set
- */
- public void setDeclaration(SimpleDeclaration declaration) {
- this.declaration = declaration;
- }
}
Index: parser/ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/ChangeLog,v
retrieving revision 1.21
diff -u -r1.21 ChangeLog
--- parser/ChangeLog 6 Apr 2003 03:06:16 -0000 1.21
+++ parser/ChangeLog 8 Apr 2003 01:07:28 -0000
@@ -1,3 +1,13 @@
+2003-04-07 John Camelon
+ Brought DOM up to par wrt functionality with Code Model.
+ Added isFunctionDefinition() to SimpleDeclaration.
+ Added visiblity indicators for member declarations.
+ Added offset information that was previously unavailable.
+ Added preprocessor statements (inclusions, macros) to DOM.
+ Updated TypeSpecifier hierarchy to allow for parameter declarations to own elaborated types.
+ Added new constructor to parser to aid testing.
+ Fixed bug36065.
+
2003-04-04 John Camelon
Fixed defect 36073.
Fixed error handling for unterminated strings in Scanner.
Index: parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java,v
retrieving revision 1.18
diff -u -r1.18 SimpleDeclarationWrapper.java
--- parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java 4 Apr 2003 18:45:09 -0000 1.18
+++ parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java 8 Apr 2003 01:07:29 -0000
@@ -235,7 +235,7 @@
this.functionDefinition = functionDefinition;
}
- private AccessSpecifier currentVisibility = new AccessSpecifier();
+ private AccessSpecifier currentVisibility = new AccessSpecifier( AccessSpecifier.v_unknown );
/**
* @return int
*/
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.23
diff -u -r1.23 Parser.java
--- parser/org/eclipse/cdt/internal/core/parser/Parser.java 6 Apr 2003 03:06:16 -0000 1.23
+++ parser/org/eclipse/cdt/internal/core/parser/Parser.java 8 Apr 2003 01:07:30 -0000
@@ -52,6 +52,13 @@
), c, false);
}
+ public Parser(String code, IParserCallback c, boolean quickParse ) throws Exception {
+ this(new Scanner().initialize( new StringReader( code ), null
+), c, quickParse);
+ }
+
+
+
public Parser(InputStream stream, IParserCallback c, boolean quick) throws Exception {
this(new Scanner().initialize( new InputStreamReader(stream), null ),
c, quick);
@@ -1069,7 +1076,8 @@
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 )
+ if( LT(2) != Token.tINTEGER && LT(2) != Token.t_false && LT(2) != Token.t_true && LT(2) != Token.tSTRING &&
+ LT(2) != Token.tLSTRING )
{
// parameterDeclarationClause
Object clause = null;
Index: parser/org/eclipse/cdt/internal/core/parser/Scanner.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Scanner.java,v
retrieving revision 1.16
diff -u -r1.16 Scanner.java
--- parser/org/eclipse/cdt/internal/core/parser/Scanner.java 6 Apr 2003 03:06:16 -0000 1.16
+++ parser/org/eclipse/cdt/internal/core/parser/Scanner.java 8 Apr 2003 01:07:31 -0000
@@ -718,7 +718,7 @@
currentContext);
} else if (c == '#') {
- int beginningOffset = currentContext.getOffset();
+ int beginningOffset = currentContext.getOffset() - 1;
// lets prepare for a preprocessor statement
StringBuffer buff = new StringBuffer();
buff.append((char) c);
Index: parser/org/eclipse/cdt/internal/core/parser/util/AccessSpecifier.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/AccessSpecifier.java,v
retrieving revision 1.1
diff -u -r1.1 AccessSpecifier.java
--- parser/org/eclipse/cdt/internal/core/parser/util/AccessSpecifier.java 29 Mar 2003 05:35:48 -0000 1.1
+++ parser/org/eclipse/cdt/internal/core/parser/util/AccessSpecifier.java 8 Apr 2003 01:07:32 -0000
@@ -21,9 +21,14 @@
public static final int v_private = 0;
public static final int v_protected = 1;
public static final int v_public = 2;
+ public static final int v_unknown = 3;
private int access;
public void setAccess(int access) { this.access = access; }
public int getAccess() { return access; }
+ public AccessSpecifier( int value )
+ {
+ setAccess( value );
+ }
}