mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Patch for John Camelon:
CORE Updated Scanner to convert ungodly control-characters to ' '. Fixed logic error in model\SimpleDeclarationWrapper. Added operator support to grammar (conversion and overloading). Fixed parser/util/Name.toString() to support non-qualified yet multi-part names.
This commit is contained in:
parent
696b775d09
commit
46d2f50c48
7 changed files with 128 additions and 19 deletions
|
@ -1,3 +1,9 @@
|
|||
2003-04-01 John Camelon
|
||||
Updated Scanner to convert control-characters to ' '.
|
||||
Fixed logic error in SimpleDeclarationWrapper.
|
||||
Added operator support to grammar.
|
||||
Fixed Name.toString() to support non-qualified yet multi-part names.
|
||||
|
||||
2003-04-01 Andrew Niefer
|
||||
Parser Symbol Table, modified lookup with respect to resolving ambiguous names,
|
||||
reducing the number of temporary lists/sets. Modified adding using declarations
|
||||
|
|
|
@ -354,8 +354,8 @@ org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(T
|
|||
elem.setElementName( elementName );
|
||||
if( wrapper.getName() != null )
|
||||
{
|
||||
elem.setIdPos(wrapper.getName().getStartOffset(), elementName.length());
|
||||
elem.setPos(wrapper.getName().getStartOffset(), elementName.length());
|
||||
elem.setIdPos(wrapper.getName().getStartOffset(), wrapper.getName().length());
|
||||
elem.setPos(wrapper.getName().getStartOffset(), wrapper.getName().length());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -14,10 +14,6 @@ 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 SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpecifier.Container, ICElementWrapper {
|
||||
|
||||
|
@ -29,7 +25,7 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
|
|||
|
||||
public SimpleDeclarationWrapper( IParent item )
|
||||
{
|
||||
this.element = item;
|
||||
this.parent = item;
|
||||
}
|
||||
|
||||
public SimpleDeclarationWrapper()
|
||||
|
@ -139,8 +135,8 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpeci
|
|||
if( currentDeclarator.getName() != null )
|
||||
{
|
||||
// hook up the offsets
|
||||
declaration.setIdPos( currentDeclarator.getName().getStartOffset(), declaratorName.length());
|
||||
declaration.setPos( currentDeclarator.getName().getStartOffset(), declaratorName.length() );
|
||||
declaration.setIdPos( currentDeclarator.getName().getStartOffset(), currentDeclarator.getName().length() );
|
||||
declaration.setPos( currentDeclarator.getName().getStartOffset(), currentDeclarator.getName().length());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -914,7 +914,7 @@ c, quick);
|
|||
*/
|
||||
protected Object initDeclarator( Object owner ) throws Backtrack {
|
||||
Object declarator = declarator( owner );
|
||||
|
||||
|
||||
// handle = initializerClause
|
||||
if (LT(1) == Token.tASSIGN) {
|
||||
consume();
|
||||
|
@ -1011,9 +1011,60 @@ c, quick);
|
|||
return declarator;
|
||||
}
|
||||
|
||||
name();
|
||||
try{ callback.declaratorId(declarator);} catch( Exception e ) {}
|
||||
|
||||
if( LT(1) == Token.t_operator )
|
||||
{
|
||||
// we know this is an operator
|
||||
Token operatorToken = consume( Token.t_operator );
|
||||
Token toSend = null;
|
||||
if( LA(1).isOperator() || LT(1) == Token.tLPAREN || LT(1) == Token.tLBRACKET )
|
||||
{
|
||||
if( (LT(1) == Token.t_new || LT(1) == Token.t_delete ) &&
|
||||
LT(2) == Token.tLBRACKET && LT(3) == Token.tRBRACKET )
|
||||
{
|
||||
consume();
|
||||
consume( Token.tLBRACKET );
|
||||
toSend = consume( Token.tRBRACKET );
|
||||
// vector new and delete operators
|
||||
}
|
||||
else if ( LT(1) == Token.tLPAREN && LT(2) == Token.tRPAREN )
|
||||
{
|
||||
// operator ()
|
||||
consume( Token.tLPAREN );
|
||||
toSend = toSend = consume( Token.tRPAREN );
|
||||
}
|
||||
else if ( LT(1) == Token.tLBRACKET && LT(2) == Token.tRBRACKET )
|
||||
{
|
||||
consume( Token.tLBRACKET );
|
||||
toSend = consume( Token.tRBRACKET );
|
||||
}
|
||||
else if( LA(1).isOperator() )
|
||||
toSend = consume();
|
||||
else
|
||||
throw backtrack;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// temporary
|
||||
while( LT(1) != Token.tLPAREN )
|
||||
{
|
||||
toSend = consume();
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
callback.nameBegin( operatorToken );
|
||||
callback.nameEnd( toSend );
|
||||
} catch( Exception e ) {}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
name();
|
||||
}
|
||||
|
||||
try{ callback.declaratorId(declarator);} catch( Exception e ) {}
|
||||
for (;;) {
|
||||
switch (LT(1)) {
|
||||
case Token.tLPAREN:
|
||||
|
|
|
@ -1196,7 +1196,7 @@ public class Scanner implements IScanner {
|
|||
throw new ScannerException( "Invalid character '" + (char)c + "' read @ offset " + currentContext.getOffset() + " of file " + currentContext.getFilename() );
|
||||
else
|
||||
{
|
||||
c = getChar();
|
||||
c = ' ';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,54 @@ public class Token {
|
|||
private Token next;
|
||||
public Token getNext() { return next; }
|
||||
public void setNext(Token t) { next = t; }
|
||||
|
||||
public boolean isOperator()
|
||||
{
|
||||
switch( getType() )
|
||||
{
|
||||
case Token.t_new:
|
||||
case Token.t_delete:
|
||||
case Token.tPLUS:
|
||||
case Token.tMINUS:
|
||||
case Token.tSTAR:
|
||||
case Token.tDIV:
|
||||
case Token.tXOR:
|
||||
case Token.tMOD:
|
||||
case Token.tAMPER:
|
||||
case Token.tBITOR:
|
||||
case Token.tCOMPL:
|
||||
case Token.tNOT:
|
||||
case Token.tASSIGN:
|
||||
case Token.tLT:
|
||||
case Token.tGT:
|
||||
case Token.tPLUSASSIGN:
|
||||
case Token.tMINUSASSIGN:
|
||||
case Token.tSTARASSIGN:
|
||||
case Token.tDIVASSIGN:
|
||||
case Token.tMODASSIGN:
|
||||
case Token.tBITORASSIGN:
|
||||
case Token.tAMPERASSIGN:
|
||||
case Token.tXORASSIGN:
|
||||
case Token.tSHIFTL:
|
||||
case Token.tSHIFTR:
|
||||
case Token.tSHIFTLASSIGN:
|
||||
case Token.tSHIFTRASSIGN:
|
||||
case Token.tEQUAL:
|
||||
case Token.tNOTEQUAL:
|
||||
case Token.tLTEQUAL:
|
||||
case Token.tGTEQUAL:
|
||||
case Token.tAND:
|
||||
case Token.tOR:
|
||||
case Token.tINCR:
|
||||
case Token.tDECR:
|
||||
case Token.tCOMMA:
|
||||
case Token.tARROW:
|
||||
case Token.tARROWSTAR:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Token types
|
||||
static public final int tIDENTIFIER = 1;
|
||||
|
@ -83,7 +131,6 @@ public class Token {
|
|||
static public final int tNOT = 36;
|
||||
static public final int tEQUAL = 37;
|
||||
static public final int tASSIGN = 38;
|
||||
static public final int tSHIFLASSIGN = 39;
|
||||
static public final int tSHIFTL = 40;
|
||||
static public final int tLTEQUAL = 41;
|
||||
static public final int tLT = 42;
|
||||
|
|
|
@ -35,13 +35,22 @@ public class Name {
|
|||
|
||||
public String toString() {
|
||||
Token t = nameStart;
|
||||
String name = t.getImage();
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( t.getImage() );
|
||||
if( t.getType() == Token.t_operator )
|
||||
buffer.append( " " );
|
||||
|
||||
while (t != nameEnd) {
|
||||
t = t.getNext();
|
||||
name += t.getImage();
|
||||
|
||||
buffer.append( t.getImage() );
|
||||
}
|
||||
|
||||
return name;
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public int length()
|
||||
{
|
||||
return getEndOffset() - getStartOffset() + nameEnd.getImage().length();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue