mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
Patch for John Camelon:
- see ChangeLogs
This commit is contained in:
parent
5dfe2bf8c4
commit
e8808fb009
15 changed files with 292 additions and 37 deletions
|
@ -3,7 +3,6 @@ package org.eclipse.cdt.internal.core.dom;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IScope;
|
||||
import org.eclipse.cdt.internal.core.parser.util.Name;
|
||||
|
||||
public class ClassSpecifier extends TypeSpecifier implements IScope {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.eclipse.cdt.internal.core.dom;
|
||||
|
||||
|
||||
import org.eclipse.cdt.core.dom.IScope;
|
||||
import org.eclipse.cdt.internal.core.parser.IParserCallback;
|
||||
import org.eclipse.cdt.internal.core.parser.Token;
|
||||
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
|
||||
|
@ -277,4 +276,51 @@ public class DOMBuilder implements IParserCallback
|
|||
public void expressionEnd(Object expression) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierAbort(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierAbort(Object classSpecifier) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierSafe(Object classSpecifier) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
|
||||
*/
|
||||
public Object elaboratedTypeSpecifierBegin(Object container, Token classKey) {
|
||||
int kind = ClassSpecifier.t_struct;
|
||||
|
||||
switch (classKey.getType()) {
|
||||
case Token.t_class:
|
||||
kind = ClassSpecifier.t_class;
|
||||
break;
|
||||
case Token.t_struct:
|
||||
kind = ClassSpecifier.t_struct;
|
||||
break;
|
||||
case Token.t_union:
|
||||
kind = ClassSpecifier.t_union;
|
||||
break;
|
||||
}
|
||||
|
||||
ElaboratedTypeSpecifier elab = new ElaboratedTypeSpecifier( kind, (SimpleDeclaration)container );
|
||||
return elab;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierEnd(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierEnd(Object elab) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierName(Object elab) {
|
||||
((ElaboratedTypeSpecifier)elab).setName( currName );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.eclipse.cdt.internal.core.dom;
|
||||
|
||||
import org.eclipse.cdt.internal.core.parser.util.Name;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
* 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 ElaboratedTypeSpecifier extends TypeSpecifier {
|
||||
|
||||
public static final int t_class = 0;
|
||||
public static final int t_struct = 1;
|
||||
public static final int t_union = 2;
|
||||
public static final int t_enum = 3;
|
||||
|
||||
private final int classKey;
|
||||
public int getClassKey() { return 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);
|
||||
this.classKey = classKey;
|
||||
}
|
||||
|
||||
private Name name;
|
||||
public void setName(Name n) { name = n; }
|
||||
public Name getName() { return name; }
|
||||
|
||||
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
package org.eclipse.cdt.core.dom;
|
||||
package org.eclipse.cdt.internal.core.dom;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.Declaration;
|
||||
|
||||
/**
|
||||
* A scope contains a set of declarations that are defined in that scope.
|
||||
*/
|
||||
public interface IScope {
|
||||
* A scope contains a set of declarations that are defined in that
|
||||
scope. */ public interface IScope {
|
||||
|
||||
public void addDeclaration(Declaration declaration);
|
||||
public List getDeclarations();
|
|
@ -3,7 +3,6 @@ package org.eclipse.cdt.internal.core.dom;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IScope;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.eclipse.cdt.internal.core.dom;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IScope;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2003-03-13 John Camelon
|
||||
Moved ## token to IScanner from Scanner.
|
||||
Updated IParserCallback and implementations to deal with Elaborated Type Specifiers.
|
||||
Moved IScope into the internal DOM package.
|
||||
|
||||
2003-03-11 John Camelon
|
||||
added ChangeLog to parser directory
|
||||
updated IParserCallback (and all implementors) for expressions
|
||||
|
|
|
@ -35,8 +35,6 @@ public class NewModelBuilder implements IParserCallback {
|
|||
return translationUnit;
|
||||
}
|
||||
|
||||
|
||||
private Token classKey;
|
||||
/**
|
||||
* @see org.eclipse.cdt.core.newparser.IParserCallback#beginClass(String, String)
|
||||
*/
|
||||
|
@ -55,24 +53,21 @@ public class NewModelBuilder implements IParserCallback {
|
|||
default:
|
||||
kind = ICElement.C_UNION;
|
||||
}
|
||||
this.classKey = classKey;
|
||||
|
||||
Structure elem = new Structure( c.getParent(), kind, null );
|
||||
c.getParent().addChild(elem);
|
||||
return new SimpleDeclarationWrapper( elem );
|
||||
SimpleDeclarationWrapper wrapper = new SimpleDeclarationWrapper();
|
||||
wrapper.setKind( kind );
|
||||
wrapper.setParent( c.getParent() );
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#classSpecifierName()
|
||||
*/
|
||||
public void classSpecifierName(Object classSpecifier) {
|
||||
|
||||
SimpleDeclarationWrapper container = (SimpleDeclarationWrapper)classSpecifier;
|
||||
String name = currName.toString();
|
||||
Structure elem = ((Structure)container.getElement());
|
||||
elem.setElementName( name );
|
||||
elem.setIdPos(currName.getStartOffset(), name.length());
|
||||
elem.setPos(currName.getStartOffset(), name.length());
|
||||
public void classSpecifierName(Object classSpecifier)
|
||||
{
|
||||
SimpleDeclarationWrapper wrapper = (SimpleDeclarationWrapper)classSpecifier;
|
||||
wrapper.setName( currName );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -312,4 +307,43 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
|
|||
public void expressionEnd(Object expression) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierAbort(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierAbort(Object classSpecifier) {
|
||||
classSpecifier = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierSafe(Object classSpecifier) {
|
||||
SimpleDeclarationWrapper wrapper = (SimpleDeclarationWrapper)classSpecifier;
|
||||
Structure elem = new Structure( wrapper.getParent(), wrapper.getKind(), null );
|
||||
wrapper.setElement( elem );
|
||||
wrapper.getParent().addChild(elem);
|
||||
String name = currName.toString();
|
||||
elem.setElementName( name );
|
||||
elem.setIdPos(currName.getStartOffset(), name.length());
|
||||
elem.setPos(currName.getStartOffset(), name.length());
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
|
||||
*/
|
||||
public Object elaboratedTypeSpecifierBegin(Object container, Token classKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierEnd(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierEnd(Object elab) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierName(Object elab) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.model.IStructure;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.parser.util.DeclSpecifier;
|
||||
import org.eclipse.cdt.internal.core.parser.util.Name;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -19,6 +20,8 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
|
|||
|
||||
private CElement element = null;
|
||||
private CElement parent = null;
|
||||
int kind;
|
||||
private Name name = null;
|
||||
|
||||
public SimpleDeclarationWrapper( CElement item )
|
||||
{
|
||||
|
@ -162,4 +165,36 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
|
|||
declarators.remove( declarator );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name.
|
||||
* @return Name
|
||||
*/
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
* @param name The name to set
|
||||
*/
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kind.
|
||||
* @return int
|
||||
*/
|
||||
public int getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the kind.
|
||||
* @param kind The kind to set
|
||||
*/
|
||||
public void setKind(int kind) {
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -269,4 +269,35 @@ public class ExpressionEvaluator implements IParserCallback {
|
|||
public void expressionEnd(Object expression) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierAbort(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierAbort(Object classSpecifier) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierSafe(Object classSpecifier) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
|
||||
*/
|
||||
public Object elaboratedTypeSpecifierBegin(Object container, Token classKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierEnd(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierEnd(Object elab) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierName(Object container) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ public interface IParserCallback {
|
|||
|
||||
public Object classSpecifierBegin(Object container, Token classKey);
|
||||
public void classSpecifierName(Object classSpecifier);
|
||||
public void classSpecifierAbort( Object classSpecifier );
|
||||
public void classSpecifierSafe( Object classSpecifier );
|
||||
public void classSpecifierEnd(Object classSpecifier);
|
||||
|
||||
public Object baseSpecifierBegin( Object containingClassSpec );
|
||||
|
@ -51,8 +53,12 @@ public interface IParserCallback {
|
|||
public void baseSpecifierVirtual( Object baseSpecifier, boolean virtual );
|
||||
public void baseSpecifierEnd( Object baseSpecifier );
|
||||
|
||||
public Object expressionBegin( Object container );
|
||||
public void expressionOperator(Token operator) throws Exception;
|
||||
public void expressionTerminal(Token terminal) throws Exception;
|
||||
public void expressionEnd(Object expression );
|
||||
public Object expressionBegin( Object container );
|
||||
public void expressionOperator(Token operator) throws Exception;
|
||||
public void expressionTerminal(Token terminal) throws Exception;
|
||||
public void expressionEnd(Object expression );
|
||||
|
||||
public Object elaboratedTypeSpecifierBegin( Object container, Token classKey );
|
||||
public void elaboratedTypeSpecifierName( Object elab );
|
||||
public void elaboratedTypeSpecifierEnd( Object elab );
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import java.util.List;
|
|||
*/
|
||||
public interface IScanner {
|
||||
|
||||
public static final int tPOUNDPOUND = -6;
|
||||
|
||||
public IScanner initialize( Reader sourceToBeRead, String fileName );
|
||||
|
||||
public void addDefinition(String key, IMacroDescriptor macroToBeAdded );
|
||||
|
|
|
@ -184,4 +184,36 @@ public class NullParserCallback implements IParserCallback {
|
|||
public void expressionEnd(Object expression) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierAbort(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierAbort(Object classSpecifier) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#classSpecifierSafe(java.lang.Object)
|
||||
*/
|
||||
public void classSpecifierSafe(Object classSpecifier) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierBegin(java.lang.Object)
|
||||
*/
|
||||
public Object elaboratedTypeSpecifierBegin(Object container, Token classKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierEnd(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierEnd(Object elab) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#elaboratedTypeSpecifierName(java.lang.Object)
|
||||
*/
|
||||
public void elaboratedTypeSpecifierName(Object elab) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ c, quick);
|
|||
lastToken = currToken;
|
||||
declaration( translationUnit );
|
||||
if( currToken == lastToken )
|
||||
skipToNextSemi();
|
||||
consumeToNextSemicolon();
|
||||
} catch (Backtrack b) {
|
||||
// Mark as failure and try to reach a recovery point
|
||||
parsePassed = false;
|
||||
|
@ -92,7 +92,7 @@ c, quick);
|
|||
if (lastBacktrack != null && lastBacktrack == LA(1)) {
|
||||
// we haven't progressed from the last backtrack
|
||||
// try and find tne next definition
|
||||
skipToNextSemi();
|
||||
consumeToNextSemicolon();
|
||||
} else {
|
||||
// start again from here
|
||||
lastBacktrack = LA(1);
|
||||
|
@ -102,7 +102,7 @@ c, quick);
|
|||
callback.translationUnitEnd(translationUnit);
|
||||
}
|
||||
|
||||
public void skipToNextSemi() {
|
||||
protected void consumeToNextSemicolon() {
|
||||
for (int t = LT(1); t != Token.tEOF; t = LT(1)) {
|
||||
consume();
|
||||
// TO DO: we should really check for matching braces too
|
||||
|
@ -338,8 +338,20 @@ c, quick);
|
|||
case Token.t_class:
|
||||
case Token.t_struct:
|
||||
case Token.t_union:
|
||||
classSpecifier(decl);
|
||||
return;
|
||||
try
|
||||
{
|
||||
classSpecifier(decl);
|
||||
return;
|
||||
}
|
||||
catch( Backtrack bt )
|
||||
{
|
||||
// this is an elaborated class specifier
|
||||
Object elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );
|
||||
name();
|
||||
callback.elaboratedTypeSpecifierName( elab );
|
||||
callback.elaboratedTypeSpecifierEnd( elab );
|
||||
|
||||
}
|
||||
case Token.t_enum:
|
||||
enumSpecifier(decl);
|
||||
break;
|
||||
|
@ -638,6 +650,7 @@ c, quick);
|
|||
public void classSpecifier( Object owner ) throws Exception {
|
||||
Token classKey = null;
|
||||
|
||||
Token mark = mark();
|
||||
// class key
|
||||
switch (LT(1)) {
|
||||
case Token.t_class:
|
||||
|
@ -656,8 +669,17 @@ c, quick);
|
|||
name();
|
||||
callback.classSpecifierName(classSpec);
|
||||
}
|
||||
|
||||
//currRegion.put(name.getImage(), classKey);
|
||||
|
||||
if( LT(1) != Token.tCOLON && LT(1) != Token.tLBRACE )
|
||||
{
|
||||
// this is not a classSpecification
|
||||
callback.classSpecifierAbort( classSpec );
|
||||
classSpec = null;
|
||||
backup( mark );
|
||||
throw backtrack;
|
||||
}
|
||||
else
|
||||
callback.classSpecifierSafe( classSpec );
|
||||
|
||||
// base clause
|
||||
if (LT(1) == Token.tCOLON) {
|
||||
|
@ -693,7 +715,7 @@ c, quick);
|
|||
declaration(classSpec);
|
||||
}
|
||||
if (lastToken == currToken)
|
||||
skipToNextSemi();
|
||||
consumeToNextSemicolon();
|
||||
}
|
||||
// consume the }
|
||||
consume();
|
||||
|
|
|
@ -325,8 +325,6 @@ public class Scanner implements IScanner {
|
|||
private static final String DEFINED = "defined";
|
||||
private static final String POUND_DEFINE = "#define ";
|
||||
|
||||
public static final int tPOUNDPOUND = -6;
|
||||
|
||||
private IScannerContext currentContext;
|
||||
private Stack contextStack = new Stack();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue