mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Base case DOMScanner/LocationMap support.
This commit is contained in:
parent
2713b4695c
commit
0a8634d93f
9 changed files with 165 additions and 45 deletions
|
@ -18,6 +18,7 @@ import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
||||||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests;
|
import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPTests;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
|
import org.eclipse.cdt.core.parser.tests.ast2.AST2Tests;
|
||||||
|
import org.eclipse.cdt.core.parser.tests.ast2.DOMScannerTests;
|
||||||
import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
|
import org.eclipse.cdt.core.parser.tests.ast2.GCCTests;
|
||||||
import org.eclipse.cdt.core.parser.tests.parser2.CompleteParser2Tests;
|
import org.eclipse.cdt.core.parser.tests.parser2.CompleteParser2Tests;
|
||||||
import org.eclipse.cdt.core.parser.tests.parser2.QuickParser2Tests;
|
import org.eclipse.cdt.core.parser.tests.parser2.QuickParser2Tests;
|
||||||
|
@ -61,6 +62,7 @@ public class ParserTestSuite extends TestCase {
|
||||||
suite.addTestSuite( AST2CPPTests.class );
|
suite.addTestSuite( AST2CPPTests.class );
|
||||||
suite.addTestSuite( QuickParser2Tests.class );
|
suite.addTestSuite( QuickParser2Tests.class );
|
||||||
suite.addTestSuite( CompleteParser2Tests.class );
|
suite.addTestSuite( CompleteParser2Tests.class );
|
||||||
|
suite.addTestSuite( DOMScannerTests.class );
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -22,16 +23,25 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
public class DOMScannerTests extends AST2BaseTest {
|
public class DOMScannerTests extends AST2BaseTest {
|
||||||
|
|
||||||
public void testSimpleLocation() throws ParserException {
|
public void testSimpleLocation() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse("int x;", ParserLanguage.C); //$NON-NLS-1$
|
for( ParserLanguage p = ParserLanguage.C; p != null; p = ( p == ParserLanguage.C ) ? ParserLanguage.CPP : null )
|
||||||
IASTNodeLocation[] nodeLocations = tu.getDeclarations()[0]
|
{
|
||||||
.getNodeLocations();
|
IASTTranslationUnit tu = parse("int x;", p); //$NON-NLS-1$
|
||||||
assertNotNull(nodeLocations);
|
IASTDeclaration declaration = tu.getDeclarations()[0];
|
||||||
assertEquals(nodeLocations.length, 1);
|
IASTNodeLocation[] nodeLocations = declaration
|
||||||
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
.getNodeLocations();
|
||||||
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
assertNotNull(nodeLocations);
|
||||||
assertEquals(fileLocation.getFileName(), "<text>"); //$NON-NLS-1$
|
assertEquals(nodeLocations.length, 1);
|
||||||
assertEquals(fileLocation.getNodeOffset(), 0);
|
assertTrue(nodeLocations[0] instanceof IASTFileLocation);
|
||||||
assertEquals(fileLocation.getNodeLength(), 6);
|
IASTFileLocation fileLocation = ((IASTFileLocation) nodeLocations[0]);
|
||||||
|
assertEquals(fileLocation.getFileName(), "<text>"); //$NON-NLS-1$
|
||||||
|
assertEquals(fileLocation.getNodeOffset(), 0);
|
||||||
|
assertEquals(fileLocation.getNodeLength(), 6);
|
||||||
|
IASTNodeLocation [] tuLocations = tu.getNodeLocations();
|
||||||
|
assertEquals( tuLocations.length, nodeLocations.length );
|
||||||
|
assertEquals(fileLocation.getFileName(), ((IASTFileLocation)tuLocations[0]).getFileName()); //$NON-NLS-1$
|
||||||
|
assertEquals(fileLocation.getNodeOffset(), tuLocations[0].getNodeOffset());
|
||||||
|
assertEquals(fileLocation.getNodeLength(), tuLocations[0].getNodeLength());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,6 +23,4 @@ public interface IASTFileLocation extends IASTNodeLocation {
|
||||||
* @return the name of the file
|
* @return the name of the file
|
||||||
*/
|
*/
|
||||||
public String getFileName();
|
public String getFileName();
|
||||||
public void setFileName( String fileName );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public interface IASTNodeLocation {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getNodeOffset();
|
public int getNodeOffset();
|
||||||
public void setNodeOffset( int offset );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the length of the node contained in this location.
|
* This is the length of the node contained in this location.
|
||||||
|
@ -34,6 +33,5 @@ public interface IASTNodeLocation {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getNodeLength();
|
public int getNodeLength();
|
||||||
public void setNodeLength( int length );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ public abstract class ASTNode implements IASTNode {
|
||||||
|
|
||||||
public void setOffsetAndLength(int offset, int length) {
|
public void setOffsetAndLength(int offset, int length) {
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
|
this.length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOffsetAndLength( ASTNode node )
|
public void setOffsetAndLength( ASTNode node )
|
||||||
|
|
|
@ -433,10 +433,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
boolean hasFunctionBody = false;
|
boolean hasFunctionBody = false;
|
||||||
boolean hasFunctionTryBlock = false;
|
boolean hasFunctionTryBlock = false;
|
||||||
boolean consumedSemi = false;
|
boolean consumedSemi = false;
|
||||||
|
int semiOffset = 0;
|
||||||
|
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tSEMI:
|
case IToken.tSEMI:
|
||||||
consume(IToken.tSEMI);
|
semiOffset = consume(IToken.tSEMI).getEndOffset();
|
||||||
consumedSemi = true;
|
consumedSemi = true;
|
||||||
break;
|
break;
|
||||||
case IToken.tLBRACE:
|
case IToken.tLBRACE:
|
||||||
|
@ -485,8 +486,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
||||||
|
|
||||||
|
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
||||||
|
if( consumedSemi )
|
||||||
|
length = semiOffset - firstOffset;
|
||||||
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset,
|
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset,
|
||||||
figureEndOffset(declSpec, declarators) - firstOffset);
|
length);
|
||||||
simpleDeclaration.setDeclSpecifier(declSpec);
|
simpleDeclaration.setDeclSpecifier(declSpec);
|
||||||
declSpec.setParent(simpleDeclaration);
|
declSpec.setParent(simpleDeclaration);
|
||||||
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
||||||
|
@ -1688,6 +1692,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTName declaratorName = null;
|
IASTName declaratorName = null;
|
||||||
IToken la = LA(1);
|
IToken la = LA(1);
|
||||||
int startingOffset = la.getOffset();
|
int startingOffset = la.getOffset();
|
||||||
|
int finalOffset = startingOffset;
|
||||||
la = null;
|
la = null;
|
||||||
List pointerOps = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
List pointerOps = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
||||||
List parameters = Collections.EMPTY_LIST;
|
List parameters = Collections.EMPTY_LIST;
|
||||||
|
@ -1698,14 +1703,19 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
overallLoop: do {
|
overallLoop: do {
|
||||||
|
|
||||||
consumePointerOperators(pointerOps);
|
consumePointerOperators(pointerOps);
|
||||||
|
if( ! pointerOps.isEmpty() )
|
||||||
|
{
|
||||||
|
finalOffset = calculateEndOffset( (IASTPointerOperator) pointerOps.get( pointerOps.size() - 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
consume();
|
consume();
|
||||||
innerDecl = declarator();
|
innerDecl = declarator();
|
||||||
consume(IToken.tRPAREN);
|
finalOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
declaratorName = createName();
|
declaratorName = createName();
|
||||||
} else if (LT(1) == IToken.tIDENTIFIER) {
|
} else if (LT(1) == IToken.tIDENTIFIER) {
|
||||||
declaratorName = createName(identifier());
|
declaratorName = createName(identifier());
|
||||||
|
finalOffset = calculateEndOffset(declaratorName );
|
||||||
} else
|
} else
|
||||||
declaratorName = createName();
|
declaratorName = createName();
|
||||||
|
|
||||||
|
@ -1716,19 +1726,23 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// d.setIsFunction(true);
|
// d.setIsFunction(true);
|
||||||
// TODO need to create a temporary scope object here
|
// TODO need to create a temporary scope object here
|
||||||
IToken last = consume(IToken.tLPAREN);
|
IToken last = consume(IToken.tLPAREN);
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
isFunction = true;
|
isFunction = true;
|
||||||
boolean seenParameter = false;
|
boolean seenParameter = false;
|
||||||
parameterDeclarationLoop: for (;;) {
|
parameterDeclarationLoop: for (;;) {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tRPAREN:
|
case IToken.tRPAREN:
|
||||||
last = consume();
|
last = consume();
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
break parameterDeclarationLoop;
|
break parameterDeclarationLoop;
|
||||||
case IToken.tELLIPSIS:
|
case IToken.tELLIPSIS:
|
||||||
last = consume();
|
last = consume();
|
||||||
encounteredVarArgs = true;
|
encounteredVarArgs = true;
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
break;
|
break;
|
||||||
case IToken.tCOMMA:
|
case IToken.tCOMMA:
|
||||||
last = consume();
|
last = consume();
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
seenParameter = false;
|
seenParameter = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1737,6 +1751,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
.getEndOffset()
|
.getEndOffset()
|
||||||
- startingOffset);
|
- startingOffset);
|
||||||
IASTParameterDeclaration pd = parameterDeclaration();
|
IASTParameterDeclaration pd = parameterDeclaration();
|
||||||
|
finalOffset = calculateEndOffset(pd);
|
||||||
if (parameters == Collections.EMPTY_LIST)
|
if (parameters == Collections.EMPTY_LIST)
|
||||||
parameters = new ArrayList(
|
parameters = new ArrayList(
|
||||||
DEFAULT_PARAMETERS_LIST_SIZE);
|
DEFAULT_PARAMETERS_LIST_SIZE);
|
||||||
|
@ -1750,10 +1765,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (arrayMods == Collections.EMPTY_LIST)
|
if (arrayMods == Collections.EMPTY_LIST)
|
||||||
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
||||||
consumeArrayModifiers(arrayMods);
|
consumeArrayModifiers(arrayMods);
|
||||||
|
if( !arrayMods.isEmpty() )
|
||||||
|
finalOffset = calculateEndOffset((IASTArrayModifier) arrayMods.get( arrayMods.size() - 1 ));
|
||||||
continue;
|
continue;
|
||||||
case IToken.tCOLON:
|
case IToken.tCOLON:
|
||||||
consume(IToken.tCOLON);
|
consume(IToken.tCOLON);
|
||||||
bitField = constantExpression();
|
bitField = constantExpression();
|
||||||
|
finalOffset = calculateEndOffset(bitField);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1808,6 +1826,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((ASTNode)d).setOffsetAndLength( startingOffset, finalOffset - startingOffset );
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1835,8 +1854,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
*/
|
*/
|
||||||
protected IASTName createName(IToken t) {
|
protected IASTName createName(IToken t) {
|
||||||
IASTName n = new CASTName(t.getCharImage());
|
IASTName n = new CASTName(t.getCharImage());
|
||||||
((ASTNode) n).setOffsetAndLength(t.getOffset(), t.getEndOffset()
|
((ASTNode) n).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
||||||
- t.getOffset());
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2567,11 +2567,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
boolean hasFunctionBody = false;
|
boolean hasFunctionBody = false;
|
||||||
boolean hasFunctionTryBlock = false;
|
boolean hasFunctionTryBlock = false;
|
||||||
boolean consumedSemi = false;
|
boolean consumedSemi = false;
|
||||||
|
int semiOffset = 0;
|
||||||
List constructorChain = Collections.EMPTY_LIST;
|
List constructorChain = Collections.EMPTY_LIST;
|
||||||
|
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tSEMI:
|
case IToken.tSEMI:
|
||||||
consume(IToken.tSEMI);
|
semiOffset = consume(IToken.tSEMI).getEndOffset();
|
||||||
consumedSemi = true;
|
consumedSemi = true;
|
||||||
break;
|
break;
|
||||||
case IToken.t_try:
|
case IToken.t_try:
|
||||||
|
@ -2669,8 +2670,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
||||||
|
int length = figureEndOffset(declSpec, declarators) - firstOffset;
|
||||||
|
if( consumedSemi )
|
||||||
|
length = semiOffset - firstOffset;
|
||||||
|
|
||||||
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset,
|
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset,
|
||||||
figureEndOffset(declSpec, declarators) - firstOffset);
|
length);
|
||||||
simpleDeclaration.setDeclSpecifier(declSpec);
|
simpleDeclaration.setDeclSpecifier(declSpec);
|
||||||
declSpec.setParent(simpleDeclaration);
|
declSpec.setParent(simpleDeclaration);
|
||||||
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
||||||
|
@ -3447,17 +3452,19 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTExpression bitField = null;
|
IASTExpression bitField = null;
|
||||||
boolean isFunction = false;
|
boolean isFunction = false;
|
||||||
boolean isPureVirtual = false, isConst = false, isVolatile = false;
|
boolean isPureVirtual = false, isConst = false, isVolatile = false;
|
||||||
|
int finalOffset = startingOffset;
|
||||||
overallLoop: do {
|
overallLoop: do {
|
||||||
|
|
||||||
consumePointerOperators(pointerOps);
|
consumePointerOperators(pointerOps);
|
||||||
|
if( ! pointerOps.isEmpty() )
|
||||||
|
finalOffset = calculateEndOffset( (IASTNode) pointerOps.get( pointerOps.size() - 1 ) );
|
||||||
|
|
||||||
if (!forTypeID && LT(1) == IToken.tLPAREN) {
|
if (!forTypeID && LT(1) == IToken.tLPAREN) {
|
||||||
IToken mark = mark();
|
IToken mark = mark();
|
||||||
try {
|
try {
|
||||||
consume();
|
consume();
|
||||||
innerDecl = declarator(strategy, forTypeID);
|
innerDecl = declarator(strategy, forTypeID);
|
||||||
consume(IToken.tRPAREN);
|
finalOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bte) {
|
} catch (BacktrackException bte) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
}
|
}
|
||||||
|
@ -3466,6 +3473,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
try {
|
try {
|
||||||
ITokenDuple d = consumeTemplatedOperatorName();
|
ITokenDuple d = consumeTemplatedOperatorName();
|
||||||
declaratorName = createName(d);
|
declaratorName = createName(d);
|
||||||
|
finalOffset = calculateEndOffset(declaratorName);
|
||||||
if (d.isConversion())
|
if (d.isConversion())
|
||||||
isFunction = true;
|
isFunction = true;
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
|
@ -3506,19 +3514,23 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
isFunction = true;
|
isFunction = true;
|
||||||
// TODO need to create a temporary scope object here
|
// TODO need to create a temporary scope object here
|
||||||
IToken last = consume(IToken.tLPAREN);
|
IToken last = consume(IToken.tLPAREN);
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
boolean seenParameter = false;
|
boolean seenParameter = false;
|
||||||
parameterDeclarationLoop: for (;;) {
|
parameterDeclarationLoop: for (;;) {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tRPAREN:
|
case IToken.tRPAREN:
|
||||||
last = consume();
|
last = consume();
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
break parameterDeclarationLoop;
|
break parameterDeclarationLoop;
|
||||||
case IToken.tELLIPSIS:
|
case IToken.tELLIPSIS:
|
||||||
last = consume();
|
last = consume();
|
||||||
encounteredVarArgs = true;
|
encounteredVarArgs = true;
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
break;
|
break;
|
||||||
case IToken.tCOMMA:
|
case IToken.tCOMMA:
|
||||||
last = consume();
|
last = consume();
|
||||||
seenParameter = false;
|
seenParameter = false;
|
||||||
|
finalOffset = last.getEndOffset();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
int endOffset = (last != null) ? last
|
int endOffset = (last != null) ? last
|
||||||
|
@ -3527,6 +3539,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
throwBacktrack(startingOffset, endOffset
|
throwBacktrack(startingOffset, endOffset
|
||||||
- startingOffset);
|
- startingOffset);
|
||||||
IASTParameterDeclaration p = parameterDeclaration();
|
IASTParameterDeclaration p = parameterDeclaration();
|
||||||
|
finalOffset = calculateEndOffset(p);
|
||||||
if (parameters == Collections.EMPTY_LIST)
|
if (parameters == Collections.EMPTY_LIST)
|
||||||
parameters = new ArrayList(
|
parameters = new ArrayList(
|
||||||
DEFAULT_PARM_LIST_SIZE);
|
DEFAULT_PARM_LIST_SIZE);
|
||||||
|
@ -3556,7 +3569,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// This will be determined further below
|
// This will be determined further below
|
||||||
while ((LT(1) == IToken.t_const || LT(1) == IToken.t_volatile)
|
while ((LT(1) == IToken.t_const || LT(1) == IToken.t_volatile)
|
||||||
&& numCVModifiers < 2) {
|
&& numCVModifiers < 2) {
|
||||||
cvModifiers[numCVModifiers++] = consume();
|
IToken t = consume();
|
||||||
|
finalOffset = t.getEndOffset();
|
||||||
|
cvModifiers[numCVModifiers++] = t;
|
||||||
afterCVModifier = mark();
|
afterCVModifier = mark();
|
||||||
}
|
}
|
||||||
//check for throws clause here
|
//check for throws clause here
|
||||||
|
@ -3570,7 +3585,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
while (!done) {
|
while (!done) {
|
||||||
switch (LT(1)) {
|
switch (LT(1)) {
|
||||||
case IToken.tRPAREN:
|
case IToken.tRPAREN:
|
||||||
consume();
|
finalOffset = consume().getEndOffset();
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
case IToken.tCOMMA:
|
case IToken.tCOMMA:
|
||||||
|
@ -3599,7 +3614,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
char[] image = LA(2).getCharImage();
|
char[] image = LA(2).getCharImage();
|
||||||
if (image.length == 1 && image[0] == '0') {
|
if (image.length == 1 && image[0] == '0') {
|
||||||
consume(IToken.tASSIGN);
|
consume(IToken.tASSIGN);
|
||||||
consume(IToken.tINTEGER);
|
finalOffset = consume(IToken.tINTEGER).getEndOffset();
|
||||||
isPureVirtual = true;
|
isPureVirtual = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3624,10 +3639,13 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
case IToken.tLBRACKET:
|
case IToken.tLBRACKET:
|
||||||
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
arrayMods = new ArrayList(DEFAULT_POINTEROPS_LIST_SIZE);
|
||||||
consumeArrayModifiers(arrayMods);
|
consumeArrayModifiers(arrayMods);
|
||||||
|
if( ! arrayMods.isEmpty() )
|
||||||
|
finalOffset = calculateEndOffset( (IASTNode) arrayMods.get( arrayMods.size() - 1 ) );
|
||||||
continue;
|
continue;
|
||||||
case IToken.tCOLON:
|
case IToken.tCOLON:
|
||||||
consume(IToken.tCOLON);
|
consume(IToken.tCOLON);
|
||||||
bitField = constantExpression();
|
bitField = constantExpression();
|
||||||
|
finalOffset = calculateEndOffset( bitField );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -3698,6 +3716,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
declaratorName.setPropertyInParent(IASTDeclarator.DECLARATOR_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((ASTNode)d).setOffsetAndLength( startingOffset, finalOffset - startingOffset );
|
||||||
return d;
|
return d;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
|
||||||
public class DOMScanner extends BaseScanner {
|
public class DOMScanner extends BaseScanner {
|
||||||
|
|
||||||
private final ICodeReaderFactory codeReaderFactory;
|
private final ICodeReaderFactory codeReaderFactory;
|
||||||
private int contextStart = 0;
|
private int globalCounter = 0;
|
||||||
|
private int contextDelta = 0;
|
||||||
|
|
||||||
private static class DOMInclusion
|
private static class DOMInclusion
|
||||||
{
|
{
|
||||||
|
@ -133,7 +134,11 @@ public class DOMScanner extends BaseScanner {
|
||||||
protected Object popContext() {
|
protected Object popContext() {
|
||||||
//TODO calibrate offsets
|
//TODO calibrate offsets
|
||||||
Object result = super.popContext();
|
Object result = super.popContext();
|
||||||
|
if( result instanceof CodeReader )
|
||||||
|
{
|
||||||
|
globalCounter += (((CodeReader)result).buffer.length - contextDelta);
|
||||||
|
locationMap.endTranslationUnit( globalCounter );
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -147,9 +152,9 @@ public class DOMScanner extends BaseScanner {
|
||||||
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
|
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
|
||||||
break;
|
break;
|
||||||
MacroData data = (MacroData)bufferData[mostRelevant + 1];
|
MacroData data = (MacroData)bufferData[mostRelevant + 1];
|
||||||
return new SimpleExpansionToken( signal, data.startOffset, data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1));
|
return new SimpleExpansionToken( signal, resolveOffset( data.startOffset ), data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1));
|
||||||
}
|
}
|
||||||
return new SimpleToken(signal, bufferPos[bufferStackPos] + 1 , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1) );
|
return new SimpleToken(signal, resolveOffset( bufferPos[bufferStackPos] + 1 ) , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IToken newToken( int signal, char [] buffer )
|
protected IToken newToken( int signal, char [] buffer )
|
||||||
|
@ -161,9 +166,9 @@ public class DOMScanner extends BaseScanner {
|
||||||
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
|
if( bufferData[mostRelevant] instanceof InclusionData || bufferData[mostRelevant] instanceof CodeReader )
|
||||||
break;
|
break;
|
||||||
MacroData data = (MacroData)bufferData[mostRelevant + 1];
|
MacroData data = (MacroData)bufferData[mostRelevant + 1];
|
||||||
return new ImagedExpansionToken( signal, buffer, data.startOffset, data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1));
|
return new ImagedExpansionToken( signal, buffer, resolveOffset( data.startOffset ), data.endOffset - data.startOffset + 1, getCurrentFilename(), getLineNumber( bufferPos[mostRelevant] + 1));
|
||||||
}
|
}
|
||||||
IToken i = new ImagedToken(signal, buffer, bufferPos[bufferStackPos] + 1 , getCurrentFilename(), getLineNumber( bufferPos[bufferStackPos] + 1));
|
IToken i = new ImagedToken(signal, buffer, resolveOffset( bufferPos[bufferStackPos] + 1 ), EMPTY_CHAR_ARRAY, getLineNumber( bufferPos[bufferStackPos] + 1));
|
||||||
if( buffer != null && buffer.length == 0 && signal != IToken.tSTRING && signal != IToken.tLSTRING )
|
if( buffer != null && buffer.length == 0 && signal != IToken.tSTRING && signal != IToken.tLSTRING )
|
||||||
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some point
|
bufferPos[bufferStackPos] += 1; //TODO - remove this hack at some point
|
||||||
|
|
||||||
|
@ -216,7 +221,7 @@ public class DOMScanner extends BaseScanner {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private int resolveOffset(int offset) {
|
private int resolveOffset(int offset) {
|
||||||
return contextStart + offset;
|
return globalCounter - contextDelta + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -232,9 +237,8 @@ public class DOMScanner extends BaseScanner {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#throwEOF()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#throwEOF()
|
||||||
*/
|
*/
|
||||||
protected void throwEOF() throws EndOfFileException {
|
protected void throwEOF() throws EndOfFileException {
|
||||||
locationMap.endTranslationUnit( preprocessedOffset );
|
locationMap.endTranslationUnit( globalCounter );
|
||||||
super.throwEOF();
|
super.throwEOF();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int preprocessedOffset = 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
|
@ -26,12 +27,75 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
*/
|
*/
|
||||||
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
|
public static class Location implements IASTNodeLocation
|
||||||
|
{
|
||||||
|
private final int nodeOffset;
|
||||||
|
private final int nodeLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param offset
|
||||||
|
* @param length
|
||||||
|
*/
|
||||||
|
public Location(int offset, int length) {
|
||||||
|
nodeOffset = offset;
|
||||||
|
nodeLength = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeOffset()
|
||||||
|
*/
|
||||||
|
public int getNodeOffset() {
|
||||||
|
return nodeOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeLength()
|
||||||
|
*/
|
||||||
|
public int getNodeLength() {
|
||||||
|
return nodeLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @author jcamelon
|
||||||
|
*/
|
||||||
|
public static class FileLocation extends Location implements IASTFileLocation {
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param length
|
||||||
|
* @param offset
|
||||||
|
* @param tu_filename
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public FileLocation(char[] tu_filename, int offset, int length) {
|
||||||
|
super( offset, length );
|
||||||
|
fileName = new String( tu_filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.core.dom.ast.IASTFileLocation#getFileName()
|
||||||
|
*/
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private static final char [] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
|
private static final char [] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
|
||||||
private List problems = Collections.EMPTY_LIST;
|
private List problems = Collections.EMPTY_LIST;
|
||||||
|
private List inclusions = Collections.EMPTY_LIST;
|
||||||
|
private List macroExpansions = Collections.EMPTY_LIST;
|
||||||
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
||||||
private static final IASTNodeLocation [] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
|
private static final IASTNodeLocation [] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
|
||||||
|
|
||||||
|
|
||||||
private char[] tu_filename = EMPTY_CHAR_ARRAY ;
|
private char[] tu_filename = EMPTY_CHAR_ARRAY ;
|
||||||
// private int finalOffset = 0;
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
private int finalOffset = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -79,7 +143,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
*/
|
*/
|
||||||
public IASTNodeLocation[] getLocations(int offset, int length) {
|
public IASTNodeLocation[] getLocations(int offset, int length) {
|
||||||
if( tu_filename == EMPTY_CHAR_ARRAY ) return EMPTY_LOCATION_ARRAY;
|
if( tu_filename == EMPTY_CHAR_ARRAY ) return EMPTY_LOCATION_ARRAY;
|
||||||
return null;
|
if( macroExpansions.isEmpty() && inclusions.isEmpty() )
|
||||||
|
{
|
||||||
|
if( offset + length > finalOffset ) return EMPTY_LOCATION_ARRAY;
|
||||||
|
IASTNodeLocation [] result = new IASTNodeLocation[1];
|
||||||
|
result[0] = new FileLocation( tu_filename, offset, length );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return EMPTY_LOCATION_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -107,7 +178,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int)
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int)
|
||||||
*/
|
*/
|
||||||
public void endTranslationUnit(int offset) {
|
public void endTranslationUnit(int offset) {
|
||||||
// this.finalOffset = offset;
|
this.finalOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -117,8 +188,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
public void startInclusion(char[] includePath, int offset) {
|
public void startInclusion(char[] includePath, int offset) {
|
||||||
// TODO Auto-generated method stub
|
inclusions.add( new String( includePath ));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -296,8 +366,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath()
|
||||||
*/
|
*/
|
||||||
public String getTranslationUnitPath() {
|
public String getTranslationUnitPath() {
|
||||||
// TODO Auto-generated method stub
|
if( tu_filename == EMPTY_CHAR_ARRAY ) return ""; //$NON-NLS-1$
|
||||||
return null;
|
return new String( tu_filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -306,9 +376,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getInclusionsPaths()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getInclusionsPaths()
|
||||||
*/
|
*/
|
||||||
public String[] getInclusionsPaths() {
|
public String[] getInclusionsPaths() {
|
||||||
// TODO Auto-generated method stub
|
if (inclusions == Collections.EMPTY_LIST)
|
||||||
return null;
|
return EMPTY_STRING_ARRAY;
|
||||||
}
|
return (String[]) inclusions.toArray(new String[inclusions.size()]); }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
|
Loading…
Add table
Reference in a new issue