mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Added lengths to ASTNodes.
This commit is contained in:
parent
11b1607681
commit
cdfc350d10
14 changed files with 7573 additions and 8862 deletions
|
@ -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.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||||
|
@ -24,6 +25,8 @@ 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$
|
IASTTranslationUnit tu = parse( "int x;", ParserLanguage.C ); //$NON-NLS-1$
|
||||||
assertEquals( tu.getDeclarations()[0].getNodeLocations().length, 1 );
|
assertEquals( tu.getDeclarations()[0].getNodeLocations().length, 1 );
|
||||||
|
assertTrue( tu.getDeclarations()[0].getNodeLocations()[0] instanceof IASTFileLocation );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -28,14 +28,25 @@ public abstract class ASTNode implements IASTNode {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOffset(int offset) {
|
public void setOffset( int offset )
|
||||||
|
{
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLength(int length) {
|
public void setLength( int length )
|
||||||
|
{
|
||||||
this.length = length;
|
this.length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOffsetAndLength(int offset, int length) {
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffsetAndLength( ASTNode node )
|
||||||
|
{
|
||||||
|
setOffsetAndLength( node.getOffset(), node.getLength() );
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
|
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
|
||||||
*/
|
*/
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -167,15 +167,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
.setPropertyInParent(IASTInitializerList.NESTED_INITIALIZER);
|
.setPropertyInParent(IASTInitializerList.NESTED_INITIALIZER);
|
||||||
} else {
|
} else {
|
||||||
ICASTDesignatedInitializer desigInitializer = createDesignatorInitializer();
|
ICASTDesignatedInitializer desigInitializer = createDesignatorInitializer();
|
||||||
((CASTNode) desigInitializer)
|
((CASTNode) desigInitializer).setOffsetAndLength(
|
||||||
.setOffset(((CASTNode) newDesignators.get(0))
|
((CASTNode) newDesignators.get(0)).getOffset(),
|
||||||
.getOffset());
|
((CASTNode) newDesignators.get(0)).getLength());
|
||||||
for (int i = 0; i < newDesignators.size(); ++i) {
|
for (int i = 0; i < newDesignators.size(); ++i) {
|
||||||
ICASTDesignator d = (ICASTDesignator) newDesignators
|
ICASTDesignator d = (ICASTDesignator) newDesignators.get(i);
|
||||||
.get(i);
|
|
||||||
d.setParent(desigInitializer);
|
d.setParent(desigInitializer);
|
||||||
d
|
d.setPropertyInParent(ICASTDesignatedInitializer.DESIGNATOR);
|
||||||
.setPropertyInParent(ICASTDesignatedInitializer.DESIGNATOR);
|
|
||||||
desigInitializer.addDesignator(d);
|
desigInitializer.addDesignator(d);
|
||||||
}
|
}
|
||||||
desigInitializer.setOperandInitializer(initializer);
|
desigInitializer.setOperandInitializer(initializer);
|
||||||
|
@ -205,7 +203,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// otherwise, its another initializer in the list
|
// otherwise, its another initializer in the list
|
||||||
}
|
}
|
||||||
// consume the closing brace
|
// consume the closing brace
|
||||||
consume(IToken.tRBRACE);
|
int lastOffset = consume(IToken.tRBRACE).getEndOffset();
|
||||||
|
((ASTNode) result).setLength(lastOffset - startingOffset);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// if we get this far, it means that we have not yet succeeded
|
// if we get this far, it means that we have not yet succeeded
|
||||||
|
@ -215,8 +214,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTExpression assignmentExpression = assignmentExpression();
|
IASTExpression assignmentExpression = assignmentExpression();
|
||||||
IASTInitializerExpression result = createInitializerExpression();
|
IASTInitializerExpression result = createInitializerExpression();
|
||||||
result.setExpression(assignmentExpression);
|
result.setExpression(assignmentExpression);
|
||||||
((ASTNode) result).setOffset(((ASTNode) assignmentExpression)
|
((ASTNode) result).setOffsetAndLength(((ASTNode) assignmentExpression)
|
||||||
.getOffset());
|
.getOffset(), ((ASTNode) assignmentExpression).getLength());
|
||||||
assignmentExpression.setParent(result);
|
assignmentExpression.setParent(result);
|
||||||
assignmentExpression
|
assignmentExpression
|
||||||
.setPropertyInParent(IASTInitializerExpression.INITIALIZER_EXPRESSION);
|
.setPropertyInParent(IASTInitializerExpression.INITIALIZER_EXPRESSION);
|
||||||
|
@ -261,23 +260,25 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
int offset = consume(IToken.tDOT).getOffset();
|
int offset = consume(IToken.tDOT).getOffset();
|
||||||
IToken id = identifier();
|
IToken id = identifier();
|
||||||
ICASTFieldDesignator designator = createFieldDesignator();
|
ICASTFieldDesignator designator = createFieldDesignator();
|
||||||
((ASTNode) designator).setOffset(offset);
|
((ASTNode) designator).setOffsetAndLength(offset, id
|
||||||
|
.getEndOffset()
|
||||||
|
- offset);
|
||||||
IASTName n = createName(id);
|
IASTName n = createName(id);
|
||||||
designator.setName(n);
|
designator.setName(n);
|
||||||
n.setParent(designator);
|
n.setParent(designator);
|
||||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(
|
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
} else if (LT(1) == IToken.tLBRACKET) {
|
} else if (LT(1) == IToken.tLBRACKET) {
|
||||||
IToken mark = consume(IToken.tLBRACKET);
|
IToken mark = consume(IToken.tLBRACKET);
|
||||||
int offset = mark.getOffset();
|
int offset = mark.getOffset();
|
||||||
IASTExpression constantExpression = expression();
|
IASTExpression constantExpression = expression();
|
||||||
if (LT(1) == IToken.tRBRACKET) {
|
if (LT(1) == IToken.tRBRACKET) {
|
||||||
consume(IToken.tRBRACKET);
|
int lastOffset = consume(IToken.tRBRACKET).getEndOffset();
|
||||||
ICASTArrayDesignator designator = createArrayDesignator();
|
ICASTArrayDesignator designator = createArrayDesignator();
|
||||||
((ASTNode) designator).setOffset(offset);
|
((ASTNode) designator).setOffsetAndLength(offset, lastOffset
|
||||||
|
- offset);
|
||||||
designator.setSubscriptExpression(constantExpression);
|
designator.setSubscriptExpression(constantExpression);
|
||||||
constantExpression.setParent(designator);
|
constantExpression.setParent(designator);
|
||||||
constantExpression
|
constantExpression
|
||||||
|
@ -294,9 +295,10 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTExpression constantExpression1 = expression();
|
IASTExpression constantExpression1 = expression();
|
||||||
consume(IToken.tELLIPSIS);
|
consume(IToken.tELLIPSIS);
|
||||||
IASTExpression constantExpression2 = expression();
|
IASTExpression constantExpression2 = expression();
|
||||||
consume(IToken.tRBRACKET);
|
int lastOffset = consume(IToken.tRBRACKET).getEndOffset();
|
||||||
IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator();
|
IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator();
|
||||||
((ASTNode) designator).setOffset(startOffset);
|
((ASTNode) designator).setOffsetAndLength(startOffset,
|
||||||
|
lastOffset - startOffset);
|
||||||
designator.setRangeFloor(constantExpression1);
|
designator.setRangeFloor(constantExpression1);
|
||||||
constantExpression1.setParent(designator);
|
constantExpression1.setParent(designator);
|
||||||
constantExpression1
|
constantExpression1
|
||||||
|
@ -313,16 +315,17 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
} else if (supportGCCStyleDesignators
|
} else if (supportGCCStyleDesignators
|
||||||
&& LT(1) == IToken.tIDENTIFIER) {
|
&& LT(1) == IToken.tIDENTIFIER) {
|
||||||
IToken identifier = identifier();
|
IToken identifier = identifier();
|
||||||
consume(IToken.tCOLON);
|
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
||||||
ICASTFieldDesignator designator = createFieldDesignator();
|
ICASTFieldDesignator designator = createFieldDesignator();
|
||||||
((ASTNode) designator).setOffset(identifier.getOffset());
|
((ASTNode) designator).setOffsetAndLength(
|
||||||
|
identifier.getOffset(), lastOffset
|
||||||
|
- identifier.getOffset());
|
||||||
IASTName n = createName(identifier);
|
IASTName n = createName(identifier);
|
||||||
designator.setName(n);
|
designator.setName(n);
|
||||||
n.setParent(designator);
|
n.setParent(designator);
|
||||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(
|
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,25 +335,27 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
if (LT(1) == IToken.tIDENTIFIER) {
|
if (LT(1) == IToken.tIDENTIFIER) {
|
||||||
IToken identifier = identifier();
|
IToken identifier = identifier();
|
||||||
consume(IToken.tCOLON);
|
int lastOffset = consume(IToken.tCOLON).getEndOffset();
|
||||||
ICASTFieldDesignator designator = createFieldDesignator();
|
ICASTFieldDesignator designator = createFieldDesignator();
|
||||||
((ASTNode) designator).setOffset(identifier.getOffset());
|
((ASTNode) designator).setOffsetAndLength(
|
||||||
|
identifier.getOffset(), lastOffset
|
||||||
|
- identifier.getOffset());
|
||||||
IASTName n = createName(identifier);
|
IASTName n = createName(identifier);
|
||||||
designator.setName(n);
|
designator.setName(n);
|
||||||
n.setParent(designator);
|
n.setParent(designator);
|
||||||
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
n.setPropertyInParent(ICASTFieldDesignator.FIELD_NAME);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(
|
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
} else if (LT(1) == IToken.tLBRACKET) {
|
} else if (LT(1) == IToken.tLBRACKET) {
|
||||||
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
int startOffset = consume(IToken.tLBRACKET).getOffset();
|
||||||
IASTExpression constantExpression1 = expression();
|
IASTExpression constantExpression1 = expression();
|
||||||
consume(IToken.tELLIPSIS);
|
consume(IToken.tELLIPSIS);
|
||||||
IASTExpression constantExpression2 = expression();
|
IASTExpression constantExpression2 = expression();
|
||||||
consume(IToken.tRBRACKET);
|
int lastOffset = consume(IToken.tRBRACKET).getEndOffset();
|
||||||
IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator();
|
IGCCASTArrayRangeDesignator designator = createArrayRangeDesignator();
|
||||||
((ASTNode) designator).setOffset(startOffset);
|
((ASTNode) designator).setOffsetAndLength(startOffset,
|
||||||
|
lastOffset - startOffset);
|
||||||
designator.setRangeFloor(constantExpression1);
|
designator.setRangeFloor(constantExpression1);
|
||||||
constantExpression1.setParent(designator);
|
constantExpression1.setParent(designator);
|
||||||
constantExpression1
|
constantExpression1
|
||||||
|
@ -360,8 +365,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
constantExpression2
|
constantExpression2
|
||||||
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION);
|
.setPropertyInParent(IGCCASTArrayRangeDesignator.SUBSCRIPT_CEILING_EXPRESSION);
|
||||||
if (designatorList == Collections.EMPTY_LIST)
|
if (designatorList == Collections.EMPTY_LIST)
|
||||||
designatorList = new ArrayList(
|
designatorList = new ArrayList(DEFAULT_DESIGNATOR_LIST_SIZE);
|
||||||
DEFAULT_DESIGNATOR_LIST_SIZE);
|
|
||||||
designatorList.add(designator);
|
designatorList.add(designator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -477,11 +481,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
s.setParent(funcDefinition);
|
s.setParent(funcDefinition);
|
||||||
s.setPropertyInParent(IASTFunctionDefinition.FUNCTION_BODY);
|
s.setPropertyInParent(IASTFunctionDefinition.FUNCTION_BODY);
|
||||||
}
|
}
|
||||||
|
((ASTNode) funcDefinition).setLength(lastToken.getEndOffset()
|
||||||
|
- firstOffset);
|
||||||
return funcDefinition;
|
return funcDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
IASTSimpleDeclaration simpleDeclaration = createSimpleDeclaration();
|
||||||
((ASTNode) simpleDeclaration).setOffset(firstOffset);
|
((ASTNode) simpleDeclaration).setOffsetAndLength(firstOffset, lastToken
|
||||||
|
.getEndOffset()
|
||||||
|
- firstOffset);
|
||||||
simpleDeclaration.setDeclSpecifier(declSpec);
|
simpleDeclaration.setDeclSpecifier(declSpec);
|
||||||
declSpec.setParent(simpleDeclaration);
|
declSpec.setParent(simpleDeclaration);
|
||||||
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
declSpec.setPropertyInParent(IASTSimpleDeclaration.DECL_SPECIFIER);
|
||||||
|
@ -549,7 +557,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
if (LA(1).hashCode() == checkOffset)
|
if (LA(1).hashCode() == checkOffset)
|
||||||
failParseWithErrorHandling();
|
failParseWithErrorHandling();
|
||||||
} catch (EndOfFileException e) {
|
} catch (EndOfFileException e) {
|
||||||
// Good
|
// As expected
|
||||||
|
if( translationUnit.getDeclarations().length != 0 )
|
||||||
|
{
|
||||||
|
CASTNode d = (CASTNode) translationUnit.getDeclarations()[ translationUnit.getDeclarations().length - 1 ];
|
||||||
|
((CASTNode) translationUnit).setLength( d.getOffset() + d.getLength() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
((CASTNode)translationUnit).setLength( 0 );
|
||||||
break;
|
break;
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
try {
|
try {
|
||||||
|
@ -557,16 +572,15 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTProblem p = failParse(b);
|
IASTProblem p = failParse(b);
|
||||||
IASTProblemDeclaration pd = createProblemDeclaration();
|
IASTProblemDeclaration pd = createProblemDeclaration();
|
||||||
pd.setProblem(p);
|
pd.setProblem(p);
|
||||||
((CASTNode) pd).setOffset(((CASTNode) p).getOffset());
|
((CASTNode) pd).setOffsetAndLength(((CASTNode) p).getOffset(),
|
||||||
|
((CASTNode) p).getLength());
|
||||||
p.setParent(pd);
|
p.setParent(pd);
|
||||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||||
pd.setParent(translationUnit);
|
pd.setParent(translationUnit);
|
||||||
pd
|
pd.setPropertyInParent(IASTTranslationUnit.OWNED_DECLARATION);
|
||||||
.setPropertyInParent(IASTTranslationUnit.OWNED_DECLARATION);
|
|
||||||
translationUnit.addDeclaration(pd);
|
translationUnit.addDeclaration(pd);
|
||||||
errorHandling();
|
errorHandling();
|
||||||
if (lastBacktrack != -1
|
if (lastBacktrack != -1 && lastBacktrack == LA(1).hashCode()) {
|
||||||
&& lastBacktrack == LA(1).hashCode()) {
|
|
||||||
// we haven't progressed from the
|
// we haven't progressed from the
|
||||||
// last backtrack
|
// last backtrack
|
||||||
// try and find tne next definition
|
// try and find tne next definition
|
||||||
|
@ -626,8 +640,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
conditionalExpression);
|
conditionalExpression);
|
||||||
case IToken.tSTARASSIGN:
|
case IToken.tSTARASSIGN:
|
||||||
return assignmentOperatorExpression(
|
return assignmentOperatorExpression(
|
||||||
IASTBinaryExpression.op_multiplyAssign,
|
IASTBinaryExpression.op_multiplyAssign, conditionalExpression);
|
||||||
conditionalExpression);
|
|
||||||
case IToken.tDIVASSIGN:
|
case IToken.tDIVASSIGN:
|
||||||
return assignmentOperatorExpression(
|
return assignmentOperatorExpression(
|
||||||
IASTBinaryExpression.op_divideAssign, conditionalExpression);
|
IASTBinaryExpression.op_divideAssign, conditionalExpression);
|
||||||
|
@ -658,8 +671,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
conditionalExpression);
|
conditionalExpression);
|
||||||
case IToken.tBITORASSIGN:
|
case IToken.tBITORASSIGN:
|
||||||
return assignmentOperatorExpression(
|
return assignmentOperatorExpression(
|
||||||
IASTBinaryExpression.op_binaryOrAssign,
|
IASTBinaryExpression.op_binaryOrAssign, conditionalExpression);
|
||||||
conditionalExpression);
|
|
||||||
}
|
}
|
||||||
return conditionalExpression;
|
return conditionalExpression;
|
||||||
}
|
}
|
||||||
|
@ -696,7 +708,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
firstExpression = buildBinaryExpression(operator,
|
firstExpression = buildBinaryExpression(operator,
|
||||||
firstExpression, secondExpression);
|
firstExpression, secondExpression, lastToken.getEndOffset());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return firstExpression;
|
return firstExpression;
|
||||||
|
@ -731,7 +743,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
firstExpression = buildBinaryExpression(operator,
|
firstExpression = buildBinaryExpression(operator,
|
||||||
firstExpression, secondExpression);
|
firstExpression, secondExpression, lastToken.getEndOffset());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return firstExpression;
|
return firstExpression;
|
||||||
|
@ -763,7 +775,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildTypeIdUnaryExpression(IASTCastExpression.op_cast,
|
return buildTypeIdUnaryExpression(IASTCastExpression.op_cast,
|
||||||
typeId, castExpression, startingOffset);
|
typeId, castExpression, startingOffset, calculateEndOffset(castExpression));
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -799,11 +811,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IToken mark = LA(1);
|
IToken mark = LA(1);
|
||||||
IASTExpression unaryExpression = null;
|
IASTExpression unaryExpression = null;
|
||||||
IASTTypeId typeId = null;
|
IASTTypeId typeId = null;
|
||||||
|
int lastOffset = 0;
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
try {
|
try {
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
typeId = typeId(false);
|
typeId = typeId(false);
|
||||||
consume(IToken.tRPAREN);
|
lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
typeId = null;
|
typeId = null;
|
||||||
|
@ -811,13 +824,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unaryExpression = unaryExpression();
|
unaryExpression = unaryExpression();
|
||||||
|
lastOffset = lastToken.getEndOffset();
|
||||||
}
|
}
|
||||||
mark = null;
|
mark = null;
|
||||||
if (typeId == null && unaryExpression != null)
|
if (typeId == null && unaryExpression != null)
|
||||||
return buildUnaryExpression(IASTUnaryExpression.op_sizeof,
|
return buildUnaryExpression(IASTUnaryExpression.op_sizeof,
|
||||||
unaryExpression, startingOffset);
|
unaryExpression, startingOffset, lastToken.getEndOffset());
|
||||||
return buildTypeIdExpression(IASTTypeIdExpression.op_sizeof,
|
return buildTypeIdExpression(IASTTypeIdExpression.op_sizeof,
|
||||||
typeId, startingOffset);
|
typeId, startingOffset, lastOffset);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (LT(1) == IGCCToken.t_typeof && supportTypeOfUnaries) {
|
if (LT(1) == IGCCToken.t_typeof && supportTypeOfUnaries) {
|
||||||
|
@ -835,16 +849,17 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param op_sizeof
|
|
||||||
* @param typeId
|
* @param typeId
|
||||||
* @param startingOffset
|
* @param startingOffset
|
||||||
|
* @param op
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected IASTExpression buildTypeIdExpression(int op_sizeof,
|
protected IASTExpression buildTypeIdExpression(int op, IASTTypeId typeId,
|
||||||
IASTTypeId typeId, int startingOffset) {
|
int startingOffset, int endingOffset) {
|
||||||
IASTTypeIdExpression result = createTypeIdExpression();
|
IASTTypeIdExpression result = createTypeIdExpression();
|
||||||
result.setOperator(op_sizeof);
|
result.setOperator(op);
|
||||||
((ASTNode) result).setOffset(startingOffset);
|
((ASTNode) result).setOffsetAndLength(startingOffset, endingOffset - startingOffset);
|
||||||
|
((ASTNode) result).setLength(endingOffset - startingOffset);
|
||||||
result.setTypeId(typeId);
|
result.setTypeId(typeId);
|
||||||
typeId.setParent(result);
|
typeId.setParent(result);
|
||||||
typeId.setPropertyInParent(IASTTypeIdExpression.TYPE_ID);
|
typeId.setPropertyInParent(IASTTypeIdExpression.TYPE_ID);
|
||||||
|
@ -874,9 +889,9 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
try {
|
try {
|
||||||
int offset = consume(IToken.tLPAREN).getOffset();
|
int offset = consume(IToken.tLPAREN).getOffset();
|
||||||
IASTTypeId t = typeId(false);
|
IASTTypeId t = typeId(false);
|
||||||
consume(IToken.tRPAREN);
|
int lastOffset = consume(IToken.tRPAREN).getEndOffset();
|
||||||
IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST);
|
IASTInitializer i = cInitializerClause(Collections.EMPTY_LIST);
|
||||||
firstExpression = buildTypeIdInitializerExpression(t, i, offset);
|
firstExpression = buildTypeIdInitializerExpression(t, i, offset, lastOffset);
|
||||||
break;
|
break;
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(m);
|
backup(m);
|
||||||
|
@ -893,10 +908,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// array access
|
// array access
|
||||||
consume(IToken.tLBRACKET);
|
consume(IToken.tLBRACKET);
|
||||||
secondExpression = expression();
|
secondExpression = expression();
|
||||||
consume(IToken.tRBRACKET);
|
int last = consume(IToken.tRBRACKET).getEndOffset();
|
||||||
IASTArraySubscriptExpression s = createArraySubscriptExpression();
|
IASTArraySubscriptExpression s = createArraySubscriptExpression();
|
||||||
((ASTNode) s)
|
((ASTNode) s).setOffsetAndLength(((ASTNode) firstExpression)
|
||||||
.setOffset(((ASTNode) firstExpression).getOffset());
|
.getOffset(), last - ((ASTNode) firstExpression)
|
||||||
|
.getOffset());
|
||||||
s.setArrayExpression(firstExpression);
|
s.setArrayExpression(firstExpression);
|
||||||
firstExpression.setParent(s);
|
firstExpression.setParent(s);
|
||||||
firstExpression
|
firstExpression
|
||||||
|
@ -912,10 +928,11 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
consume(IToken.tLPAREN);
|
consume(IToken.tLPAREN);
|
||||||
if (LT(1) != IToken.tRPAREN)
|
if (LT(1) != IToken.tRPAREN)
|
||||||
secondExpression = expression();
|
secondExpression = expression();
|
||||||
consume(IToken.tRPAREN);
|
last = consume(IToken.tRPAREN).getEndOffset();
|
||||||
IASTFunctionCallExpression f = createFunctionCallExpression();
|
IASTFunctionCallExpression f = createFunctionCallExpression();
|
||||||
((ASTNode) f)
|
((ASTNode) f).setOffsetAndLength(((ASTNode) firstExpression)
|
||||||
.setOffset(((ASTNode) firstExpression).getOffset());
|
.getOffset(), last - ((ASTNode) firstExpression)
|
||||||
|
.getOffset());
|
||||||
f.setFunctionNameExpression(firstExpression);
|
f.setFunctionNameExpression(firstExpression);
|
||||||
firstExpression.setParent(f);
|
firstExpression.setParent(f);
|
||||||
firstExpression
|
firstExpression
|
||||||
|
@ -930,24 +947,24 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
firstExpression = f;
|
firstExpression = f;
|
||||||
break;
|
break;
|
||||||
case IToken.tINCR:
|
case IToken.tINCR:
|
||||||
int offset = consume(IToken.tINCR).getOffset();
|
int offset = consume(IToken.tINCR).getEndOffset();
|
||||||
firstExpression = buildUnaryExpression(
|
firstExpression = buildUnaryExpression(
|
||||||
IASTUnaryExpression.op_postFixIncr, firstExpression,
|
IASTUnaryExpression.op_postFixIncr, firstExpression,
|
||||||
offset);
|
((CASTNode)firstExpression).getOffset(), offset);
|
||||||
break;
|
break;
|
||||||
case IToken.tDECR:
|
case IToken.tDECR:
|
||||||
offset = consume().getOffset();
|
offset = consume().getEndOffset();
|
||||||
firstExpression = buildUnaryExpression(
|
firstExpression = buildUnaryExpression(
|
||||||
IASTUnaryExpression.op_postFixDecr, firstExpression,
|
IASTUnaryExpression.op_postFixDecr, firstExpression,
|
||||||
offset);
|
((CASTNode)firstExpression).getOffset(), offset);
|
||||||
break;
|
break;
|
||||||
case IToken.tDOT:
|
case IToken.tDOT:
|
||||||
// member access
|
// member access
|
||||||
consume(IToken.tDOT);
|
consume(IToken.tDOT);
|
||||||
IASTName name = createName(identifier());
|
IASTName name = createName(identifier());
|
||||||
IASTFieldReference result = createFieldReference();
|
IASTFieldReference result = createFieldReference();
|
||||||
((ASTNode) result).setOffset(((ASTNode) firstExpression)
|
((ASTNode) result).setOffsetAndLength(
|
||||||
.getOffset());
|
((ASTNode) firstExpression).getOffset(), lastToken.getEndOffset() - ((ASTNode) firstExpression).getOffset());
|
||||||
result.setFieldOwner(firstExpression);
|
result.setFieldOwner(firstExpression);
|
||||||
result.setIsPointerDereference(false);
|
result.setIsPointerDereference(false);
|
||||||
firstExpression.setParent(result);
|
firstExpression.setParent(result);
|
||||||
|
@ -963,8 +980,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
consume(IToken.tARROW);
|
consume(IToken.tARROW);
|
||||||
name = createName(identifier());
|
name = createName(identifier());
|
||||||
result = createFieldReference();
|
result = createFieldReference();
|
||||||
((ASTNode) result).setOffset(((ASTNode) firstExpression)
|
((ASTNode) result).setOffsetAndLength(
|
||||||
.getOffset());
|
((ASTNode) firstExpression).getOffset(), lastToken.getEndOffset() - ((ASTNode) firstExpression).getOffset());
|
||||||
result.setFieldOwner(firstExpression);
|
result.setFieldOwner(firstExpression);
|
||||||
result.setIsPointerDereference(true);
|
result.setIsPointerDereference(true);
|
||||||
firstExpression.setParent(result);
|
firstExpression.setParent(result);
|
||||||
|
@ -999,12 +1016,13 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* @param t
|
* @param t
|
||||||
* @param i
|
* @param i
|
||||||
* @param offset
|
* @param offset
|
||||||
|
* @param lastOffset TODO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected ICASTTypeIdInitializerExpression buildTypeIdInitializerExpression(
|
protected ICASTTypeIdInitializerExpression buildTypeIdInitializerExpression(
|
||||||
IASTTypeId t, IASTInitializer i, int offset) {
|
IASTTypeId t, IASTInitializer i, int offset, int lastOffset) {
|
||||||
ICASTTypeIdInitializerExpression result = createTypeIdInitializerExpression();
|
ICASTTypeIdInitializerExpression result = createTypeIdInitializerExpression();
|
||||||
((ASTNode) result).setOffset(offset);
|
((ASTNode) result).setOffsetAndLength(offset, lastOffset - offset);
|
||||||
result.setTypeId(t);
|
result.setTypeId(t);
|
||||||
t.setParent(result);
|
t.setParent(result);
|
||||||
t.setPropertyInParent(ICASTTypeIdInitializerExpression.TYPE_ID);
|
t.setPropertyInParent(ICASTTypeIdInitializerExpression.TYPE_ID);
|
||||||
|
@ -1044,14 +1062,14 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
literalExpression
|
literalExpression
|
||||||
.setKind(IASTLiteralExpression.lk_integer_constant);
|
.setKind(IASTLiteralExpression.lk_integer_constant);
|
||||||
literalExpression.setValue(t.getImage());
|
literalExpression.setValue(t.getImage());
|
||||||
((ASTNode) literalExpression).setOffset(t.getOffset());
|
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
||||||
return literalExpression;
|
return literalExpression;
|
||||||
case IToken.tFLOATINGPT:
|
case IToken.tFLOATINGPT:
|
||||||
t = consume();
|
t = consume();
|
||||||
literalExpression = createLiteralExpression();
|
literalExpression = createLiteralExpression();
|
||||||
literalExpression.setKind(IASTLiteralExpression.lk_float_constant);
|
literalExpression.setKind(IASTLiteralExpression.lk_float_constant);
|
||||||
literalExpression.setValue(t.getImage());
|
literalExpression.setValue(t.getImage());
|
||||||
((ASTNode) literalExpression).setOffset(t.getOffset());
|
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
||||||
return literalExpression;
|
return literalExpression;
|
||||||
case IToken.tSTRING:
|
case IToken.tSTRING:
|
||||||
case IToken.tLSTRING:
|
case IToken.tLSTRING:
|
||||||
|
@ -1059,7 +1077,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
literalExpression = createLiteralExpression();
|
literalExpression = createLiteralExpression();
|
||||||
literalExpression.setKind(IASTLiteralExpression.lk_string_literal);
|
literalExpression.setKind(IASTLiteralExpression.lk_string_literal);
|
||||||
literalExpression.setValue(t.getImage());
|
literalExpression.setValue(t.getImage());
|
||||||
((ASTNode) literalExpression).setOffset(t.getOffset());
|
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
||||||
return literalExpression;
|
return literalExpression;
|
||||||
case IToken.tCHAR:
|
case IToken.tCHAR:
|
||||||
case IToken.tLCHAR:
|
case IToken.tLCHAR:
|
||||||
|
@ -1067,7 +1085,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
literalExpression = createLiteralExpression();
|
literalExpression = createLiteralExpression();
|
||||||
literalExpression.setKind(IASTLiteralExpression.lk_char_constant);
|
literalExpression.setKind(IASTLiteralExpression.lk_char_constant);
|
||||||
literalExpression.setValue(t.getImage());
|
literalExpression.setValue(t.getImage());
|
||||||
((ASTNode) literalExpression).setOffset(t.getOffset());
|
((ASTNode) literalExpression).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
||||||
return literalExpression;
|
return literalExpression;
|
||||||
case IToken.tLPAREN:
|
case IToken.tLPAREN:
|
||||||
t = consume();
|
t = consume();
|
||||||
|
@ -1131,7 +1149,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTTypeId result = createTypeId();
|
IASTTypeId result = createTypeId();
|
||||||
((ASTNode) result).setOffset(startingOffset);
|
int length = (lastToken != null ) ? lastToken.getEndOffset() - startingOffset : 0;
|
||||||
|
((ASTNode) result).setOffsetAndLength(startingOffset, length);
|
||||||
|
|
||||||
result.setDeclSpecifier(declSpecifier);
|
result.setDeclSpecifier(declSpecifier);
|
||||||
declSpecifier.setParent(result);
|
declSpecifier.setParent(result);
|
||||||
|
@ -1198,7 +1217,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTPointerOperator po = createPointer();
|
IASTPointerOperator po = createPointer();
|
||||||
((ASTNode) po).setOffset(startOffset);
|
((ASTNode) po).setOffsetAndLength(startOffset, lastToken.getEndOffset() - startOffset);
|
||||||
((ICASTPointer) po).setConst(isConst);
|
((ICASTPointer) po).setConst(isConst);
|
||||||
((ICASTPointer) po).setVolatile(isVolatile);
|
((ICASTPointer) po).setVolatile(isVolatile);
|
||||||
((ICASTPointer) po).setRestrict(isRestrict);
|
((ICASTPointer) po).setRestrict(isRestrict);
|
||||||
|
@ -1397,7 +1416,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (structSpec != null) {
|
if (structSpec != null) {
|
||||||
((ASTNode) structSpec).setOffset(startingOffset);
|
((ASTNode) structSpec).setOffsetAndLength(startingOffset, lastToken.getEndOffset() - startingOffset);
|
||||||
structSpec.setConst(isConst);
|
structSpec.setConst(isConst);
|
||||||
((ICASTCompositeTypeSpecifier) structSpec).setRestrict(isRestrict);
|
((ICASTCompositeTypeSpecifier) structSpec).setRestrict(isRestrict);
|
||||||
structSpec.setVolatile(isVolatile);
|
structSpec.setVolatile(isVolatile);
|
||||||
|
@ -1408,7 +1427,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enumSpec != null) {
|
if (enumSpec != null) {
|
||||||
((ASTNode) enumSpec).setOffset(startingOffset);
|
((ASTNode) enumSpec).setOffsetAndLength(startingOffset, lastToken.getEndOffset() - startingOffset);
|
||||||
enumSpec.setConst(isConst);
|
enumSpec.setConst(isConst);
|
||||||
((CASTEnumerationSpecifier) enumSpec).setRestrict(isRestrict);
|
((CASTEnumerationSpecifier) enumSpec).setRestrict(isRestrict);
|
||||||
enumSpec.setVolatile(isVolatile);
|
enumSpec.setVolatile(isVolatile);
|
||||||
|
@ -1418,7 +1437,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
}
|
}
|
||||||
if (elabSpec != null) {
|
if (elabSpec != null) {
|
||||||
((ASTNode) elabSpec).setOffset(startingOffset);
|
((ASTNode) elabSpec).setOffsetAndLength(startingOffset, lastToken.getEndOffset() - startingOffset);
|
||||||
elabSpec.setConst(isConst);
|
elabSpec.setConst(isConst);
|
||||||
((CASTElaboratedTypeSpecifier) elabSpec).setRestrict(isRestrict);
|
((CASTElaboratedTypeSpecifier) elabSpec).setRestrict(isRestrict);
|
||||||
elabSpec.setVolatile(isVolatile);
|
elabSpec.setVolatile(isVolatile);
|
||||||
|
@ -1435,7 +1454,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declSpec.setInline(isInline);
|
declSpec.setInline(isInline);
|
||||||
declSpec.setStorageClass(storageClass);
|
declSpec.setStorageClass(storageClass);
|
||||||
|
|
||||||
((ASTNode) declSpec).setOffset(startingOffset);
|
((ASTNode) declSpec).setOffsetAndLength(startingOffset, lastToken.getEndOffset() - startingOffset);
|
||||||
IASTName name = createName(identifier);
|
IASTName name = createName(identifier);
|
||||||
declSpec.setName(name);
|
declSpec.setName(name);
|
||||||
name.setParent(declSpec);
|
name.setParent(declSpec);
|
||||||
|
@ -1455,8 +1474,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
declSpec.setUnsigned(isUnsigned);
|
declSpec.setUnsigned(isUnsigned);
|
||||||
declSpec.setSigned(isSigned);
|
declSpec.setSigned(isSigned);
|
||||||
declSpec.setShort(isShort);
|
declSpec.setShort(isShort);
|
||||||
|
int length = ( lastToken != null ) ? lastToken.getEndOffset() - startingOffset : 0 ;
|
||||||
((ASTNode) declSpec).setOffset(startingOffset);
|
((ASTNode) declSpec).setOffsetAndLength(startingOffset, length );
|
||||||
return declSpec;
|
return declSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1481,8 +1500,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
* "}"
|
* "}"
|
||||||
*
|
*
|
||||||
* @param owner
|
* @param owner
|
||||||
* IParserCallback object that represents the declaration that
|
* IParserCallback object that represents the declaration that owns
|
||||||
* owns this classSpecifier
|
* this classSpecifier
|
||||||
*
|
*
|
||||||
* @return TODO
|
* @return TODO
|
||||||
* @throws BacktrackException
|
* @throws BacktrackException
|
||||||
|
@ -1563,7 +1582,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
failParseWithErrorHandling();
|
failParseWithErrorHandling();
|
||||||
}
|
}
|
||||||
// consume the }
|
// consume the }
|
||||||
consume(IToken.tRBRACE);
|
int endOffset = consume(IToken.tRBRACE).getEndOffset();
|
||||||
|
((CASTNode)result).setLength( endOffset - classKey.getOffset() );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1728,8 +1748,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
IASTParameterDeclaration p = (IASTParameterDeclaration) parameters
|
||||||
.get(i);
|
.get(i);
|
||||||
p.setParent(fc);
|
p.setParent(fc);
|
||||||
p
|
p.setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER);
|
||||||
.setPropertyInParent(IASTFunctionDeclarator.FUNCTION_PARAMETER);
|
|
||||||
fc.addParameterDeclaration(p);
|
fc.addParameterDeclaration(p);
|
||||||
}
|
}
|
||||||
d = fc;
|
d = fc;
|
||||||
|
@ -1792,7 +1811,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).setOffset(t.getOffset());
|
((ASTNode) n).setOffsetAndLength(t.getOffset(), t.getEndOffset() - t.getOffset());
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1865,7 +1884,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
temp.setVariableSized(isVarSized);
|
temp.setVariableSized(isVarSized);
|
||||||
arrayMod = temp;
|
arrayMod = temp;
|
||||||
}
|
}
|
||||||
((ASTNode) arrayMod).setOffset(startOffset);
|
((ASTNode) arrayMod).setOffsetAndLength(startOffset, lastToken.getEndOffset() - startOffset);
|
||||||
if (exp != null) {
|
if (exp != null) {
|
||||||
arrayMod.setConstantExpression(exp);
|
arrayMod.setConstantExpression(exp);
|
||||||
exp.setParent(arrayMod);
|
exp.setParent(arrayMod);
|
||||||
|
@ -1905,7 +1924,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTParameterDeclaration result = createParameterDeclaration();
|
IASTParameterDeclaration result = createParameterDeclaration();
|
||||||
((ASTNode) result).setOffset(startingOffset);
|
((ASTNode) result).setOffsetAndLength(startingOffset, lastToken.getEndOffset() - startingOffset);
|
||||||
result.setDeclSpecifier(declSpec);
|
result.setDeclSpecifier(declSpec);
|
||||||
declSpec.setParent(result);
|
declSpec.setParent(result);
|
||||||
declSpec.setPropertyInParent(IASTParameterDeclaration.DECL_SPECIFIER);
|
declSpec.setPropertyInParent(IASTParameterDeclaration.DECL_SPECIFIER);
|
||||||
|
@ -1932,6 +1951,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
try {
|
try {
|
||||||
IASTExpression e = expression();
|
IASTExpression e = expression();
|
||||||
consume(IToken.tSEMI);
|
consume(IToken.tSEMI);
|
||||||
|
//TODO is this a problem? Should we wrap this in an expression statement?
|
||||||
return e;
|
return e;
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
backup(mark);
|
backup(mark);
|
||||||
|
@ -1940,7 +1960,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
} catch (BacktrackException b) {
|
} catch (BacktrackException b) {
|
||||||
IASTProblem p = failParse(b);
|
IASTProblem p = failParse(b);
|
||||||
IASTProblemExpression pe = createProblemExpression();
|
IASTProblemExpression pe = createProblemExpression();
|
||||||
((CASTNode) pe).setOffset(((CASTNode) p).getOffset());
|
((CASTNode) pe).setOffsetAndLength(((CASTNode) p));
|
||||||
pe.setProblem(p);
|
pe.setProblem(p);
|
||||||
p.setParent(pe);
|
p.setParent(pe);
|
||||||
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
p.setPropertyInParent(IASTProblemHolder.PROBLEM);
|
||||||
|
@ -2225,8 +2245,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
*/
|
*/
|
||||||
protected IASTProblem createProblem(int signal, int offset, int length) {
|
protected IASTProblem createProblem(int signal, int offset, int length) {
|
||||||
IASTProblem result = new CASTProblem(signal, EMPTY_STRING, false, true);
|
IASTProblem result = new CASTProblem(signal, EMPTY_STRING, false, true);
|
||||||
((ASTNode) result).setOffset(offset);
|
((ASTNode) result).setOffsetAndLength(offset, length);
|
||||||
((ASTNode) result).setLength(length);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CollectProblemsAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -95,7 +95,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
|
|
||||||
// The context stack
|
// The context stack
|
||||||
protected static final int bufferInitialSize = 8;
|
protected static final int bufferInitialSize = 8;
|
||||||
int bufferStackPos = -1;
|
protected int bufferStackPos = -1;
|
||||||
protected char[][] bufferStack = new char[bufferInitialSize][];
|
protected char[][] bufferStack = new char[bufferInitialSize][];
|
||||||
protected Object[] bufferData = new Object[bufferInitialSize];
|
protected Object[] bufferData = new Object[bufferInitialSize];
|
||||||
protected int[] bufferPos = new int[bufferInitialSize];
|
protected int[] bufferPos = new int[bufferInitialSize];
|
||||||
|
@ -1269,16 +1269,18 @@ abstract class BaseScanner implements IScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void popContext() {
|
protected Object popContext() {
|
||||||
bufferStack[bufferStackPos] = null;
|
bufferStack[bufferStackPos] = null;
|
||||||
if( bufferData[bufferStackPos] instanceof InclusionData )
|
if( bufferData[bufferStackPos] instanceof InclusionData )
|
||||||
popInclusion(((InclusionData)bufferData[bufferStackPos]).inclusion);
|
popInclusion(((InclusionData)bufferData[bufferStackPos]).inclusion);
|
||||||
|
|
||||||
|
Object result = bufferData[bufferStackPos];
|
||||||
bufferData[bufferStackPos] = null;
|
bufferData[bufferStackPos] = null;
|
||||||
--bufferStackPos;
|
--bufferStackPos;
|
||||||
|
|
||||||
if( preIncludeFiles.hasNext() )
|
if( preIncludeFiles.hasNext() )
|
||||||
pushForcedInclusion();
|
pushForcedInclusion();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2115,7 +2117,7 @@ abstract class BaseScanner implements IScanner {
|
||||||
/**
|
/**
|
||||||
* @param scanner_bad_character
|
* @param scanner_bad_character
|
||||||
*/
|
*/
|
||||||
protected abstract void handleProblem(int id, int startOffset, char [] arg );
|
protected abstract void handleProblem(int id, int offset, char [] arg );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param i
|
* @param i
|
||||||
|
|
|
@ -32,6 +32,7 @@ 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 static class DOMInclusion
|
private static class DOMInclusion
|
||||||
{
|
{
|
||||||
|
@ -128,9 +129,11 @@ public class DOMScanner extends BaseScanner {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
|
||||||
*/
|
*/
|
||||||
protected void popContext() {
|
protected Object popContext() {
|
||||||
//TODO calibrate offsets
|
//TODO calibrate offsets
|
||||||
super.popContext();
|
Object result = super.popContext();
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
|
@ -200,9 +203,19 @@ public class DOMScanner extends BaseScanner {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[])
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int, int, char[])
|
||||||
*/
|
*/
|
||||||
protected void handleProblem(int id, int startOffset, char[] arg) {
|
protected void handleProblem(int id, int offset, char[] arg) {
|
||||||
IASTProblem problem = new ScannerASTProblem(id, arg, true, false );
|
IASTProblem problem = new ScannerASTProblem(id, arg, true, false );
|
||||||
|
int o = resolveOffset( offset );
|
||||||
|
((ScannerASTProblem)problem).setOffsetAndLength( o, resolveOffset( getCurrentOffset() + 1 ) - o );
|
||||||
locationMap.encounterProblem(problem);
|
locationMap.encounterProblem(problem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param offset
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int resolveOffset(int offset) {
|
||||||
|
return contextStart + offset;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
*/
|
*/
|
||||||
public interface IScannerPreprocessorLog {
|
public interface IScannerPreprocessorLog {
|
||||||
|
|
||||||
public void startTranslationUnit();
|
|
||||||
|
|
||||||
public void endTranslationUnit(int finalOffset);
|
public void endTranslationUnit(int finalOffset);
|
||||||
|
|
||||||
public void startInclusion(char[] includePath, int offset);
|
public void startInclusion(char[] includePath, int offset);
|
||||||
|
|
|
@ -28,6 +28,12 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
|
|
||||||
private List problems = Collections.EMPTY_LIST;
|
private List problems = Collections.EMPTY_LIST;
|
||||||
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public LocationMap() {
|
||||||
|
startTranslationUnit();
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
|
||||||
|
@ -72,9 +78,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
|
||||||
*/
|
*/
|
||||||
public void startTranslationUnit() {
|
protected void startTranslationUnit() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -242,10 +242,10 @@ public class Scanner2 extends BaseScanner {
|
||||||
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
|
* @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
|
||||||
* int, char[])
|
* int, char[])
|
||||||
*/
|
*/
|
||||||
protected void handleProblem(int id, int startOffset, char[] arg) {
|
protected void handleProblem(int id, int offset, char[] arg) {
|
||||||
if (parserMode == ParserMode.COMPLETION_PARSE)
|
if (parserMode == ParserMode.COMPLETION_PARSE)
|
||||||
return;
|
return;
|
||||||
IProblem p = spf.createProblem(id, startOffset,
|
IProblem p = spf.createProblem(id, offset,
|
||||||
bufferPos[bufferStackPos],
|
bufferPos[bufferStackPos],
|
||||||
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
|
getLineNumber(bufferPos[bufferStackPos]), getCurrentFilename(),
|
||||||
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
|
arg != null ? arg : EMPTY_CHAR_ARRAY, false, true);
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class BasicTokenDuple implements ITokenDuple {
|
||||||
if( token.getType() == IToken.tLT )
|
if( token.getType() == IToken.tLT )
|
||||||
token = TokenFactory.consumeTemplateIdArguments( token, last );
|
token = TokenFactory.consumeTemplateIdArguments( token, last );
|
||||||
if( token.getType() == IToken.tCOLONCOLON ){
|
if( token.getType() == IToken.tCOLONCOLON ){
|
||||||
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev );
|
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, ( prev == null ) ? startOfSegment : prev );
|
||||||
r.add( d );
|
r.add( d );
|
||||||
startOfSegment = token.getNext();
|
startOfSegment = token.getNext();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class TemplateTokenDuple extends BasicTokenDuple {
|
||||||
newArgs = new ArrayList( 1 );
|
newArgs = new ArrayList( 1 );
|
||||||
newArgs.add( argLists[count]);
|
newArgs.add( argLists[count]);
|
||||||
}
|
}
|
||||||
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev, newArgs );
|
ITokenDuple d = TokenFactory.createTokenDuple( startOfSegment, prev != null ? prev : startOfSegment, newArgs );
|
||||||
r.add( d );
|
r.add( d );
|
||||||
startOfSegment = token.getNext();
|
startOfSegment = token.getNext();
|
||||||
++count;
|
++count;
|
||||||
|
|
Loading…
Add table
Reference in a new issue