1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 00:05:53 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2016-06-06 15:55:42 -07:00
parent 591f90c6d2
commit 941c435544

View file

@ -7,7 +7,7 @@
* *
* 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;
@ -20,10 +20,11 @@ import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
/** /**
* Helper class for detecting include guards * Helper class for detecting include guards.
*/ */
public class IncludeGuardDetection { 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); Lexer l= new Lexer(content, lexOptions, ILexerLog.NULL, null);
char[] guard= findIncludeGuard(l, ppKeywords); char[] guard= findIncludeGuard(l, ppKeywords);
if (guard != null && currentIfSpansFile(l, ppKeywords)) { if (guard != null && currentIfSpansFile(l, ppKeywords)) {
@ -34,7 +35,7 @@ public class IncludeGuardDetection {
private static char[] findIncludeGuard(Lexer l, CharArrayIntMap ppKeywords) { private static char[] findIncludeGuard(Lexer l, CharArrayIntMap ppKeywords) {
try { try {
if (skipAll(l, Lexer.tNEWLINE).getType() == IToken.tPOUND) { if (skipAll(l, Lexer.tNEWLINE).getType() == IToken.tPOUND) {
Token t = l.nextToken(); Token t = l.nextToken();
if (t.getType() == IToken.tIDENTIFIER) { if (t.getType() == IToken.tIDENTIFIER) {
char[] guard= null; char[] guard= null;
@ -49,7 +50,7 @@ public class IncludeGuardDetection {
case IPreprocessorDirective.ppIf: case IPreprocessorDirective.ppIf:
// #if !defined GUARD // #if !defined GUARD
// #if ((!((defined (GUARD))))) // #if ((!((defined (GUARD)))))
guard = findNotDefined(l); guard = findNotDefined(l);
break; break;
} }
if (guard != null) { if (guard != null) {
@ -73,7 +74,7 @@ public class IncludeGuardDetection {
Token t; Token t;
if (skipAll(l, IToken.tLPAREN).getType() == IToken.tNOT if (skipAll(l, IToken.tLPAREN).getType() == IToken.tNOT
&& checkToken(skipAll(l, IToken.tLPAREN), Keywords.cDEFINED)) { && 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) if (t.getType() == IToken.tLPAREN)
t= l.nextToken(); t= l.nextToken();
if (t.getType() == IToken.tIDENTIFIER) { if (t.getType() == IToken.tIDENTIFIER) {
@ -88,9 +89,9 @@ public class IncludeGuardDetection {
private static boolean checkToken(Token t, char[] image) throws OffsetLimitReachedException { private static boolean checkToken(Token t, char[] image) throws OffsetLimitReachedException {
return CharArrayUtils.equals(t.getCharImage(), image); return CharArrayUtils.equals(t.getCharImage(), image);
} }
private static boolean currentIfSpansFile(Lexer l, CharArrayIntMap ppKeywords) { 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 { try {
int nesting= 1; int nesting= 1;
while (nesting > 0) { while (nesting > 0) {
@ -114,9 +115,9 @@ public class IncludeGuardDetection {
} }
return true; return true;
} }
private static Token skipAll(Lexer l, int kind) throws OffsetLimitReachedException { private static Token skipAll(Lexer l, int kind) throws OffsetLimitReachedException {
// Skip empty lines // Skip empty lines.
Token t= l.nextToken(); Token t= l.nextToken();
while (t.getType() == kind) while (t.getType() == kind)
t= l.nextToken(); t= l.nextToken();
@ -144,7 +145,7 @@ public class IncludeGuardDetection {
return false; return false;
if (!checkToken(l.nextToken(), Keywords.cENDIF)) if (!checkToken(l.nextToken(), Keywords.cENDIF))
return false; return false;
return true; return true;
} }