From 60de352b8e4537247b99c6f7e7431fe6250117ae Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 6 Aug 2011 20:14:16 -0700 Subject: [PATCH] Cosmetics. --- .../core/parser/scanner/CPreprocessor.java | 128 +++++++++++------- 1 file changed, 82 insertions(+), 46 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index 4687ae8fa83..a2fe8e155ce 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -6,10 +6,10 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation - * Anton Leherbauer (Wind River Systems) - * Markus Schorn (Wind River Systems) - * Sergey Prigogin (Google) + * IBM - Initial API and implementation + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; @@ -63,11 +63,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { public static final String PROP_VALUE = "CPreprocessor"; //$NON-NLS-1$ public static final int tDEFINED= IToken.FIRST_RESERVED_PREPROCESSOR; - public static final int tEXPANDED_IDENTIFIER= IToken.FIRST_RESERVED_PREPROCESSOR+1; - public static final int tSCOPE_MARKER= IToken.FIRST_RESERVED_PREPROCESSOR+2; - public static final int tSPACE= IToken.FIRST_RESERVED_PREPROCESSOR+3; - public static final int tNOSPACE= IToken.FIRST_RESERVED_PREPROCESSOR+4; - public static final int tMACRO_PARAMETER= IToken.FIRST_RESERVED_PREPROCESSOR+5; + public static final int tEXPANDED_IDENTIFIER= IToken.FIRST_RESERVED_PREPROCESSOR + 1; + public static final int tSCOPE_MARKER= IToken.FIRST_RESERVED_PREPROCESSOR + 2; + public static final int tSPACE= IToken.FIRST_RESERVED_PREPROCESSOR + 3; + public static final int tNOSPACE= IToken.FIRST_RESERVED_PREPROCESSOR + 4; + public static final int tMACRO_PARAMETER= IToken.FIRST_RESERVED_PREPROCESSOR + 5; private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE; private static final int ORIGIN_INACTIVE_CODE = OffsetLimitReachedException.ORIGIN_INACTIVE_CODE; @@ -81,7 +81,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { 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_HOSTED__ = new ObjectStyleMacro("__STDC_HOSTED__".toCharArray(), ONE); //$NON-NLS-1$ - private static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro("__STDC_VERSION__".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ + private static final ObjectStyleMacro __STDC_VERSION__ = + new ObjectStyleMacro("__STDC_VERSION__".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$ private static final DynamicMacro __FILE__= new FileMacro("__FILE__".toCharArray()); //$NON-NLS-1$ private static final DynamicMacro __DATE__= new DateMacro("__DATE__".toCharArray()); //$NON-NLS-1$ @@ -108,7 +109,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } }; - private static class IncludeResolution {String fLocation; boolean fHeuristic;} + private static class IncludeResolution { + String fLocation; + boolean fHeuristic; + } + final private IIncludeFileTester createPathTester= new IIncludeFileTester() { public IncludeResolution checkFile(String path, boolean isHeuristicMatch, IncludeSearchPathElement onPath) { if (fFileContentProvider.getInclusionExists(path)) { @@ -123,9 +128,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { private final class TokenSequence implements ITokenSequence { private final boolean fStopAtNewline; + TokenSequence(boolean stopAtNewline) { fStopAtNewline= stopAtNewline; } + public Token nextToken() throws OffsetLimitReachedException { final Lexer lexer= fCurrentContext.getLexer(); Token t= lexer.nextToken(); @@ -138,9 +145,11 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { return t; } + public int getLastEndOffset() { return fCurrentContext.getLexer().getLastEndOffset(); } + public Token currentToken() { Token t= fCurrentContext.currentLexerToken(); if (fStopAtNewline && t.getType() == Lexer.tNEWLINE) @@ -149,6 +158,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { return t; } } + TokenSequence fInputToMacroExpansion= new TokenSequence(false); TokenSequence fLineInputToMacroExpansion= new TokenSequence(true); @@ -191,9 +201,9 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { private InternalFileContent fRootContent; - - public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, IParserLogService log, - IScannerExtensionConfiguration configuration, IncludeFileContentProvider readerFactory) { + public CPreprocessor(FileContent fileContent, IScannerInfo info, ParserLanguage language, + IParserLogService log, IScannerExtensionConfiguration configuration, + IncludeFileContentProvider readerFactory) { if (readerFactory instanceof InternalFileContentProvider) { fFileContentProvider= (InternalFileContentProvider) readerFactory; } else if (readerFactory == null) { @@ -320,7 +330,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { return ScannerUtility.createReconciledPath(directory.getAbsolutePath(), inlcudePath); } - private void setupMacroDictionary(IScannerExtensionConfiguration config, IScannerInfo info, ParserLanguage lang) { + private void setupMacroDictionary(IScannerExtensionConfiguration config, IScannerInfo info, + ParserLanguage lang) { // built in macros fMacroDictionary.put(__CDT_PARSER__.getNameCharArray(), __CDT_PARSER__); fMacroDictionary.put(__STDC__.getNameCharArray(), __STDC__); @@ -530,7 +541,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { Token t4= fetchToken(); end= t4.getEndOffset(); if (t4.getType() == IToken.tRPAREN) { - fLocationMap.encounterPragmaOperator(t1.getOffset(), t3.getOffset(), t3.getEndOffset(), t4.getEndOffset()); + fLocationMap.encounterPragmaOperator(t1.getOffset(), t3.getOffset(), + t3.getEndOffset(), t4.getEndOffset()); return; } else { end= t3.getEndOffset(); @@ -549,7 +561,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { end= t1.getEndOffset(); pushbackToken(t2); } - fLocationMap.encounterProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, t1.getCharImage(), t1.getOffset(), end); + fLocationMap.encounterProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, t1.getCharImage(), + t1.getOffset(), end); } /** @@ -591,7 +604,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { case IToken.tUTF32STRING: StringType st = StringType.fromToken(tt1); Token t2; - StringBuffer buf= null; + StringBuilder buf= null; int endOffset= 0; loop: while (true) { t2= fetchToken(); @@ -603,7 +616,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { case IToken.tUTF32STRING: st = StringType.max(st, StringType.fromToken(tt2)); if (buf == null) { - buf= new StringBuffer(); + buf= new StringBuilder(); appendStringContent(buf, t1); } appendStringContent(buf, t2); @@ -671,7 +684,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { return fCurrentContext.getCodeBranchNesting(); } - private void appendStringContent(StringBuffer buf, Token t1) { + private void appendStringContent(StringBuilder buf, Token t1) { final char[] image= t1.getCharImage(); final int length= image.length; int start = 1; @@ -689,7 +702,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { } } - Token internalFetchToken(final ScannerContext uptoEndOfCtx, int options, boolean withinExpansion) throws OffsetLimitReachedException { + Token internalFetchToken(final ScannerContext uptoEndOfCtx, int options, boolean withinExpansion) + throws OffsetLimitReachedException { Token ppToken= fCurrentContext.currentLexerToken(); while (true) { switch (ppToken.getType()) { @@ -890,7 +904,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { continue loop; } } - for (int i=0; i