mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-22 16:35:25 +02:00
Some minor fixes to the parser.
This commit is contained in:
parent
b22cebf8f8
commit
ead4068efc
3 changed files with 67 additions and 10 deletions
|
@ -85,6 +85,9 @@ public class SimpleDeclarationWrapper extends DeclSpecifier implements Declarati
|
||||||
}
|
}
|
||||||
else if( parentElement instanceof ITranslationUnit )
|
else if( parentElement instanceof ITranslationUnit )
|
||||||
{
|
{
|
||||||
|
// TODO - this was to get rid of the NULL pointer we've been seeing
|
||||||
|
if (currentDeclarator.getName() == null)
|
||||||
|
return;
|
||||||
declaration = new Variable( parentElement, currentDeclarator.getName().toString() );
|
declaration = new Variable( parentElement, currentDeclarator.getName().toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* 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:
|
||||||
|
* Rational Software - Initial API and implementation
|
||||||
|
***********************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.parser;
|
package org.eclipse.cdt.internal.core.parser;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -6,10 +17,6 @@ import java.io.StringReader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* This is an attempt at a copyright clean parser. The grammar is based
|
|
||||||
* on the ISO C++ standard
|
|
||||||
*/
|
|
||||||
public class Parser {
|
public class Parser {
|
||||||
|
|
||||||
private IParserCallback callback;
|
private IParserCallback callback;
|
||||||
|
@ -185,6 +192,16 @@ c, quick);
|
||||||
case Token.tSEMI:
|
case Token.tSEMI:
|
||||||
consume();
|
consume();
|
||||||
break;
|
break;
|
||||||
|
case Token.tCOLON:
|
||||||
|
// TODO - Initializer for constructor, for now consume
|
||||||
|
// and look for the left brace;
|
||||||
|
consume();
|
||||||
|
while (LT(1) != Token.tLBRACE) {
|
||||||
|
if (consume().getType() == Token.tEOF)
|
||||||
|
// Oops, couldn't find it
|
||||||
|
throw backtrack;
|
||||||
|
}
|
||||||
|
// Falling through on purpose
|
||||||
case Token.tLBRACE:
|
case Token.tLBRACE:
|
||||||
callback.functionBodyBegin();
|
callback.functionBodyBegin();
|
||||||
if (quickParse) {
|
if (quickParse) {
|
||||||
|
@ -333,19 +350,32 @@ c, quick);
|
||||||
* - Handle unqualifiedId
|
* - Handle unqualifiedId
|
||||||
*/
|
*/
|
||||||
public boolean name() throws Exception {
|
public boolean name() throws Exception {
|
||||||
|
Token first = LA(1);
|
||||||
Token last = null;
|
Token last = null;
|
||||||
|
|
||||||
callback.nameBegin(LA(1));
|
callback.nameBegin(first);
|
||||||
|
|
||||||
if (LT(1) == Token.tCOLONCOLON)
|
if (LT(1) == Token.tCOLONCOLON)
|
||||||
last = consume();
|
last = consume();
|
||||||
|
|
||||||
last = consume(Token.tIDENTIFIER);
|
// TODO - whacky way to deal with destructors, please revisit
|
||||||
|
switch (LT(1)) {
|
||||||
|
case Token.tIDENTIFIER:
|
||||||
|
case Token.tCOMPL:
|
||||||
|
last = consume();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw backtrack;
|
||||||
|
}
|
||||||
|
|
||||||
while (LT(1) == Token.tCOLONCOLON) {
|
while (LT(1) == Token.tCOLONCOLON) {
|
||||||
last = consume();
|
last = consume();
|
||||||
|
|
||||||
last = consume(Token.tIDENTIFIER);
|
switch (LT(1)) {
|
||||||
|
case Token.tIDENTIFIER:
|
||||||
|
case Token.tCOMPL:
|
||||||
|
last = consume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.nameEnd(last);
|
callback.nameEnd(last);
|
||||||
|
@ -377,6 +407,29 @@ c, quick);
|
||||||
*/
|
*/
|
||||||
public void initDeclarator( Object owner ) throws Exception {
|
public void initDeclarator( Object owner ) throws Exception {
|
||||||
declarator( owner );
|
declarator( owner );
|
||||||
|
|
||||||
|
if (LT(1) == Token.tASSIGN) {
|
||||||
|
consume();
|
||||||
|
|
||||||
|
if (LT(1) == Token.tLBRACE) {
|
||||||
|
// for now, just consume to matching brace
|
||||||
|
consume();
|
||||||
|
int depth = 1;
|
||||||
|
while (depth > 0) {
|
||||||
|
switch (consume().getType()) {
|
||||||
|
case Token.tRBRACE:
|
||||||
|
--depth;
|
||||||
|
break;
|
||||||
|
case Token.tLBRACE:
|
||||||
|
++depth;
|
||||||
|
break;
|
||||||
|
case Token.tEOF:
|
||||||
|
// Oops, no match
|
||||||
|
throw backtrack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,10 +34,11 @@ public class Name {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String name = nameStart.getImage();
|
Token t = nameStart;
|
||||||
|
String name = t.getImage();
|
||||||
|
|
||||||
for (Token t = nameStart; nameStart != nameEnd;) {
|
while (t != nameEnd) {
|
||||||
t = nameStart.getNext();
|
t = t.getNext();
|
||||||
name += t.getImage();
|
name += t.getImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue