Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Camelon2003-05-05 20:31:08 +0000
committerJohn Camelon2003-05-05 20:31:08 +0000
commit23a5c599d49f0ee7db69312712d32106275fee34 (patch)
treedd85a57024367ecead886257c95321a22d5544cf
parent4a88230536b781dbefc10d54b49be6f68966fa27 (diff)
downloadorg.eclipse.cdt-23a5c599d49f0ee7db69312712d32106275fee34.tar.gz
org.eclipse.cdt-23a5c599d49f0ee7db69312712d32106275fee34.tar.xz
org.eclipse.cdt-23a5c599d49f0ee7db69312712d32106275fee34.zip
Symbol table/Parser interworking.
First blood has been drawn.
-rw-r--r--core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/DOMBuilder.java10
-rw-r--r--core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java15
-rw-r--r--core/org.eclipse.cdt.core/parser/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java1
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ISymbol.java21
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/Parser.java101
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java2
9 files changed, 137 insertions, 28 deletions
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 c0cde71fb99..f6d312c73c1 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
@@ -935,5 +935,15 @@ public class DOMBuilder implements IParserCallback
BitField b = (BitField)bitfield;
b.getOwnerDeclarator().setBitField( b );
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierType(java.lang.Object, java.lang.Object)
+ */
+ public void simpleDeclSpecifierType(Object declaration, Object type) {
+ if( type instanceof TypeSpecifier )
+ {
+ System.out.println( "Told you so!");
+ }
+ }
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java
index bad26a37971..9e495ef0d04 100644
--- a/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java
+++ b/core/org.eclipse.cdt.core/dom/org/eclipse/cdt/internal/core/dom/ElaboratedTypeSpecifier.java
@@ -29,5 +29,20 @@ public class ElaboratedTypeSpecifier extends TypeSpecifier {
public void setName(Name n) { name = n; }
public Name getName() { return name; }
+ private ClassSpecifier classSpec = null;
+
+ /**
+ * @return
+ */
+ public ClassSpecifier getClassSpec() {
+ return classSpec;
+ }
+
+ /**
+ * @param specifier
+ */
+ public void setClassSpec(ClassSpecifier specifier) {
+ classSpec = specifier;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/ChangeLog b/core/org.eclipse.cdt.core/parser/ChangeLog
index 8cacfb59374..1d7500b19d8 100644
--- a/core/org.eclipse.cdt.core/parser/ChangeLog
+++ b/core/org.eclipse.cdt.core/parser/ChangeLog
@@ -1,3 +1,6 @@
+2003-05-05 John Camelon/Andrew Niefer
+ Added Symboltable infrastructure into main parser.
+
2003-05-05 Andrew Niefer
Structural changes to ParserSymbolTable:
- moved TypeInfo & Declaration inside ParserSymbolTable
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java
index 27748ef74dc..1b7d3448781 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ExpressionEvaluator.java
@@ -730,5 +730,11 @@ public class ExpressionEvaluator implements IParserCallback {
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#endBitfield(java.lang.Object)
*/
public void endBitfield(Object bitfield) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierType(java.lang.Object, java.lang.Object)
+ */
+ public void simpleDeclSpecifierType(Object declaration, Object type) {
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java
index 51322657359..c1c67b1c496 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/IParserCallback.java
@@ -24,6 +24,7 @@ public interface IParserCallback {
public Object simpleDeclarationBegin(Object Container, Token firstToken);
public void simpleDeclSpecifier(Object Container, Token specifier);
public void simpleDeclSpecifierName( Object declaration );
+ public void simpleDeclSpecifierType( Object declaration, Object type );
public void simpleDeclarationEnd(Object declaration, Token lastToken);
public Object parameterDeclarationBegin( Object Container );
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ISymbol.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ISymbol.java
new file mode 100644
index 00000000000..ade7da35cb2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ISymbol.java
@@ -0,0 +1,21 @@
+/**********************************************************************
+ * Copyright (c) 2002,2003 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 Rational Software - Initial API and implementation
+***********************************************************************/
+package org.eclipse.cdt.internal.core.parser;
+
+/**
+ * @author jcamelon
+ *
+ */
+public interface ISymbol {
+
+ public Object getObject();
+
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java
index 23986fdef94..2118a21229f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/NullParserCallback.java
@@ -635,4 +635,10 @@ public class NullParserCallback implements IParserCallback {
public void endBitfield(Object bitfield) {
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.internal.core.parser.IParserCallback#simpleDeclSpecifierType(java.lang.Object, java.lang.Object)
+ */
+ public void simpleDeclSpecifierType(Object declaration, Object type) {
+ }
+
}
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 5bb155eed08..32d545b59ff 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
@@ -16,6 +16,8 @@ import java.io.InputStreamReader;
import java.io.StringReader;
import org.eclipse.cdt.internal.core.model.Util;
+import org.eclipse.cdt.internal.core.parser.ParserSymbolTable.Declaration;
+import org.eclipse.cdt.internal.core.parser.ParserSymbolTable.TypeInfo;
/**
* This is our first implementation of the IParser interface, serving as a parser for
@@ -33,6 +35,7 @@ public class Parser implements IParser {
private boolean quickParse = false; // are we doing the high-level parse, or an in depth parse?
private boolean parsePassed = true; // did the parse pass?
private boolean cppNature = true; // true for C++, false for C
+ private ParserSymbolTable pst = new ParserSymbolTable(); // names
/**
* This is the single entry point for setting parsePassed to
@@ -160,12 +163,13 @@ c, quickParse);
try { callback.setParser( this ); } catch( Exception e) {}
Object translationUnit = null;
try{ translationUnit = callback.translationUnitBegin();} catch( Exception e ) {}
+ pst.getCompilationUnit().setObject(translationUnit);
Token lastBacktrack = null;
Token checkToken;
while (true) {
try {
checkToken = LA(1);
- declaration( translationUnit );
+ declaration( translationUnit, pst.getCompilationUnit() );
if( LA(1) == checkToken )
errorHandling();
} catch (EndOfFile e) {
@@ -341,7 +345,7 @@ c, quickParse);
default:
try
{
- declaration(linkageSpec);
+ declaration(linkageSpec, null);
}
catch( Backtrack bt )
{
@@ -359,7 +363,7 @@ c, quickParse);
}
else // single declaration
{
- declaration( linkageSpec );
+ declaration( linkageSpec, null );
try{ callback.linkageSpecificationEnd( linkageSpec );} catch( Exception e ) {}
}
}
@@ -393,7 +397,7 @@ c, quickParse);
// explicit-instantiation
Object instantiation = null;
try { instantiation = callback.explicitInstantiationBegin( container ); } catch( Exception e ) { }
- declaration( instantiation );
+ declaration( instantiation, null );
try { callback.explicitInstantiationEnd( instantiation ); } catch( Exception e ) { }
return;
}
@@ -406,7 +410,7 @@ c, quickParse);
// explicit-specialization
Object specialization = null;
try{ specialization = callback.explicitSpecializationBegin( container ); } catch( Exception e ) { }
- declaration( specialization );
+ declaration( specialization, null );
try{ callback.explicitSpecializationEnd( specialization ); } catch( Exception e ) { }
return;
}
@@ -418,7 +422,7 @@ c, quickParse);
try{ templateDeclaration = callback.templateDeclarationBegin( container, firstToken ); } catch ( Exception e ) {}
templateParameterList( templateDeclaration );
consume( Token.tGT );
- declaration( templateDeclaration );
+ declaration( templateDeclaration, null );
try{ callback.templateDeclarationEnd( templateDeclaration, lastToken ); } catch( Exception e ) {}
} catch( Backtrack bt )
@@ -548,7 +552,7 @@ c, quickParse);
* @param container IParserCallback object which serves as the owner scope for this declaration.
* @throws Backtrack request a backtrack
*/
- protected void declaration( Object container ) throws Backtrack {
+ protected void declaration( Object container, Declaration scope ) throws Backtrack {
switch (LT(1)) {
case Token.t_asm:
consume( Token.t_asm );
@@ -561,7 +565,7 @@ c, quickParse);
try{ callback.asmDefinition( container, assembly );} catch( Exception e ) {}
return;
case Token.t_namespace:
- namespaceDefinition( container );
+ namespaceDefinition( container, scope );
return;
case Token.t_using:
usingClause( container );
@@ -580,13 +584,13 @@ c, quickParse);
Token mark = mark();
try
{
- simpleDeclaration( container, true ); // try it first with the original strategy
+ simpleDeclaration( container, true, scope ); // try it first with the original strategy
}
catch( Backtrack bt)
{
// did not work
backup( mark );
- simpleDeclaration( container, false ); // try it again with the second strategy
+ simpleDeclaration( container, false, scope ); // try it again with the second strategy
}
}
}
@@ -602,21 +606,61 @@ c, quickParse);
* @throws Backtrack request a backtrack
*/
- protected void namespaceDefinition( Object container ) throws Backtrack
+ protected void namespaceDefinition( Object container, Declaration scope ) throws Backtrack
{
Object namespace = null;
- try{ namespace = callback.namespaceDefinitionBegin( container, consume( Token.t_namespace) );} catch( Exception e ) {}
+ boolean redeclared = false;
+ Token firstToken = consume( Token.t_namespace );
- // optional name
+ // optional name
+ String identifier = "";
if( LT(1) == Token.tIDENTIFIER )
{
- name();
- try{ callback.namespaceDefinitionId( namespace );} catch( Exception e ) {}
+ identifier = LA(1).getImage();
+ identifier();
}
if( LT(1) == Token.tLBRACE )
{
- consume();
+ consume( Token.tLBRACE);
+
+ Declaration namespaceSymbol = null;
+ try {
+ namespaceSymbol = scope.Lookup( identifier );
+ } catch (ParserSymbolTableException e1) {
+ // should not get ambiguity here
+ }
+
+ if( namespaceSymbol == null )
+ {
+ namespaceSymbol = pst.new Declaration( identifier );
+ try
+ {
+ namespaceSymbol.setType( TypeInfo.t_namespace );
+ }
+ catch( ParserSymbolTableException pste )
+ {
+ // should never happen
+ }
+ try{ namespace = callback.namespaceDefinitionBegin( container, firstToken );} catch( Exception e ) {}
+ namespaceSymbol.setObject( namespace );
+ try {
+ scope.addDeclaration( namespaceSymbol );
+ } catch (ParserSymbolTableException e2) {
+ // TODO ambiguity?
+ }
+ if( !identifier.equals( "" ))
+ try{ callback.namespaceDefinitionId( namespace );} catch( Exception e ) {}
+ }
+ else
+ {
+ if( namespaceSymbol.getType() != TypeInfo.t_namespace )
+ throw backtrack;
+ namespace = namespaceSymbol.getObject();
+ redeclared = true;
+ }
+
+
namepsaceDeclarationLoop:
while (LT(1) != Token.tRBRACE) {
Token checkToken = LA(1);
@@ -627,7 +671,7 @@ c, quickParse);
default:
try
{
- declaration(namespace);
+ declaration(namespace, namespaceSymbol);
}
catch( Backtrack bt )
{
@@ -641,7 +685,9 @@ c, quickParse);
}
// consume the }
- try{ callback.namespaceDefinitionEnd( namespace, consume( Token.tRBRACE ));} catch( Exception e ) {}
+ Token lastToken =consume( Token.tRBRACE );
+ if( ! redeclared )
+ try{ callback.namespaceDefinitionEnd( namespace, lastToken );} catch( Exception e ) {}
}
else
{
@@ -669,10 +715,10 @@ c, quickParse);
* @param tryConstructor true == take strategy1 (constructor ) : false == take strategy 2 ( pointer to function)
* @throws Backtrack request a backtrack
*/
- protected void simpleDeclaration( Object container, boolean tryConstructor ) throws Backtrack {
+ protected void simpleDeclaration( Object container, boolean tryConstructor, Declaration scope ) throws Backtrack {
Object simpleDecl = null;
try{ simpleDecl = callback.simpleDeclarationBegin( container, LA(1));} catch( Exception e ) {}
- declSpecifierSeq(simpleDecl, false, tryConstructor);
+ declSpecifierSeq(simpleDecl, false, tryConstructor, scope);
Object declarator = null;
if (LT(1) != Token.tSEMI)
@@ -800,7 +846,7 @@ c, quickParse);
Token current = LA(1);
Object parameterDecl = null;
try{ parameterDecl = callback.parameterDeclarationBegin( containerObject );} catch( Exception e ) {}
- declSpecifierSeq( parameterDecl, true, false );
+ declSpecifierSeq( parameterDecl, true, false, null );
if (LT(1) != Token.tSEMI)
try {
@@ -956,7 +1002,7 @@ c, quickParse);
* @param tryConstructor true for constructor, false for pointer to function strategy
* @throws Backtrack request a backtrack
*/
- protected void declSpecifierSeq( Object decl, boolean parm, boolean tryConstructor ) throws Backtrack {
+ protected void declSpecifierSeq( Object decl, boolean parm, boolean tryConstructor, Declaration scope ) throws Backtrack {
Flags flags = new Flags( parm, tryConstructor );
declSpecifiers:
for (;;) {
@@ -1024,6 +1070,7 @@ c, quickParse);
return;
if ( lookAheadForDeclarator( flags ) )
return;
+
try{ callback.simpleDeclSpecifier(decl,LA(1));} catch( Exception e ) {}
name();
try{ callback.simpleDeclSpecifierName( decl );} catch( Exception e ) {}
@@ -1038,7 +1085,7 @@ c, quickParse);
{
try
{
- classSpecifier(decl);
+ classSpecifier(decl, scope);
return;
}
catch( Backtrack bt )
@@ -1804,7 +1851,7 @@ c, quickParse);
* @param owner IParserCallback object that represents the declaration that owns this classSpecifier
* @throws Backtrack request a backtrack
*/
- protected void classSpecifier( Object owner ) throws Backtrack {
+ protected void classSpecifier( Object owner, Declaration scope ) throws Backtrack {
Token classKey = null;
Token mark = mark();
@@ -1862,7 +1909,7 @@ c, quickParse);
default:
try
{
- declaration(classSpec);
+ declaration(classSpec, scope);
}
catch( Backtrack bt )
{
@@ -2046,7 +2093,7 @@ c, quickParse);
while (LT(1) == Token.t_catch) {
consume();
consume(Token.tLPAREN);
- declaration(null); // was exceptionDeclaration
+ declaration(null, null); // was exceptionDeclaration
consume(Token.tRPAREN);
compoundStatement();
}
@@ -2078,7 +2125,7 @@ c, quickParse);
}
// declarationStatement
- declaration(null);
+ declaration(null, null);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java
index af4b4f370fd..799f93617ac 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/ParserSymbolTable.java
@@ -1323,7 +1323,7 @@ public class ParserSymbolTable {
}
}
- public class Declaration implements Cloneable {
+ public class Declaration implements Cloneable, ISymbol {
/**
* Constructor for Declaration.

Back to the top