mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 00:05:53 +02:00
Cosmetics.
This commit is contained in:
parent
591f90c6d2
commit
941c435544
1 changed files with 12 additions and 11 deletions
|
@ -7,7 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import static org.eclipse.cdt.core.parser.OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
|
||||
|
@ -20,10 +20,11 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
|
|||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||
|
||||
/**
|
||||
* Helper class for detecting include guards
|
||||
* Helper class for detecting include guards.
|
||||
*/
|
||||
public class IncludeGuardDetection {
|
||||
public static char[] detectIncludeGuard(AbstractCharArray content, Lexer.LexerOptions lexOptions, CharArrayIntMap ppKeywords) {
|
||||
public static char[] detectIncludeGuard(AbstractCharArray content, Lexer.LexerOptions lexOptions,
|
||||
CharArrayIntMap ppKeywords) {
|
||||
Lexer l= new Lexer(content, lexOptions, ILexerLog.NULL, null);
|
||||
char[] guard= findIncludeGuard(l, ppKeywords);
|
||||
if (guard != null && currentIfSpansFile(l, ppKeywords)) {
|
||||
|
@ -34,7 +35,7 @@ public class IncludeGuardDetection {
|
|||
|
||||
private static char[] findIncludeGuard(Lexer l, CharArrayIntMap ppKeywords) {
|
||||
try {
|
||||
if (skipAll(l, Lexer.tNEWLINE).getType() == IToken.tPOUND) {
|
||||
if (skipAll(l, Lexer.tNEWLINE).getType() == IToken.tPOUND) {
|
||||
Token t = l.nextToken();
|
||||
if (t.getType() == IToken.tIDENTIFIER) {
|
||||
char[] guard= null;
|
||||
|
@ -49,7 +50,7 @@ public class IncludeGuardDetection {
|
|||
case IPreprocessorDirective.ppIf:
|
||||
// #if !defined GUARD
|
||||
// #if ((!((defined (GUARD)))))
|
||||
guard = findNotDefined(l);
|
||||
guard = findNotDefined(l);
|
||||
break;
|
||||
}
|
||||
if (guard != null) {
|
||||
|
@ -73,7 +74,7 @@ public class IncludeGuardDetection {
|
|||
Token t;
|
||||
if (skipAll(l, IToken.tLPAREN).getType() == IToken.tNOT
|
||||
&& checkToken(skipAll(l, IToken.tLPAREN), Keywords.cDEFINED)) {
|
||||
t= l.nextToken(); // only a single parenthesis is allowed
|
||||
t= l.nextToken(); // Only a single parenthesis is allowed.
|
||||
if (t.getType() == IToken.tLPAREN)
|
||||
t= l.nextToken();
|
||||
if (t.getType() == IToken.tIDENTIFIER) {
|
||||
|
@ -88,9 +89,9 @@ public class IncludeGuardDetection {
|
|||
private static boolean checkToken(Token t, char[] image) throws OffsetLimitReachedException {
|
||||
return CharArrayUtils.equals(t.getCharImage(), image);
|
||||
}
|
||||
|
||||
|
||||
private static boolean currentIfSpansFile(Lexer l, CharArrayIntMap ppKeywords) {
|
||||
// Check if the #ifndef spans the entire file
|
||||
// Check if the #ifndef spans the entire file.
|
||||
try {
|
||||
int nesting= 1;
|
||||
while (nesting > 0) {
|
||||
|
@ -114,9 +115,9 @@ public class IncludeGuardDetection {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static Token skipAll(Lexer l, int kind) throws OffsetLimitReachedException {
|
||||
// Skip empty lines
|
||||
// Skip empty lines.
|
||||
Token t= l.nextToken();
|
||||
while (t.getType() == kind)
|
||||
t= l.nextToken();
|
||||
|
@ -144,7 +145,7 @@ public class IncludeGuardDetection {
|
|||
return false;
|
||||
if (!checkToken(l.nextToken(), Keywords.cENDIF))
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue