mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 13:25:45 +02:00
Cosmetics.
This commit is contained in:
parent
d3b06fadd2
commit
361aa35205
8 changed files with 62 additions and 88 deletions
|
@ -29,14 +29,14 @@ public class CommentTests extends AST2TestBase {
|
||||||
return suite(CommentTests.class);
|
return suite(CommentTests.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCountCommentsInHeaderFile() throws ParserException{
|
public void testCountCommentsInHeaderFile() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true);
|
IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
|
||||||
assertEquals(9, comments.length);
|
assertEquals(9, comments.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCommentsInHeaderFile() throws ParserException{
|
public void testCommentsInHeaderFile() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true);
|
IASTTranslationUnit tu = parse(getHSource(), ParserLanguage.CPP, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
|
||||||
|
@ -51,14 +51,14 @@ public class CommentTests extends AST2TestBase {
|
||||||
assertEquals("//Endcomment h", new String(comments[8].getComment()));
|
assertEquals("//Endcomment h", new String(comments[8].getComment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCountCommentsInCPPFile() throws ParserException{
|
public void testCountCommentsInCPPFile() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true);
|
IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
|
||||||
assertEquals(10, comments.length);
|
assertEquals(10, comments.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCommentsInCPPFile() throws ParserException{
|
public void testCommentsInCPPFile() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true);
|
IASTTranslationUnit tu = parse(getCppSource(), ParserLanguage.CPP, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
|
||||||
|
@ -74,14 +74,14 @@ public class CommentTests extends AST2TestBase {
|
||||||
assertEquals("//An integer", new String(comments[9].getComment()));
|
assertEquals("//An integer", new String(comments[9].getComment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCountCommentsInCFile() throws ParserException{
|
public void testCountCommentsInCFile() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true);
|
IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
|
||||||
assertEquals(4, comments.length);
|
assertEquals(4, comments.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCommentsInCFile() throws ParserException{
|
public void testCommentsInCFile() throws ParserException {
|
||||||
IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true);
|
IASTTranslationUnit tu = parse(getCSource(), ParserLanguage.C, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ public class CommentTests extends AST2TestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// //comment
|
// //comment
|
||||||
public void testCommentLocation_bug186337() throws Exception{
|
public void testCommentLocation_bug186337() throws Exception {
|
||||||
CharSequence code= getContents(1)[0];
|
CharSequence code= getContents(1)[0];
|
||||||
IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, true);
|
IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, true);
|
||||||
IASTComment[] comments = tu.getComments();
|
IASTComment[] comments = tu.getComments();
|
||||||
|
@ -234,7 +234,6 @@ public class CommentTests extends AST2TestBase {
|
||||||
// #ifdef WHATEVA // TODO: ignored
|
// #ifdef WHATEVA // TODO: ignored
|
||||||
// #endif // TODO: ignored
|
// #endif // TODO: ignored
|
||||||
// // TODO: shows up in task list
|
// // TODO: shows up in task list
|
||||||
|
|
||||||
public void testCommentInDirectives_bug192546() throws Exception {
|
public void testCommentInDirectives_bug192546() throws Exception {
|
||||||
CharSequence code= getContents(1)[0];
|
CharSequence code= getContents(1)[0];
|
||||||
IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, false);
|
IASTTranslationUnit tu = parse(code.toString(), ParserLanguage.CPP, false, false);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* John Camelon (IBM) - Initial API and implementation
|
* John Camelon (IBM) - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||||
|
|
||||||
|
@ -22,13 +22,12 @@ import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||||
/**
|
/**
|
||||||
* Extern "C" construct.
|
* Extern "C" construct.
|
||||||
*/
|
*/
|
||||||
public class CPPASTLinkageSpecification extends ASTNode implements
|
public class CPPASTLinkageSpecification extends ASTNode
|
||||||
ICPPASTLinkageSpecification, IASTAmbiguityParent {
|
implements ICPPASTLinkageSpecification, IASTAmbiguityParent {
|
||||||
|
|
||||||
private String fLiteral;
|
private String fLiteral;
|
||||||
private IASTDeclaration[] fAllDeclarations;
|
private IASTDeclaration[] fAllDeclarations;
|
||||||
private IASTDeclaration[] fActiveDeclarations;
|
private IASTDeclaration[] fActiveDeclarations;
|
||||||
private int fLastDeclaration=-1;
|
private int fLastDeclaration = -1;
|
||||||
|
|
||||||
public CPPASTLinkageSpecification() {
|
public CPPASTLinkageSpecification() {
|
||||||
}
|
}
|
||||||
|
@ -45,13 +44,10 @@ public class CPPASTLinkageSpecification extends ASTNode implements
|
||||||
@Override
|
@Override
|
||||||
public CPPASTLinkageSpecification copy(CopyStyle style) {
|
public CPPASTLinkageSpecification copy(CopyStyle style) {
|
||||||
CPPASTLinkageSpecification copy = new CPPASTLinkageSpecification(fLiteral);
|
CPPASTLinkageSpecification copy = new CPPASTLinkageSpecification(fLiteral);
|
||||||
for (IASTDeclaration declaration : getDeclarations())
|
for (IASTDeclaration declaration : getDeclarations()) {
|
||||||
copy.addDeclaration(declaration == null ? null : declaration.copy(style));
|
copy.addDeclaration(declaration == null ? null : declaration.copy(style));
|
||||||
copy.setOffsetAndLength(this);
|
|
||||||
if (style == CopyStyle.withLocations) {
|
|
||||||
copy.setCopyLocation(this);
|
|
||||||
}
|
}
|
||||||
return copy;
|
return copy(copy, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,7 +66,7 @@ public class CPPASTLinkageSpecification extends ASTNode implements
|
||||||
if (decl != null) {
|
if (decl != null) {
|
||||||
decl.setParent(this);
|
decl.setParent(this);
|
||||||
decl.setPropertyInParent(OWNED_DECLARATION);
|
decl.setPropertyInParent(OWNED_DECLARATION);
|
||||||
fAllDeclarations = ArrayUtil.appendAt( IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
|
fAllDeclarations = ArrayUtil.appendAt(IASTDeclaration.class, fAllDeclarations, ++fLastDeclaration, decl);
|
||||||
fActiveDeclarations= null;
|
fActiveDeclarations= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,9 +95,9 @@ public class CPPASTLinkageSpecification extends ASTNode implements
|
||||||
public boolean accept(ASTVisitor action) {
|
public boolean accept(ASTVisitor action) {
|
||||||
if (action.shouldVisitDeclarations) {
|
if (action.shouldVisitDeclarations) {
|
||||||
switch (action.visit(this)) {
|
switch (action.visit(this)) {
|
||||||
case ASTVisitor.PROCESS_ABORT : return false;
|
case ASTVisitor.PROCESS_ABORT: return false;
|
||||||
case ASTVisitor.PROCESS_SKIP : return true;
|
case ASTVisitor.PROCESS_SKIP: return true;
|
||||||
default : break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class ASTCommenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int checkOffsets(IASTNode node) {
|
private int checkOffsets(IASTNode node) {
|
||||||
int offset = ((ASTNode)node).getOffset();
|
int offset = ((ASTNode) node).getOffset();
|
||||||
int status = PROCESS_CONTINUE;
|
int status = PROCESS_CONTINUE;
|
||||||
|
|
||||||
if (isCommentOnSameLine(node)
|
if (isCommentOnSameLine(node)
|
||||||
|
@ -169,33 +169,29 @@ public class ASTCommenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a NodeCommentMap for the given TranslationUnit. This is the only way
|
* Creates a NodeCommentMap for the given AST. This is the only way to get a NodeCommentMap
|
||||||
* to get a NodeCommentMap which contains all the comments mapped against nodes.
|
* which contains all the comments mapped against nodes.
|
||||||
*
|
*
|
||||||
* @param tu TranslationUnit
|
* @param ast the AST
|
||||||
* @return NodeCommentMap
|
* @return NodeCommentMap
|
||||||
*/
|
*/
|
||||||
public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit tu){
|
public static NodeCommentMap getCommentedNodeMap(IASTTranslationUnit ast) {
|
||||||
NodeCommentMap commentMap = new NodeCommentMap();
|
NodeCommentMap commentMap = new NodeCommentMap();
|
||||||
if (tu == null) {
|
if (ast == null) {
|
||||||
return commentMap;
|
return commentMap;
|
||||||
}
|
}
|
||||||
IASTComment[] commentsArray = tu.getComments();
|
IASTComment[] commentsArray = ast.getComments();
|
||||||
if (commentsArray == null) {
|
List<IASTComment> comments = new ArrayList<IASTComment>(commentsArray.length);
|
||||||
return commentMap;
|
for (IASTComment comment : commentsArray) {
|
||||||
}
|
|
||||||
List<IASTComment> comments = filterNonTuComments(commentsArray);
|
|
||||||
return addCommentsToCommentMap(tu, comments);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<IASTComment> filterNonTuComments(IASTComment[] comments) {
|
|
||||||
List<IASTComment> filtered = new ArrayList<IASTComment>(comments.length);
|
|
||||||
for (IASTComment comment : comments) {
|
|
||||||
if (comment.isPartOfTranslationUnitFile()) {
|
if (comment.isPartOfTranslationUnitFile()) {
|
||||||
filtered.add(comment);
|
comments.add(comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filtered;
|
assignPreprocessorComments(commentMap, comments, ast);
|
||||||
|
CommentHandler commentHandler = new CommentHandler(comments);
|
||||||
|
ASTCommenterVisitor commenter = new ASTCommenterVisitor(commentHandler, commentMap);
|
||||||
|
ast.accept(commenter);
|
||||||
|
return commentMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCommentDirectlyBeforePreprocessorStatement(IASTComment comment,
|
private static boolean isCommentDirectlyBeforePreprocessorStatement(IASTComment comment,
|
||||||
|
@ -204,11 +200,11 @@ public class ASTCommenter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
IASTFileLocation commentLocation = comment.getFileLocation();
|
IASTFileLocation commentLocation = comment.getFileLocation();
|
||||||
int preprcessorOffset = statement.getFileLocation().getNodeOffset();
|
int preprocessorOffset = statement.getFileLocation().getNodeOffset();
|
||||||
if (preprcessorOffset > commentLocation.getNodeOffset()) {
|
if (preprocessorOffset > commentLocation.getNodeOffset()) {
|
||||||
PreprocessorRangeChecker vister = new PreprocessorRangeChecker(preprcessorOffset, commentLocation);
|
PreprocessorRangeChecker visitor = new PreprocessorRangeChecker(preprocessorOffset, commentLocation);
|
||||||
tu.accept(vister);
|
tu.accept(visitor);
|
||||||
return vister.isPreStatementComment;
|
return visitor.isPreStatementComment;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -218,22 +214,7 @@ public class ASTCommenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts leading and training comments to the returned map and removes them from
|
* Puts leading and trailing comments to {@code commentMap} and removes them from
|
||||||
* the {@code comments} list.
|
|
||||||
*/
|
|
||||||
private static NodeCommentMap addCommentsToCommentMap(IASTTranslationUnit tu,
|
|
||||||
List<IASTComment> comments) {
|
|
||||||
NodeCommentMap commentMap = new NodeCommentMap();
|
|
||||||
CommentHandler commHandler = new CommentHandler(comments);
|
|
||||||
|
|
||||||
assignPreprocessorComments(commentMap, comments, tu);
|
|
||||||
ASTCommenterVisitor commenter = new ASTCommenterVisitor(commHandler, commentMap);
|
|
||||||
tu.accept(commenter);
|
|
||||||
return commentMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Puts leading and training comments to {@code commentMap} and removes them from
|
|
||||||
* the {@code comments} list.
|
* the {@code comments} list.
|
||||||
*/
|
*/
|
||||||
private static void assignPreprocessorComments(NodeCommentMap commentMap,
|
private static void assignPreprocessorComments(NodeCommentMap commentMap,
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier
|
||||||
* @author Guido Zgraggen IFS
|
* @author Guido Zgraggen IFS
|
||||||
*/
|
*/
|
||||||
public class ASTCommenterVisitor extends ASTVisitor {
|
public class ASTCommenterVisitor extends ASTVisitor {
|
||||||
protected CommentHandler commHandler;
|
protected CommentHandler commentHandler;
|
||||||
protected NodeCommentMap commentMap;
|
protected NodeCommentMap commentMap;
|
||||||
|
|
||||||
private NodeCommenter nodeCommenter;
|
private NodeCommenter nodeCommenter;
|
||||||
|
@ -61,14 +61,14 @@ public class ASTCommenterVisitor extends ASTVisitor {
|
||||||
shouldVisitTranslationUnit = true;
|
shouldVisitTranslationUnit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ASTCommenterVisitor(CommentHandler commHandler, NodeCommentMap commentMap) {
|
public ASTCommenterVisitor(CommentHandler commentHandler, NodeCommentMap commentMap) {
|
||||||
this.commHandler = commHandler;
|
this.commentHandler = commentHandler;
|
||||||
this.commentMap = commentMap;
|
this.commentMap = commentMap;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
nodeCommenter = new NodeCommenter(this, commHandler, commentMap);
|
nodeCommenter = new NodeCommenter(this, commentHandler, commentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -62,13 +62,13 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTWhileStatement;
|
||||||
*/
|
*/
|
||||||
public class NodeCommenter {
|
public class NodeCommenter {
|
||||||
protected ASTVisitor visitor;
|
protected ASTVisitor visitor;
|
||||||
protected CommentHandler commHandler;
|
protected CommentHandler commentHandler;
|
||||||
protected NodeCommentMap commentMap;
|
protected NodeCommentMap commentMap;
|
||||||
protected List<IASTNode> children;
|
protected List<IASTNode> children;
|
||||||
|
|
||||||
public NodeCommenter(ASTVisitor visitor, CommentHandler commHandler, NodeCommentMap commentMap) {
|
public NodeCommenter(ASTVisitor visitor, CommentHandler commHandler, NodeCommentMap commentMap) {
|
||||||
this.visitor = visitor;
|
this.visitor = visitor;
|
||||||
this.commHandler = commHandler;
|
this.commentHandler = commHandler;
|
||||||
this.commentMap = commentMap;
|
this.commentMap = commentMap;
|
||||||
this.children = new ArrayList<IASTNode>();
|
this.children = new ArrayList<IASTNode>();
|
||||||
}
|
}
|
||||||
|
@ -122,17 +122,17 @@ public class NodeCommenter {
|
||||||
|
|
||||||
private void addLeadingCommentToMap(ASTNode node, IASTComment comment) {
|
private void addLeadingCommentToMap(ASTNode node, IASTComment comment) {
|
||||||
commentMap.addLeadingCommentToNode(node, comment);
|
commentMap.addLeadingCommentToNode(node, comment);
|
||||||
commHandler.allreadyAdded(comment);
|
commentHandler.allreadyAdded(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addTrailingCommentToMap(ASTNode node, IASTComment comment) {
|
private void addTrailingCommentToMap(ASTNode node, IASTComment comment) {
|
||||||
commentMap.addTrailingCommentToNode(node, comment);
|
commentMap.addTrailingCommentToNode(node, comment);
|
||||||
commHandler.allreadyAdded(comment);
|
commentHandler.allreadyAdded(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFreestandingCommentToMap(ASTNode node, IASTComment comment) {
|
private void addFreestandingCommentToMap(ASTNode node, IASTComment comment) {
|
||||||
commentMap.addFreestandingCommentToNode(node, comment);
|
commentMap.addFreestandingCommentToNode(node, comment);
|
||||||
commHandler.allreadyAdded(comment);
|
commentHandler.allreadyAdded(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTrailing(ASTNode node, ASTNode com, int nodeLineNumber, int commentLineNumber) {
|
private boolean isTrailing(ASTNode node, ASTNode com, int nodeLineNumber, int commentLineNumber) {
|
||||||
|
@ -200,8 +200,8 @@ public class NodeCommenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int appendComments(ASTNode node) {
|
protected int appendComments(ASTNode node) {
|
||||||
while (commHandler.hasMore()) {
|
while (commentHandler.hasMore()) {
|
||||||
IASTComment comment = commHandler.getFirst();
|
IASTComment comment = commentHandler.getFirst();
|
||||||
|
|
||||||
if (isNotSameFile(node, comment)) {
|
if (isNotSameFile(node, comment)) {
|
||||||
return ASTVisitor.PROCESS_SKIP;
|
return ASTVisitor.PROCESS_SKIP;
|
||||||
|
@ -215,8 +215,8 @@ public class NodeCommenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int appendFreestandingComments(ASTNode node) {
|
protected int appendFreestandingComments(ASTNode node) {
|
||||||
while (commHandler.hasMore()) {
|
while (commentHandler.hasMore()) {
|
||||||
IASTComment comment = commHandler.getFirst();
|
IASTComment comment = commentHandler.getFirst();
|
||||||
|
|
||||||
if (isNotSameFile(node, comment)) {
|
if (isNotSameFile(node, comment)) {
|
||||||
return ASTVisitor.PROCESS_SKIP;
|
return ASTVisitor.PROCESS_SKIP;
|
||||||
|
@ -234,9 +234,9 @@ public class NodeCommenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void appendRemainingComments(IASTDeclaration declaration) {
|
public void appendRemainingComments(IASTDeclaration declaration) {
|
||||||
while (commHandler.hasMore()) {
|
while (commentHandler.hasMore()) {
|
||||||
IASTComment comment = commHandler.getFirst();
|
IASTComment comment = commentHandler.getFirst();
|
||||||
if (appendComment((ASTNode)declaration, comment)) {
|
if (appendComment((ASTNode) declaration, comment)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addFreestandingCommentToMap((ASTNode) declaration, comment);
|
addFreestandingCommentToMap((ASTNode) declaration, comment);
|
||||||
|
|
|
@ -113,6 +113,7 @@ abstract class ASTPreprocessorNode extends ASTNode {
|
||||||
class ASTComment extends ASTPreprocessorNode implements IASTComment {
|
class ASTComment extends ASTPreprocessorNode implements IASTComment {
|
||||||
private final boolean fIsBlockComment;
|
private final boolean fIsBlockComment;
|
||||||
private String fFilePath;
|
private String fFilePath;
|
||||||
|
|
||||||
public ASTComment(IASTTranslationUnit parent, String filePath, int offset, int endOffset, boolean isBlockComment) {
|
public ASTComment(IASTTranslationUnit parent, String filePath, int offset, int endOffset, boolean isBlockComment) {
|
||||||
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, offset, endOffset);
|
super(parent, IASTTranslationUnit.PREPROCESSOR_STATEMENT, offset, endOffset);
|
||||||
fIsBlockComment= isBlockComment;
|
fIsBlockComment= isBlockComment;
|
||||||
|
|
|
@ -68,8 +68,8 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C-Preprocessor providing tokens for the parsers. The class should not be used directly, rather than that
|
* C-Preprocessor providing tokens for the parsers. The class should not be used directly,
|
||||||
* you should be using the {@link IScanner} interface.
|
* rather than that you should be using the {@link IScanner} interface.
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
|
@ -87,8 +87,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
|
|
||||||
private static final char[] ONE = "1".toCharArray(); //$NON-NLS-1$
|
private static final char[] ONE = "1".toCharArray(); //$NON-NLS-1$
|
||||||
|
|
||||||
|
// Standard built-ins
|
||||||
// standard built-ins
|
|
||||||
private static final ObjectStyleMacro __CDT_PARSER__= new ObjectStyleMacro("__CDT_PARSER__".toCharArray(), ONE); //$NON-NLS-1$
|
private static final ObjectStyleMacro __CDT_PARSER__= new ObjectStyleMacro("__CDT_PARSER__".toCharArray(), ONE); //$NON-NLS-1$
|
||||||
private static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro("__cplusplus".toCharArray(), ONE); //$NON-NLS-1$
|
private static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro("__cplusplus".toCharArray(), ONE); //$NON-NLS-1$
|
||||||
private static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro("__STDC__".toCharArray(), ONE); //$NON-NLS-1$
|
private static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro("__STDC__".toCharArray(), ONE); //$NON-NLS-1$
|
||||||
|
@ -374,7 +373,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
|
||||||
return fLocationMap;
|
return fLocationMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureKeywords(ParserLanguage language, IScannerExtensionConfiguration configuration) {
|
private void configureKeywords(ParserLanguage language, IScannerExtensionConfiguration configuration) {
|
||||||
Keywords.addKeywordsPreprocessor(fPPKeywords);
|
Keywords.addKeywordsPreprocessor(fPPKeywords);
|
||||||
if (language == ParserLanguage.C) {
|
if (language == ParserLanguage.C) {
|
||||||
Keywords.addKeywordsC(fKeywords);
|
Keywords.addKeywordsC(fKeywords);
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||||
|
|
||||||
import static org.eclipse.cdt.core.parser.OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
|
import static org.eclipse.cdt.core.parser.OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
|
||||||
|
@ -39,7 +38,7 @@ public class IncludeGuardDetection {
|
||||||
Token t = l.nextToken();
|
Token t = l.nextToken();
|
||||||
if (t.getType() == IToken.tIDENTIFIER) {
|
if (t.getType() == IToken.tIDENTIFIER) {
|
||||||
char[] guard= null;
|
char[] guard= null;
|
||||||
switch(ppKeywords.get(t.getCharImage())) {
|
switch (ppKeywords.get(t.getCharImage())) {
|
||||||
case IPreprocessorDirective.ppIfndef:
|
case IPreprocessorDirective.ppIfndef:
|
||||||
// #ifndef GUARD
|
// #ifndef GUARD
|
||||||
t= l.nextToken();
|
t= l.nextToken();
|
||||||
|
@ -98,7 +97,7 @@ public class IncludeGuardDetection {
|
||||||
Token t= l.nextDirective();
|
Token t= l.nextDirective();
|
||||||
if (t.getType() == IToken.tEND_OF_INPUT)
|
if (t.getType() == IToken.tEND_OF_INPUT)
|
||||||
return true;
|
return true;
|
||||||
switch(ppKeywords.get(l.nextToken().getCharImage())) {
|
switch (ppKeywords.get(l.nextToken().getCharImage())) {
|
||||||
case IPreprocessorDirective.ppIf:
|
case IPreprocessorDirective.ppIf:
|
||||||
case IPreprocessorDirective.ppIfdef:
|
case IPreprocessorDirective.ppIfdef:
|
||||||
case IPreprocessorDirective.ppIfndef:
|
case IPreprocessorDirective.ppIfndef:
|
||||||
|
@ -124,7 +123,6 @@ public class IncludeGuardDetection {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean detectIncludeEndif(Lexer l) {
|
public static boolean detectIncludeEndif(Lexer l) {
|
||||||
l.saveState();
|
l.saveState();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue