Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2007-12-21 09:35:52 +0000
committerMarkus Schorn2007-12-21 09:35:52 +0000
commit1e43fc3186e6292fd5ee3e164619f67280d801ee (patch)
tree0a1d77d10227908621a222b2cafe419aafb37f2c /core/org.eclipse.cdt.core/parser
parent74659247c59ab95bfd31fdfc5db08804f8f3ef6e (diff)
downloadorg.eclipse.cdt-1e43fc3186e6292fd5ee3e164619f67280d801ee.tar.gz
org.eclipse.cdt-1e43fc3186e6292fd5ee3e164619f67280d801ee.tar.xz
org.eclipse.cdt-1e43fc3186e6292fd5ee3e164619f67280d801ee.zip
Removes DOMScanner and related classes, cleans up interfaces IScanner and IIndexMacro, (bug 212864).
Diffstat (limited to 'core/org.eclipse.cdt.core/parser')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java54
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java118
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java18
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java22
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java7
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexMacro.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java20
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java35
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java32
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java96
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTComment.java99
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java72
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IRequiresLocationInformation.java25
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java103
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java21
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java95
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPBasicType.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java17
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeTypeContainer.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java3
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java34
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IIndexBasedCodeReaderFactory.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IIndexBasedCodeReaderFactory.java)2
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java11
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java33
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java20
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerProblemFactory.java)6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java (renamed from core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java)4
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java4267
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java1413
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java44
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicFunctionStyleMacro.java29
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java42
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java1076
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java71
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java144
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java52
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java53
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IDependencyNodeHost.java19
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java56
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java110
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java48
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InvalidPreprocessorNodeException.java36
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java2937
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroBinding.java80
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroExpansionToken.java157
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java46
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java240
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java331
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java485
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java20
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java228
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TodoTaskParser.java6
70 files changed, 411 insertions, 12704 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java
index d19e9eb36fe..628e2c2d561 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/IMacroCollector.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.core.dom;
-import org.eclipse.cdt.core.parser.IMacro;
+import org.eclipse.cdt.core.index.IIndexMacro;
/**
* Allows an ICodeReaderFactory to retrieve macro definitions from the index,
@@ -27,7 +27,8 @@ import org.eclipse.cdt.core.parser.IMacro;
* @since 4.0
*
*/
+// mstodo get rid of this interface
public interface IMacroCollector {
- public void addDefinition(IMacro macro);
+ public void addMacroDefinition(IIndexMacro macro);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
index 72f1cae2c25..ce498984c27 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTSignatureUtil.java
@@ -724,16 +724,7 @@ public class ASTSignatureUtil {
}
private static String getLiteralExpression( IASTLiteralExpression expression ){
- StringBuffer result = new StringBuffer();
- result.append(expression.toString());
- if (expression.getKind() == IASTLiteralExpression.lk_string_literal) {
- // mstodo- old scanner, remove
- if (result.length() == 0 || result.charAt(0) != '"') {
- result.insert(0, '"');
- result.append('"');
- }
- }
- return result.toString();
+ return expression.toString();
}
private static String getIdExpression( IASTIdExpression expression ){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java
index e41814cea46..cf37fc7b365 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.java
@@ -173,15 +173,6 @@ public interface IASTTranslationUnit extends IASTNode, IAdaptable {
public IASTProblem[] getPreprocessorProblems();
/**
- * For a given range of locations, return a String that represents what is there underneath the range.
- *
- * @param locations A range of node locations
- * @return A String signature.
- * @deprecated was never fully implemented.
- */
- public String getUnpreprocessedSignature(IASTNodeLocation[] locations);
-
- /**
* Get the translation unit's full path.
* @return String representation of path.
*/
@@ -246,13 +237,6 @@ public interface IASTTranslationUnit extends IASTNode, IAdaptable {
*/
public void setIndex(IIndex index);
- /**
- * Set comments to translation unit.
- *
- * @param comment
- */
- public void setComments(IASTComment[] comments);
-
/**
* In case the ast was created in a way that supports comment parsing,
* all comments of the translation unit are returned. Otherwise an
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java
index cfc97efdf20..58eac5ed0a2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/AbstractScannerExtensionConfiguration.java
@@ -7,13 +7,12 @@
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.parser;
+import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
-import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
/**
* Abstract scanner extension configuration to help model C/C++ dialects.
@@ -28,6 +27,22 @@ import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
* @since 4.0
*/
public abstract class AbstractScannerExtensionConfiguration implements IScannerExtensionConfiguration {
+ protected static class MacroDefinition implements IMacro {
+ private char[] fSignature;
+ private char[] fExpansion;
+
+ MacroDefinition(char[] signature, char[] expansion) {
+ fSignature= signature;
+ fExpansion= expansion;
+ }
+
+ public char[] getSignature() {
+ return fSignature;
+ }
+ public char[] getExpansion() {
+ return fExpansion;
+ }
+ }
/*
* @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#initializeMacroValuesTo1()
@@ -64,10 +79,8 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE
return null;
}
- /*
- * @see org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration#getAdditionalMacros()
- */
- public CharArrayObjectMap getAdditionalMacros() {
+
+ public IMacro[] getAdditionalMacros() {
return null;
}
@@ -80,14 +93,11 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE
/**
* Helper method to add an object style macro to the given map.
- *
- * @param macros the macro map
- * @param name the macro name
+ * @param signature the signature of the macro, see {@link IMacro#getSignature()}.
* @param value the macro value
*/
- protected void addObjectStyleMacro(CharArrayObjectMap macros, String name, String value) {
- char[] nameChars= name.toCharArray();
- macros.put(nameChars, new ObjectStyleMacro(nameChars, value.toCharArray()));
+ protected static IMacro createMacro(String signature, String value) {
+ return new MacroDefinition(signature.toCharArray(), value.toCharArray());
}
/**
@@ -98,13 +108,19 @@ public abstract class AbstractScannerExtensionConfiguration implements IScannerE
* @param value the macro value
* @param arguments the macro arguments
*/
- protected void addFunctionStyleMacro(CharArrayObjectMap macros, String name, String value, String[] arguments) {
- char[] nameChars= name.toCharArray();
- char[][] argumentsArray= new char[arguments.length][];
+ protected static IMacro createFunctionStyleMacro(String name, String value, String[] arguments) {
+ StringBuffer buf= new StringBuffer();
+ buf.append(name);
+ buf.append('(');
for (int i = 0; i < arguments.length; i++) {
- argumentsArray[i]= arguments[i].toCharArray();
+ if (i>0) {
+ buf.append(',');
+ }
+ buf.append(arguments[i]);
}
- macros.put(nameChars, new FunctionStyleMacro(nameChars, value.toCharArray(), argumentsArray));
+ buf.append(')');
+ char[] signature= new char[buf.length()];
+ buf.getChars(0, signature.length, signature, 0);
+ return new MacroDefinition(signature, value.toCharArray());
}
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java
index 02e0235115a..29e93d9242f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/GNUScannerExtensionConfiguration.java
@@ -6,24 +6,47 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.parser;
+import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.IPreprocessorDirective;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
-import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
/**
* @author jcamelon
*/
public abstract class GNUScannerExtensionConfiguration extends AbstractScannerExtensionConfiguration {
- protected static final char[] emptyCharArray = "".toCharArray(); //$NON-NLS-1$
+ private static IMacro[] sAdditionalMacros= new IMacro[] {
+ createMacro("__asm__", "asm"), //$NON-NLS-1$//$NON-NLS-2$
+ createMacro("__complex__", "_Complex"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__const__", "const"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__const", "const"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__extension__", ""), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__inline__", "inline"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__imag__", "(int)"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__null", "(void *)0"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__real__", "(int)"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__restrict__", "restrict"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__restrict", "restrict"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__volatile__", "volatile"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__signed__", "signed"), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__stdcall", ""), //$NON-NLS-1$ //$NON-NLS-2$
+ createMacro("__typeof__", "typeof"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ createMacro("__builtin_va_arg(ap,type)", "*(type *)ap"), //$NON-NLS-1$//$NON-NLS-2$
+ createMacro("__builtin_constant_p(exp)", "0") //$NON-NLS-1$//$NON-NLS-2$
+ };
+
+ public static IMacro[] getAdditionalGNUMacros() {
+ return sAdditionalMacros;
+ }
+
public boolean initializeMacroValuesTo1() {
return true;
@@ -36,86 +59,9 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
public char[] supportAdditionalNumericLiteralSuffixes() {
return "ij".toCharArray(); //$NON-NLS-1$
}
-
- private static final ObjectStyleMacro __asm__ = new ObjectStyleMacro(
- "__asm__".toCharArray(), "asm".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
-
- private static final ObjectStyleMacro __inline__ = new ObjectStyleMacro(
- "__inline__".toCharArray(), "inline".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __extension__ = new ObjectStyleMacro(
- "__extension__".toCharArray(), emptyCharArray); //$NON-NLS-1$
-
-
- private static final ObjectStyleMacro __restrict__ = new ObjectStyleMacro(
- "__restrict__".toCharArray(), "restrict".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __restrict = new ObjectStyleMacro(
- "__restrict".toCharArray(), "restrict".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __volatile__ = new ObjectStyleMacro(
- "__volatile__".toCharArray(), "volatile".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __const__ = new ObjectStyleMacro(
- "__const__".toCharArray(), "const".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __const = new ObjectStyleMacro(
- "__const".toCharArray(), "const".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __signed__ = new ObjectStyleMacro(
- "__signed__".toCharArray(), "signed".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __complex__ = new ObjectStyleMacro(
- "__complex__".toCharArray(), "_Complex".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __real__ = new ObjectStyleMacro(
- "__real__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __imag__ = new ObjectStyleMacro(
- "__imag__".toCharArray(), "(int)".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final ObjectStyleMacro __null = new ObjectStyleMacro(
- "__null".toCharArray(), "(void *)0".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final FunctionStyleMacro __builtin_va_arg = new FunctionStyleMacro(
- "__builtin_va_arg".toCharArray(), //$NON-NLS-1$
- "*(type *)ap".toCharArray(), //$NON-NLS-1$
- new char[][] { "ap".toCharArray(), "type".toCharArray() }); //$NON-NLS-1$//$NON-NLS-2$
-
- private static final FunctionStyleMacro __builtin_constant_p = new FunctionStyleMacro(
- "__builtin_constant_p".toCharArray(), //$NON-NLS-1$
- "0".toCharArray(), //$NON-NLS-1$
- new char[][] { "exp".toCharArray() }); //$NON-NLS-1$
-
- // Kludge for MSVC support until we get a real extension
- private static final ObjectStyleMacro __stdcall = new ObjectStyleMacro(
- "__stdcall".toCharArray(), emptyCharArray); //$NON-NLS-1$
-
- /**
- * @return
- */
- public CharArrayObjectMap getAdditionalMacros() {
- CharArrayObjectMap realDefinitions = new CharArrayObjectMap(16);
- realDefinitions.put(__inline__.name, __inline__);
- realDefinitions.put(__const__.name, __const__);
- realDefinitions.put(__const.name, __const);
- realDefinitions.put(__extension__.name, __extension__);
- realDefinitions.put(__restrict__.name, __restrict__);
- realDefinitions.put(__restrict.name, __restrict);
- realDefinitions.put(__volatile__.name, __volatile__);
- realDefinitions.put(__signed__.name, __signed__);
- realDefinitions.put(__complex__.name, __complex__);
- realDefinitions.put(__imag__.name, __imag__);
- realDefinitions.put( __null.name, __null );
- realDefinitions.put(__real__.name, __real__);
- realDefinitions.put(__builtin_va_arg.name, __builtin_va_arg);
- realDefinitions.put(__builtin_constant_p.name, __builtin_constant_p);
- realDefinitions.put( __asm__.name, __asm__ );
- realDefinitions.put(__stdcall.name, __stdcall);
-
- return realDefinitions;
+ public IMacro[] getAdditionalMacros() {
+ return sAdditionalMacros;
}
/*
@@ -132,5 +78,5 @@ public abstract class GNUScannerExtensionConfiguration extends AbstractScannerEx
additionalPPKeywords.put(Keywords.cUNASSERT, IPreprocessorDirective.ppIgnore);
return additionalPPKeywords;
}
-
+
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java
index 151a7e0127a..68786462bb0 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/IScannerExtensionConfiguration.java
@@ -6,13 +6,15 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom.parser;
+import org.eclipse.cdt.core.parser.IMacro;
+import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
/**
* Scanner extension configuration interface.
@@ -69,19 +71,15 @@ public interface IScannerExtensionConfiguration {
* Support for additional keywords.
*
* @return a mapping of keyword name to one of the constants defined in
- * {@link org.eclipse.cdt.core.parser.IToken IToken} or
- * <code>null</code> for no additional keywords.
+ * {@link IToken} or <code>null</code> for no additional keywords.
*/
public CharArrayIntMap getAdditionalKeywords();
/**
* Support for additional macros.
- *
- * @return a mapping of macro name to
- * {@link org.eclipse.cdt.core.parser.IMacro IMacro} or
- * <code>null</code> for no additional macros.
+ * @return an array of macros or <code>null</code> for no additional macros.
*/
- public CharArrayObjectMap getAdditionalMacros();
+ public IMacro[] getAdditionalMacros();
/**
* Support for additional preprocessor directives.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java
index 2f5e7f654ac..4a6671a17b3 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/AbstractCLanguage.java
@@ -41,7 +41,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
-import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.c.PDOMCLinkageFactory;
@@ -152,11 +151,7 @@ public abstract class AbstractCLanguage extends AbstractLanguage implements ICLa
* @return an instance of IScanner
*/
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
- if (!DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
- return new CPreprocessor(reader, scanInfo, ParserLanguage.C, log, getScannerExtensionConfiguration(), fileCreator);
- }
- return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C,
- log, getScannerExtensionConfiguration(), fileCreator);
+ return new CPreprocessor(reader, scanInfo, ParserLanguage.C, log, getScannerExtensionConfiguration(), fileCreator);
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java
index 93172a05a64..72cdd51afeb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c/GCCScannerExtensionConfiguration.java
@@ -14,15 +14,22 @@ package org.eclipse.cdt.core.dom.parser.c;
import org.eclipse.cdt.core.dom.parser.GNUScannerExtensionConfiguration;
import org.eclipse.cdt.core.parser.GCCKeywords;
import org.eclipse.cdt.core.parser.IGCCToken;
+import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
/**
* @author jcamelon
*/
public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfiguration {
+ private static IMacro[] sAdditionalMacros;
+ static {
+ final IMacro[] macros = GNUScannerExtensionConfiguration.getAdditionalGNUMacros();
+ sAdditionalMacros= new IMacro[macros.length+1];
+ System.arraycopy(macros, 0, sAdditionalMacros, 0, macros.length);
+ sAdditionalMacros[macros.length]= createMacro("_Pragma(arg)", ""); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#supportMinAndMaxOperators()
*/
@@ -30,19 +37,12 @@ public class GCCScannerExtensionConfiguration extends GNUScannerExtensionConfigu
return false;
}
- private static final FunctionStyleMacro _Pragma = new FunctionStyleMacro(
- "_Pragma".toCharArray(), //$NON-NLS-1$
- emptyCharArray,
- new char[][] { "arg".toCharArray() } ); //$NON-NLS-1$
-
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
*/
- public CharArrayObjectMap getAdditionalMacros() {
- CharArrayObjectMap result = super.getAdditionalMacros();
- result.put(_Pragma.name, _Pragma );
- return result;
+ public IMacro[] getAdditionalMacros() {
+ return sAdditionalMacros;
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java
index 18cab1fa647..c744759ce1b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp/AbstractCPPLanguage.java
@@ -40,7 +40,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
-import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
import org.eclipse.cdt.internal.core.pdom.dom.IPDOMLinkageFactory;
import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPLinkageFactory;
@@ -148,11 +147,7 @@ public abstract class AbstractCPPLanguage extends AbstractLanguage implements IC
* @return an instance of IScanner
*/
protected IScanner createScanner(CodeReader reader, IScannerInfo scanInfo, ICodeReaderFactory fileCreator, IParserLogService log) {
- if (!DOMScanner.PROP_VALUE.equals(System.getProperty("scanner"))) { //$NON-NLS-1$
- return new CPreprocessor(reader, scanInfo, ParserLanguage.CPP, log, getScannerExtensionConfiguration(), fileCreator);
- }
- return new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP,
- log, getScannerExtensionConfiguration(), fileCreator);
+ return new CPreprocessor(reader, scanInfo, ParserLanguage.CPP, log, getScannerExtensionConfiguration(), fileCreator);
}
/**
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexMacro.java
index 8c4ab511273..f6ab17ff035 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexMacro.java
@@ -12,7 +12,7 @@
package org.eclipse.cdt.core.index;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
-import org.eclipse.cdt.core.parser.IMacro;
+import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.core.runtime.CoreException;
/**
@@ -29,10 +29,7 @@ import org.eclipse.core.runtime.CoreException;
*
* @since 4.0
*/
-// mstodo scanner removal: IIndexMacro should extend IMacroBinding. However, the DOMScanner requires
-// the delivery of some internal representation of macros. That's what this interface seems to be
-// trimmed to.
-public interface IIndexMacro extends IMacro {
+public interface IIndexMacro extends IMacroBinding {
IIndexMacro[] EMPTY_INDEX_MACRO_ARRAY = new IIndexMacro[0];
@@ -58,10 +55,4 @@ public interface IIndexMacro extends IMacro {
* Returns the length of the name.
*/
public int getNodeLength();
-
- /**
- * Returns the parameter names or <code>null</code> if this is not a function style macro
- * @since 5.0
- */
- char[][] getParameterList();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java
index 5942fb288dd..00e0bce4af6 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IMacro.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,20 +7,24 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
-/*
- * Created on Sep 16, 2004
- */
package org.eclipse.cdt.core.parser;
/**
- * @author aniefer
+ * Interface to provide macro definitions in an IScannerExtensionConfiguration.
*/
public interface IMacro {
- //For object-like macros these will be the same,
- //for function-like macros, the signature includes the parameters
+ /**
+ * Return the signature of a macro, which is the name for object style macros and
+ * the name followed by the comma-separated parameters put in parenthesis. For
+ * example: 'funcStyleMacro(par1, par2)'.
+ */
public char[] getSignature();
- public char[] getName();
+
+ /**
+ * Returns the expansion for this macro.
+ */
public char[] getExpansion();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
index 8bfd35e2734..202d307cdb7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/IScanner.java
@@ -7,25 +7,25 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.parser;
import java.util.Map;
import org.eclipse.cdt.core.dom.IMacroCollector;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
+import org.eclipse.cdt.core.dom.ast.IMacroBinding;
+import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
+import org.eclipse.cdt.internal.core.parser.scanner.Lexer;
/**
- * @author jcamelon
- *
+ * Interface between the parser and the preprocessor.
* <p>
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
* part of a work in progress. There is no guarantee that this API will
* work or that it will remain the same. Please do not use this API without
* consulting with the CDT team.
* </p>
- *
*/
public interface IScanner extends IMacroCollector {
@@ -46,22 +46,33 @@ public interface IScanner extends IMacroCollector {
* @since 5.0
*/
public void setComputeImageLocations(boolean val);
-
- public IMacro addDefinition(char[] key, char[] value);
- public void addDefinition(IMacro macro);
- public Map getDefinitions();
- public String[] getIncludePaths();
+ /**
+ * Returns a map from {@link String} to {@link IMacroBinding} containing
+ * all the definitions that are defined at the current point in the
+ * process of scanning.
+ */
+ public Map getDefinitions();
+ /**
+ * Returns next token for the parser. String literals are concatenated.
+ * @throws EndOfFileException when the end of the translation unit has been reached.
+ * @throws OffsetLimitReachedException see {@link Lexer}.
+ */
public IToken nextToken() throws EndOfFileException;
- public int getCount();
/**
* Returns <code>true</code>, whenever we are processing the outermost file of the translation unit.
*/
public boolean isOnTopContext();
- public CharArrayObjectMap getRealDefinitions();
+
+ /**
+ * Attempts to cancel the scanner.
+ */
public void cancel();
+ /**
+ * Returns the location resolver associated with this scanner.
+ */
public ILocationResolver getLocationResolver();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java
index a3062c556ac..f175875991f 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/OffsetLimitReachedException.java
@@ -34,32 +34,11 @@ public class OffsetLimitReachedException extends EndOfFileException {
public static final int ORIGIN_INACTIVE_CODE = 3;
public static final int ORIGIN_MACRO_EXPANSION = 4;
- private final String prefix;
private final IToken finalToken;
private final int fOrigin;
-
- /**
- * mstodo- scanner removal
- * @deprecated
- * @param prefix
- */
- public OffsetLimitReachedException( String prefix )
- {
- this.prefix= prefix;
- finalToken = null;
- fOrigin= ORIGIN_UNKNOWN;
- }
-
- public OffsetLimitReachedException( IToken token )
- {
- fOrigin= ORIGIN_UNKNOWN;
- prefix= token.getImage();
- finalToken = token;
- }
-
+
public OffsetLimitReachedException(int origin, IToken lastToken) {
fOrigin= origin;
- prefix= lastToken.getImage();
finalToken= lastToken;
}
@@ -76,13 +55,4 @@ public class OffsetLimitReachedException extends EndOfFileException {
public IToken getFinalToken() {
return finalToken;
}
-
- /**
- * mstodo- scanner removal
- * @return returns the IASTCompletionNode
- * @deprecated
- */
- public String getPrefix() {
- return prefix;
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java
deleted file mode 100644
index fc4973d2de6..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ast/IASTCompletionNode.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Rational Software - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.core.parser.ast;
-
-import org.eclipse.cdt.core.parser.Enum;
-
-
-/**
- * @author jcamelon
- *
- */
-public interface IASTCompletionNode {
-
- public static class CompletionKind extends Enum {
-
- // class member declaration type reference
- public static final CompletionKind FIELD_TYPE = new CompletionKind( 2 );
-
- // stand-alone declaration type reference
- public static final CompletionKind VARIABLE_TYPE = new CompletionKind( 3 );
-
- // function/method argument type reference
- public static final CompletionKind ARGUMENT_TYPE = new CompletionKind( 4 );
-
- // inside code body - name reference || int X::[ ]
- public static final CompletionKind SINGLE_NAME_REFERENCE = new CompletionKind( 5 );
-
- // any place one can expect a type
- public static final CompletionKind TYPE_REFERENCE = new CompletionKind( 6 );
-
- // any place where one can expect a class name
- public static final CompletionKind CLASS_REFERENCE = new CompletionKind( 7 );
-
- // any place where a namespace name is expected
- public static final CompletionKind NAMESPACE_REFERENCE = new CompletionKind( 8 );
-
- // any place where an exception name is expected
- public static final CompletionKind EXCEPTION_REFERENCE = new CompletionKind( 9 );
-
- // any place where exclusively a preprocessor macro name would be expected
- public static final CompletionKind MACRO_REFERENCE = new CompletionKind( 10 );
-
- // any place where constructor parameters are expected
- public static final CompletionKind CONSTRUCTOR_REFERENCE = new CompletionKind( 12 );
-
- // any place where exclusively a preprocessor directive is expected
- public static final CompletionKind PREPROCESSOR_DIRECTIVE = new CompletionKind( 13 );
-
- // any place where function parameters are expected
- public static final CompletionKind FUNCTION_REFERENCE = new CompletionKind( 15 );
-
- // after a new expression
- public static final CompletionKind NEW_TYPE_REFERENCE = new CompletionKind( 16 );
-
- // inside something that does not reach the parser - (#ifdefed out/comment)
- public static final CompletionKind UNREACHABLE_CODE = new CompletionKind( 17 );
-
- // structs only
- public static final CompletionKind STRUCT_REFERENCE = new CompletionKind( 18 );
-
- // unions only
- public static final CompletionKind UNION_REFERENCE = new CompletionKind( 19 );
-
- // enums only
- public static final CompletionKind ENUM_REFERENCE = new CompletionKind( 20 );
-
- // error condition -- a place in the grammar where there is nothing to lookup
- public static final CompletionKind NO_SUCH_KIND = new CompletionKind( 200 );
- /**
- * @param enumValue
- */
- protected CompletionKind(int enumValue) {
- super(enumValue);
- }
-
- }
-
-
- /**
- * @return kind of completion expected
- */
- public CompletionKind getCompletionKind();
-
- /**
- * @return the prefix
- */
- public String getCompletionPrefix();
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java
index 373e87ad3c7..15155e713ce 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/CharArrayMap.java
@@ -84,13 +84,13 @@ public final class CharArrayMap/*<V>*/ {
public int hashCode() {
int result = 17;
for(int i = start; i < start+length; i++) {
- result = 37 * result + (int)buffer[i];
+ result = 37 * result + buffer[i];
}
return result;
}
public String toString() {
- return "'" + new String(buffer, start, length) + "'@(" + start + "," + length + ")";
+ return "'" + new String(buffer, start, length) + "'@(" + start + "," + length + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTComment.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTComment.java
deleted file mode 100644
index 2c458284dbb..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTComment.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Institute for Software, HSR Hochschule fuer Technik
- * Rapperswil, University of applied sciences and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Emanuel Graf & Leo Buettiker - initial API and implementation
- * Guido Zgraggen
- ******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.parser;
-
-import org.eclipse.cdt.core.dom.ast.ASTVisitor;
-import org.eclipse.cdt.core.dom.ast.IASTComment;
-import org.eclipse.cdt.core.parser.IToken;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
-
-/**
- * @author egraf
- *
- */
-public class ASTComment extends ASTNode implements IASTComment {
-
- private char[] comment;
-
- private boolean blockComment;
-
- public ASTComment(IToken commentTocken){
- switch(commentTocken.getType()){
- case IToken.tCOMMENT:
- blockComment = false;
- break;
- case IToken.tBLOCKCOMMENT:
- blockComment = true;
- break;
- default:
- throw new IllegalArgumentException("No Comment Token"); //$NON-NLS-1$
- }
- comment = commentTocken.getImage().toCharArray();
- setOffsetAndLength(commentTocken.getOffset(), commentTocken.getLength());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.dom.parser.ASTNode#accept(org.eclipse.cdt.core.dom.ast.ASTVisitor)
- */
- public boolean accept(ASTVisitor visitor) {
- if (visitor.shouldVisitComments) {
- switch (visitor.visit(this)) {
- case ASTVisitor.PROCESS_ABORT:
- return false;
- case ASTVisitor.PROCESS_SKIP:
- return true;
- default:
- break;
- }
- }
- return true;
- }
-
- /**
- * @return the comment
- */
- public char[] getComment() {
- return comment;
- }
-
- /**
- * @param comment the comment to set
- */
- public void setComment(char[] comment) {
- this.comment = comment;
- }
-
- public boolean isBlockComment() {
- return blockComment;
- }
-
-
- public boolean equals(Object obj) {
- if(! (obj instanceof ASTComment))
- return false;
- ASTComment com2 = (ASTComment)obj;
- if(getOffset() == com2.getOffset() && getLength() == com2.getLength()){
- return true;
- }else{
- return false;
- }
- }
-
- public static IASTComment[] addComment(IASTComment[] comments, IASTComment comment) {
- if(!ArrayUtil.contains(comments, comment)){
- comments = (IASTComment[]) ArrayUtil.append(IASTComment.class, comments, comment);
- }
-
- return comments;
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java
index b57717e7b83..5b1e725b34b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java
@@ -89,7 +89,7 @@ public abstract class ASTNode implements IASTNode {
else {
final IASTTranslationUnit tu= getTranslationUnit();
if (tu != null) {
- org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver l= (org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver) tu.getAdapter(org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver.class);
+ ILocationResolver l= (ILocationResolver) tu.getAdapter(ILocationResolver.class);
if (l != null) {
locations= l.getLocations(offset, length);
}
@@ -117,10 +117,6 @@ public abstract class ASTNode implements IASTNode {
if (lr != null) {
return new String(lr.getUnpreprocessedSignature(getFileLocation()));
}
- else {
- // mstodo- old location resolver, remove
- return ast.getUnpreprocessedSignature(getNodeLocations());
- }
}
return ""; //$NON-NLS-1$
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index 78b1afdf868..249611a7eda 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -21,7 +21,6 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
-import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
@@ -93,16 +92,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected final boolean supportKnRC;
- protected IASTComment[] comments = new ASTComment[0];
-
protected final boolean supportAttributeSpecifiers;
protected final boolean supportDeclspecSpecifiers;
protected final IBuiltinBindingsProvider builtinBindingsProvider;
- private IToken lastTokenFromScanner;
-
protected AbstractGNUSourceCodeParser(IScanner scanner,
IParserLogService logService, ParserMode parserMode,
boolean supportStatementsInExpressions,
@@ -254,29 +249,13 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
* thrown when the scanner.nextToken() yields no tokens
*/
protected IToken fetchToken() throws EndOfFileException {
- IToken value= null;
- boolean adjustNextToken= false;
try {
- value= scanner.nextToken();
- // Put the Comments in the Array for later processing
- int type = value.getType();
- while(type == IToken.tCOMMENT || type == IToken.tBLOCKCOMMENT){
- IASTComment comment = createComment(value);
- comments = ASTComment.addComment(comments, comment);
- value = scanner.nextToken();
- type= value.getType();
- adjustNextToken= true;
- }
+ return scanner.nextToken();
} catch (OffsetLimitReachedException olre) {
handleOffsetLimitException(olre);
- value= null;
- }
-
- if (lastTokenFromScanner != null && adjustNextToken) {
- lastTokenFromScanner.setNext(value);
+ // never returns, to make the java-compiler happy:
+ return null;
}
- lastTokenFromScanner= value;
- return value;
}
protected boolean isCancelled = false;
@@ -333,7 +312,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
*/
public synchronized void cancel() {
isCancelled = true;
- scanner.cancel();
}
/**
@@ -1425,19 +1403,39 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected IASTDeclaration asmDeclaration() throws EndOfFileException,
BacktrackException {
IToken first = consume(); // t_asm
- consume(IToken.tLPAREN);
- char[] assemblyChars = consume(IToken.tSTRING).getCharImage();
- String assembly;
- if (assemblyChars.length > 2 && assemblyChars[0] == '"') {
- assembly= new String(assemblyChars, 1, assemblyChars.length-2);
+ IToken next= LA(1);
+ if (next.getType() == IToken.t_volatile) {
+ consume();
}
- else {
- assembly= new String(assemblyChars);
+
+ consume(IToken.tLPAREN);
+ boolean needspace= false;
+ StringBuffer buffer= new StringBuffer();
+ int open= 1;
+ while (open > 0) {
+ IToken t= consume();
+ switch(t.getType()) {
+ case IToken.tLPAREN:
+ open++;
+ break;
+ case IToken.tRPAREN:
+ open--;
+ break;
+ case IToken.tEOC:
+ throw new EndOfFileException();
+
+ default:
+ if (needspace) {
+ buffer.append(' ');
+ }
+ buffer.append(t.getCharImage());
+ needspace= true;
+ break;
+ }
}
- consume(IToken.tRPAREN);
int lastOffset = consume(IToken.tSEMI).getEndOffset();
- return buildASMDirective(first.getOffset(), assembly, lastOffset);
+ return buildASMDirective(first.getOffset(), buffer.toString(), lastOffset);
}
/**
@@ -2266,10 +2264,4 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
return false;
}
-
- /**
- * Creates the ast node for a comment.
- * @since 4.0
- */
- protected abstract IASTComment createComment(IToken commentToken) throws EndOfFileException;
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java
index 13394247d4c..9e236ce6462 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/GCCBuiltinSymbolProvider.java
@@ -263,19 +263,19 @@ public class GCCBuiltinSymbolProvider implements IBuiltinBindingsProvider {
cpp_const_char_p_r = new GPPPointerType(new CPPQualifierType(cpp_char, true, false), false, false, true);
cpp_double = new CPPBasicType(IBasicType.t_double, 0);
- cpp_double_complex = new GPPBasicType(IBasicType.t_double, GPPBasicType.IS_COMPLEX, null);
+ cpp_double_complex = new GPPBasicType(IBasicType.t_double, ICPPBasicType.IS_COMPLEX, null);
cpp_float = new CPPBasicType(IBasicType.t_float, 0);
- cpp_float_complex = new GPPBasicType(IBasicType.t_float, GPPBasicType.IS_COMPLEX, null);
+ cpp_float_complex = new GPPBasicType(IBasicType.t_float, ICPPBasicType.IS_COMPLEX, null);
cpp_int = new CPPBasicType(IBasicType.t_int, 0);
cpp_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG);
cpp_long_double = new CPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG);
- cpp_long_double_complex = new GPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG | GPPBasicType.IS_COMPLEX, null);
- cpp_long_long_int = new CPPBasicType(IBasicType.t_int, GPPBasicType.IS_LONGLONG);
+ cpp_long_double_complex = new GPPBasicType(IBasicType.t_double, ICPPBasicType.IS_LONG | ICPPBasicType.IS_COMPLEX, null);
+ cpp_long_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG_LONG);
cpp_signed_long_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_LONG | ICPPBasicType.IS_SIGNED);
cpp_unsigned_int = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED);
cpp_unsigned_long = new CPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG);
- cpp_unsigned_long_long = new GPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | GPPBasicType.IS_LONGLONG, null);
+ cpp_unsigned_long_long = new GPPBasicType(IBasicType.t_int, ICPPBasicType.IS_UNSIGNED | ICPPBasicType.IS_LONG_LONG, null);
cpp_size_t = cpp_unsigned_long; // assumed unsigned long int
cpp_va_list = new CPPFunctionType( cpp_char_p, new IType[0]); // assumed: char * va_list();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IRequiresLocationInformation.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IRequiresLocationInformation.java
deleted file mode 100644
index ca589da2584..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/IRequiresLocationInformation.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.dom.parser;
-
-import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
-
-/**
- * @author jcamelon
- */
-public interface IRequiresLocationInformation {
-
- /**
- * @param locationResolver
- */
- void setLocationResolver(ILocationResolver resolver);
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java
index 6cbf1ad301e..f2246e2a846 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTAmbiguity.java
@@ -81,7 +81,7 @@ public abstract class CASTAmbiguity extends CASTNode {
}
}
}
- catch( Throwable t )
+ catch( Exception t )
{
++issues[i];
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java
index 50048a29b3e..690c45a9ed2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTDeclarator.java
@@ -1,14 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Yuan Zhang / Beth Tibbitts (IBM Research)
+ * IBM Rational Software - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Yuan Zhang / Beth Tibbitts (IBM Research)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c;
@@ -98,7 +98,7 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator {
this.name = name;
if (name != null) {
name.setParent(this);
- name.setPropertyInParent(DECLARATOR_NAME);;
+ name.setPropertyInParent(DECLARATOR_NAME);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
index d10a23317e9..27ec23fa710 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTTranslationUnit.java
@@ -47,45 +47,29 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.cdt.internal.core.dom.parser.ASTComment;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
-import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
-import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
-import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
-import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
+import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
import org.eclipse.core.runtime.CoreException;
/**
* @author jcamelon
*/
-public class CASTTranslationUnit extends CASTNode implements
- IASTTranslationUnit, IRequiresLocationInformation {
-
- private IASTDeclaration[] decls = null;
- private int declsPos=-1;
-
- // Binding
- private CScope compilationUnit = null;
-
- private ILocationResolver resolver;
-
- private IIndex index;
+public class CASTTranslationUnit extends CASTNode implements IASTTranslationUnit {
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
-
private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
-
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
-
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
-
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
-
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
-
- private IASTComment[] comments = new ASTComment[0];
+
+ private IASTDeclaration[] decls = null;
+ private int declsPos=-1;
+
+ private CScope compilationUnit = null;
+ private ILocationResolver resolver;
+ private IIndex index;
private boolean fIsHeader;
public IASTTranslationUnit getTranslationUnit() {
@@ -395,47 +379,21 @@ public class CASTTranslationUnit extends CASTNode implements
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getNodeForLocation(org.eclipse.cdt.core.dom.ast.IASTNodeLocation)
*/
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
- if (resolver instanceof org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) {
- org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver r2= (org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) resolver;
- IASTNode result= null;
- int start= r2.getSequenceNumberForFileOffset(path, realOffset);
+ IASTNode result= null;
+ if (resolver != null) {
+ int start= resolver.getSequenceNumberForFileOffset(path, realOffset);
if (start >= 0) {
int length= realLength < 1 ? 0 :
- r2.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
- result= r2.findSurroundingPreprocessorNode(start, length);
+ resolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
+ result= resolver.findSurroundingPreprocessorNode(start, length);
if (result == null) {
CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(start, length);
accept(nodeFinder);
result = nodeFinder.getNode();
}
}
- return result;
- }
-
- // mstodo- old location resolver remove
- IASTNode node = null;
- ASTPreprocessorSelectionResult result = null;
- int globalOffset = 0;
-
- try {
- result = resolver.getPreprocessorNode(path, realOffset, realLength);
- } catch (InvalidPreprocessorNodeException ipne) {
- globalOffset = ipne.getGlobalOffset();
- }
-
- if (result != null && result.getSelectedNode() != null) {
- node = result.getSelectedNode();
- } else {
- // use the globalOffset to get the node from the AST if it's valid
- globalOffset = result == null ? globalOffset : result.getGlobalOffset();
- if (globalOffset >= 0) {
- CFindNodeForOffsetAction nodeFinder = new CFindNodeForOffsetAction(globalOffset, realLength);
- accept(nodeFinder);
- node = nodeFinder.getNode();
- }
}
-
- return node;
+ return result;
}
/*
@@ -520,17 +478,6 @@ public class CASTTranslationUnit extends CASTNode implements
/*
* (non-Javadoc)
*
- * @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getUnpreprocessedSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
- */
- public String getUnpreprocessedSignature(IASTNodeLocation[] locations) {
- if (resolver == null)
- return EMPTY_STRING;
- return new String(resolver.getUnpreprocessedSignature(locations));
- }
-
- /*
- * (non-Javadoc)
- *
* @see org.eclipse.cdt.core.dom.ast.IASTTranslationUnit#getFilePath()
*/
public String getFilePath() {
@@ -567,12 +514,6 @@ public class CASTTranslationUnit extends CASTNode implements
return resolver.flattenLocations( nodeLocations );
}
- public IASTName[] getMacroExpansions() {
- if( resolver == null )
- return EMPTY_NAME_ARRAY;
- return resolver.getMacroExpansions();
- }
-
public IDependencyTree getDependencyTree() {
if( resolver == null )
return null;
@@ -582,7 +523,7 @@ public class CASTTranslationUnit extends CASTNode implements
public String getContainingFilename(int offset) {
if( resolver == null )
return EMPTY_STRING;
- return resolver.getContainingFilename( offset );
+ return resolver.getContainingFilePath( offset );
}
public ParserLanguage getParserLanguage() {
@@ -599,18 +540,12 @@ public class CASTTranslationUnit extends CASTNode implements
}
public IASTComment[] getComments() {
- if (resolver instanceof org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) {
- org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver r2= (org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) resolver;
- return r2.getComments();
+ if (resolver != null) {
+ return resolver.getComments();
}
- // support for old location resolver
- return comments;
+ return new IASTComment[0];
}
- public void setComments(IASTComment[] comments) {
- this.comments = comments;
- }
-
public Object getAdapter(Class adapter) {
if (adapter.isAssignableFrom(resolver.getClass())) {
return resolver;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
index cb2ef0e6d33..b767e3aa6de 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/GNUCSourceParser.java
@@ -26,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
-import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
@@ -103,11 +102,9 @@ import org.eclipse.cdt.core.parser.IGCCToken;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken;
-import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.internal.core.dom.parser.ASTComment;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
@@ -606,18 +603,8 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
} catch (EndOfFileException e3) {
// nothing
}
- } catch (ParseError perr) {
- throw perr;
- } catch (Throwable e) {
- logThrowable("translationUnit", e); //$NON-NLS-1$
- try {
- failParseWithErrorHandling();
- } catch (EndOfFileException e3) {
- // break;
- }
}
}
- translationUnit.setComments((IASTComment[]) ArrayUtil.trim(IASTComment.class, comments));
}
/**
@@ -633,6 +620,12 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
*/
protected IASTExpression assignmentExpression() throws EndOfFileException,
BacktrackException {
+ if (LT(1) == IToken.tLPAREN && LT(2) == IToken.tLBRACE && supportStatementsInExpressions) {
+ IASTExpression resultExpression = compoundStatementExpression();
+ if (resultExpression != null)
+ return resultExpression;
+ }
+
IASTExpression conditionalExpression = conditionalExpression();
// if the condition not taken, try assignment operators
if (conditionalExpression != null
@@ -2672,11 +2665,4 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
}
return for_statement;
}
-
- protected IASTComment createComment(IToken commentToken) throws EndOfFileException {
- ASTComment comment = new ASTComment(commentToken);
- comment.setParent(translationUnit);
- return comment;
- }
-
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
index c544c14daea..0f639bc2c3b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTAmbiguity.java
@@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
//no change for leave()
@@ -68,7 +69,7 @@ public abstract class CPPASTAmbiguity extends CPPASTNode {
IBinding b = names[j].resolveBinding();
if (b == null || b instanceof IProblemBinding)
++issues[i];
- } catch (Throwable t) {
+ } catch (Exception t) {
++issues[i];
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java
index 52ba214ac87..22c9bc474c1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTCastExpression.java
@@ -6,11 +6,12 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
+ * IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCastExpression;
@@ -48,7 +49,7 @@ public class CPPASTCastExpression extends CPPASTUnaryExpression implements ICPPA
// ICPPASTCastExpression.OPERAND
if (expression != null) {
expression.setParent(this);
- expression.setPropertyInParent(ICPPASTCastExpression.OPERAND);
+ expression.setPropertyInParent(IASTCastExpression.OPERAND);
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java
index 43c353e7d69..e3e59f98112 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTName.java
@@ -6,10 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Bryan Wilkinson (QNX)
- * Anton Leherbauer (Wind River Systems)
+ * IBM - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Bryan Wilkinson (QNX)
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp;
@@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
@@ -99,8 +100,8 @@ public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionCo
ICPPASTElaboratedTypeSpecifier specifier = (ICPPASTElaboratedTypeSpecifier) parent;
int kind = specifier.getKind();
switch (kind) {
- case ICPPASTElaboratedTypeSpecifier.k_struct:
- case ICPPASTElaboratedTypeSpecifier.k_union:
+ case ICompositeType.k_struct:
+ case ICompositeType.k_union:
case ICPPASTElaboratedTypeSpecifier.k_class:
break;
default:
@@ -129,13 +130,13 @@ public class CPPASTName extends CPPASTNode implements IASTName, IASTCompletionCo
ICPPClassType type = (ICPPClassType) bindings[i];
try {
switch (type.getKey()) {
- case ICPPClassType.k_struct:
- if (kind != ICPPASTElaboratedTypeSpecifier.k_struct) {
+ case ICompositeType.k_struct:
+ if (kind != ICompositeType.k_struct) {
bindings[i] = null;
}
break;
- case ICPPClassType.k_union:
- if (kind != ICPPASTElaboratedTypeSpecifier.k_union) {
+ case ICompositeType.k_union:
+ if (kind != ICompositeType.k_union) {
bindings[i] = null;
}
break;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
index 3d0f0d656af..a7d875def6e 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTTranslationUnit.java
@@ -58,46 +58,31 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPScope;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.internal.core.dom.parser.ASTComment;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
-import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
-import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
-import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
-import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
+import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
import org.eclipse.core.runtime.CoreException;
/**
* @author jcamelon
*/
-public class CPPASTTranslationUnit extends CPPASTNode implements
- ICPPASTTranslationUnit, IRequiresLocationInformation, IASTAmbiguityParent {
- private IASTDeclaration[] decls = new IASTDeclaration[32];
-
- private ICPPNamespace binding = null;
-
- private ICPPScope scope = null;
-
- private ILocationResolver resolver;
-
- private IIndex index;
-
+public class CPPASTTranslationUnit extends CPPASTNode implements ICPPASTTranslationUnit, IASTAmbiguityParent {
+
private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_STATEMENT_ARRAY = new IASTPreprocessorStatement[0];
-
private static final IASTNodeLocation[] EMPTY_PREPROCESSOR_LOCATION_ARRAY = new IASTNodeLocation[0];
-
private static final IASTPreprocessorMacroDefinition[] EMPTY_PREPROCESSOR_MACRODEF_ARRAY = new IASTPreprocessorMacroDefinition[0];
-
private static final IASTPreprocessorIncludeStatement[] EMPTY_PREPROCESSOR_INCLUSION_ARRAY = new IASTPreprocessorIncludeStatement[0];
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final IASTProblem[] EMPTY_PROBLEM_ARRAY = new IASTProblem[0];
-
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
- private IASTComment[] comments = new ASTComment[0];
-
+ private IASTDeclaration[] decls = new IASTDeclaration[32];
+ private ICPPNamespace binding = null;
+ private ICPPScope scope = null;
+ private ILocationResolver resolver;
+ private IIndex index;
private boolean fIsHeader;
public IASTTranslationUnit getTranslationUnit() {
@@ -381,47 +366,21 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
public IASTNode selectNodeForLocation(String path, int realOffset, int realLength) {
- if (resolver instanceof org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) {
- org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver r2= (org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) resolver;
- IASTNode result= null;
- int start= r2.getSequenceNumberForFileOffset(path, realOffset);
+ IASTNode result= null;
+ if (resolver != null) {
+ int start= resolver.getSequenceNumberForFileOffset(path, realOffset);
if (start >= 0) {
int length= realLength < 1 ? 0 :
- r2.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
- result= r2.findSurroundingPreprocessorNode(start, length);
+ resolver.getSequenceNumberForFileOffset(path, realOffset+realLength-1) + 1 - start;
+ result= resolver.findSurroundingPreprocessorNode(start, length);
if (result == null) {
CPPFindNodeForOffsetAction nodeFinder = new CPPFindNodeForOffsetAction(start, length);
accept(nodeFinder);
result = nodeFinder.getNode();
}
}
- return result;
- }
-
- // mstodo- old location resolver, remove
- IASTNode node = null;
- ASTPreprocessorSelectionResult result = null;
- int globalOffset = 0;
-
- try {
- result = resolver.getPreprocessorNode(path, realOffset, realLength);
- } catch (InvalidPreprocessorNodeException ipne) {
- globalOffset = ipne.getGlobalOffset();
- }
-
- if (result != null && result.getSelectedNode() != null) {
- node = result.getSelectedNode();
- } else {
- // use the globalOffset to get the node from the AST if it's valid
- globalOffset = result == null ? globalOffset : result.getGlobalOffset();
- if (globalOffset >= 0) {
- CPPFindNodeForOffsetAction nodeFinder = new CPPFindNodeForOffsetAction(globalOffset, realLength);
- accept(nodeFinder);
- node = nodeFinder.getNode();
- }
}
-
- return node;
+ return result;
}
@@ -473,12 +432,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
return result;
}
- public String getUnpreprocessedSignature(IASTNodeLocation[] locations) {
- if( resolver == null ) return EMPTY_STRING;
- return new String( resolver.getUnpreprocessedSignature(locations) );
- }
-
-
public String getFilePath() {
if (resolver == null)
return EMPTY_STRING;
@@ -514,12 +467,6 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
return resolver.flattenLocations( nodeLocations );
}
- public IASTName[] getMacroExpansions() {
- if( resolver == null )
- return EMPTY_NAME_ARRAY;
- return resolver.getMacroExpansions();
- }
-
public IDependencyTree getDependencyTree() {
if( resolver == null )
return null;
@@ -529,7 +476,7 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
public String getContainingFilename(int offset) {
if( resolver == null )
return EMPTY_STRING;
- return resolver.getContainingFilename( offset );
+ return resolver.getContainingFilePath( offset );
}
public void replace(IASTNode child, IASTNode other) {
@@ -559,16 +506,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
}
public IASTComment[] getComments() {
- if (resolver instanceof org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) {
- org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver r2= (org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver) resolver;
- return r2.getComments();
+ if (resolver != null) {
+ return resolver.getComments();
}
- // support for old location resolver
- return comments;
- }
-
- public void setComments(IASTComment[] comments) {
- this.comments = comments;
+ return new IASTComment[0];
}
public Object getAdapter(Class adapter) {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java
index 742bad31fe2..9c0d303d7c1 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPClassTemplateSpecialization.java
@@ -95,7 +95,7 @@ public class CPPClassTemplateSpecialization extends CPPClassSpecialization
ICPPTemplateDefinition template = null;
try {
- template = CPPTemplates.matchTemplatePartialSpecialization( (ICPPClassTemplate) this, arguments );
+ template = CPPTemplates.matchTemplatePartialSpecialization( this, arguments );
} catch (DOMException e) {
return e.getProblem();
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
index b284b19729e..bffe1572cea 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPVisitor.java
@@ -1645,7 +1645,7 @@ public class CPPVisitor {
if( gspec.getTypeofExpression() != null ){
type = getExpressionType( gspec.getTypeofExpression() );
} else {
- bits |= ( gspec.isLongLong() ? GPPBasicType.IS_LONGLONG : 0 );
+ bits |= ( gspec.isLongLong() ? ICPPBasicType.IS_LONG_LONG : 0 );
type = new GPPBasicType( spec.getType(), bits, getExpressionType(gspec.getTypeofExpression()) );
}
} else {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 90329f1253e..047110410fd 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -27,7 +27,6 @@ import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
-import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
@@ -138,10 +137,8 @@ import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.ITokenDuple;
-import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.internal.core.dom.parser.ASTComment;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
@@ -4340,18 +4337,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} catch (EndOfFileException e3) {
// nothing
}
- } catch (ParseError perr) {
- throw perr;
- } catch (Throwable e) {
- logThrowable("translationUnit", e); //$NON-NLS-1$
- try {
- failParseWithErrorHandling();
- } catch (EndOfFileException e3) {
- // break;
- }
}
}
- translationUnit.setComments((IASTComment[]) ArrayUtil.trim(IASTComment.class, comments));
}
@@ -4977,10 +4964,4 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
}
return for_statement;
}
-
- protected IASTComment createComment(IToken commentToken) throws EndOfFileException {
- ASTComment comment = new ASTComment(commentToken);
- comment.setParent(translationUnit);
- return comment;
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPBasicType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPBasicType.java
index 3eb070953ec..227024f0836 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPBasicType.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GPPBasicType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
/*
* Created on Dec 10, 2004
@@ -22,10 +23,6 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType;
* @author aniefer
*/
public class GPPBasicType extends CPPBasicType implements IGPPBasicType {
- public static final int IS_LONGLONG = LAST << 1;
- public static final int IS_COMPLEX = LAST << 2;
- public static final int IS_IMAGINARY = LAST << 3;
-
private IType typeOf;
public GPPBasicType( int type, int bits, IType typeOf ){
@@ -34,7 +31,7 @@ public class GPPBasicType extends CPPBasicType implements IGPPBasicType {
if( type == IBasicType.t_unspecified ){
if((qualifierBits & ( IS_COMPLEX | IS_IMAGINARY )) != 0 )
type = IBasicType.t_float;
- else if( (qualifierBits & IS_LONGLONG) != 0 )
+ else if( (qualifierBits & IS_LONG_LONG) != 0 )
type = IBasicType.t_int;
}
}
@@ -43,7 +40,7 @@ public class GPPBasicType extends CPPBasicType implements IGPPBasicType {
* @see org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPBasicType#isLongLong()
*/
public boolean isLongLong() {
- return ( qualifierBits & IS_LONGLONG ) != 0;
+ return ( qualifierBits & IS_LONG_LONG ) != 0;
}
/* (non-Javadoc)
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java
index f7b36b2a841..f68e7b96821 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/IndexBasedCodeReaderFactory.java
@@ -30,12 +30,10 @@ import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.ICodeReaderCache;
-import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.ParserUtil;
-import org.eclipse.cdt.internal.core.parser.scanner2.IIndexBasedCodeReaderFactory;
+import org.eclipse.cdt.internal.core.parser.scanner.IIndexBasedCodeReaderFactory;
import org.eclipse.cdt.internal.core.pdom.ASTFilePathResolver;
import org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask;
-import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
import org.eclipse.core.runtime.CoreException;
/**
@@ -100,9 +98,9 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
for (Iterator iterator = macroMap.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
IIndexFileLocation includedIFL = (IIndexFileLocation) entry.getKey();
- IMacro[] macros = (IMacro[]) entry.getValue();
+ IIndexMacro[] macros = (IIndexMacro[]) entry.getValue();
for (int i = 0; i < macros.length; ++i) {
- scanner.addDefinition(macros[i]);
+ scanner.addMacroDefinition(macros[i]);
}
fIncludedFiles.add(includedIFL);
}
@@ -132,7 +130,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
if (macroMap.containsKey(ifl) || (checkIncluded && fIncludedFiles.contains(ifl))) {
return;
}
- IMacro[] converted;
+ IIndexMacro[] converted;
if (fRelatedIndexerTask != null) {
converted= fRelatedIndexerTask.getConvertedMacros(fLinkage, ifl);
if (converted == null) {
@@ -140,12 +138,7 @@ public final class IndexBasedCodeReaderFactory implements IIndexBasedCodeReaderF
}
}
else {
- IIndexMacro[] macros= file.getMacros();
- converted= new IMacro[macros.length];
- for (int i = 0; i < macros.length; i++) {
- IIndexMacro macro = macros[i];
- converted[i]= ((PDOMMacro)macro).getMacro();
- }
+ converted= file.getMacros();
}
macroMap.put(ifl, converted); // prevent recursion
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeTypeContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeTypeContainer.java
index 55543c13839..fc0ed1631d8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeTypeContainer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/CompositeTypeContainer.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite;
@@ -31,7 +31,7 @@ public class CompositeTypeContainer extends CompositeType implements ITypeContai
try {
return ASTTypeUtil.getType(getType());
} catch (DOMException e) {
- return "";
+ return ""; //$NON-NLS-1$
}
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java
index 41b90029d5f..e5870cbbf24 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/CompositeCPPFunctionSpecialization.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
+ * Andrew Ferguson (Symbian) - Initial implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@@ -22,7 +22,7 @@ public class CompositeCPPFunctionSpecialization extends CompositeCPPFunction
implements ICPPFunction, ICPPSpecialization {
public CompositeCPPFunctionSpecialization(ICompositesFactory cf, ICPPFunction ft) {
- super(cf, (ICPPFunction) ft);
+ super(cf, ft);
}
public String toString() {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java
index 61e1d3b9051..c1de137928a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/composite/cpp/InternalTemplateInstantiatorUtil.java
@@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Andrew Ferguson (Symbian) - Initial implementation
- * Bryan Wilkinson (QNX)
+ * Andrew Ferguson (Symbian) - Initial implementation
+ * Bryan Wilkinson (QNX)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@@ -57,7 +57,7 @@ public class InternalTemplateInstantiatorUtil {
public static IBinding instantiate(IType[] arguments, ICompositesFactory cf, IIndexBinding rbinding) {
IBinding ins= ((ICPPInternalTemplateInstantiator)rbinding).instantiate(arguments);
if (ins instanceof IIndexFragmentBinding) {
- return (IBinding) cf.getCompositeBinding((IIndexFragmentBinding)ins);
+ return cf.getCompositeBinding((IIndexFragmentBinding)ins);
} else {
// can result in a non-index binding
return ins;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java
index b3f3abdedb7..4c2afd1b275 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ASTPreprocessorName.java
@@ -137,7 +137,8 @@ class ASTMacroReferenceName extends ASTPreprocessorName {
return fImageLocationInfo.createLocation(lr, fImageLocationInfo);
}
}
+ return null;
}
- return null;
+ return super.getImageLocation();
}
}
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 027b02ece9b..cf3783238d4 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
@@ -45,8 +45,6 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.parser.scanner.ExpressionEvaluator.EvalException;
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser.InvalidMacroDefinitionException;
-import org.eclipse.cdt.internal.core.parser.scanner2.IIndexBasedCodeReaderFactory;
-import org.eclipse.cdt.internal.core.parser.scanner2.ScannerUtility;
/**
* C-Preprocessor providing tokens for the parsers. The class should not be used directly, rather than that
@@ -181,7 +179,6 @@ public class CPreprocessor implements ILexerLog, IScanner {
/** Set of already included files */
private final HashSet fAllIncludedFiles= new HashSet();
- private int fTokenCount;
private final Lexer fRootLexer;
private final ScannerContext fRootContext;
@@ -287,10 +284,10 @@ public class CPreprocessor implements ILexerLog, IScanner {
fMacroDictionary.put(__STDC_VERSION__.getNameCharArray(), __STDC_VERSION__);
}
- CharArrayObjectMap toAdd = config.getAdditionalMacros();
- for (int i = 0; i < toAdd.size(); ++i) {
- addDefinition((IMacro) toAdd.getAt(i));
- }
+ IMacro[] toAdd = config.getAdditionalMacros();
+ for (int i = 0; i < toAdd.length; i++) {
+ addDefinition(toAdd[i]);
+ }
// macros provided on command-line (-D)
final boolean initEmptyMacros= config.initializeMacroValuesTo1();
@@ -376,10 +373,6 @@ public class CPreprocessor implements ILexerLog, IScanner {
}
}
- public int getCount() {
- return fTokenCount;
- }
-
public Map getDefinitions() {
final CharArrayObjectMap objMap= fMacroDictionary;
int size = objMap.size();
@@ -391,15 +384,11 @@ public class CPreprocessor implements ILexerLog, IScanner {
return hashMap;
}
- public String[] getIncludePaths() {
- return fIncludePaths;
- }
-
public boolean isOnTopContext() {
return fCurrentContext == fRootContext;
}
- public synchronized void cancel() {
+ public void cancel() {
isCancelled= true;
}
@@ -549,7 +538,6 @@ public class CPreprocessor implements ILexerLog, IScanner {
Token internalFetchToken(final boolean expandMacros, final boolean stopAtNewline,
final boolean checkNumbers, final ScannerContext uptoEndOfCtx) throws OffsetLimitReachedException {
- ++fTokenCount;
Token ppToken= fCurrentContext.currentLexerToken();
while(true) {
switch(ppToken.getType()) {
@@ -814,13 +802,13 @@ public class CPreprocessor implements ILexerLog, IScanner {
public void addMacroDefinition(IIndexMacro macro) {
try {
- PreprocessorMacro result= fMacroDefinitionParser.parseMacroDefinition(macro.getName(), macro.getParameterList(), macro.getExpansion());
+ PreprocessorMacro result= fMacroDefinitionParser.parseMacroDefinition(macro.getNameCharArray(), macro.getParameterList(), macro.getExpansionImage());
final IASTFileLocation loc= macro.getFileLocation();
fLocationMap.registerMacroFromIndex(result, loc, -1);
fMacroDictionary.put(result.getNameCharArray(), result);
}
catch (Exception e) {
- fLog.traceLog("Invalid macro definition: '" + String.valueOf(macro.getName()) + "'"); //$NON-NLS-1$//$NON-NLS-2$
+ fLog.traceLog("Invalid macro definition: '" + macro.getName() + "'"); //$NON-NLS-1$//$NON-NLS-2$
}
}
@@ -1404,15 +1392,9 @@ public class CPreprocessor implements ILexerLog, IScanner {
addMacroDefinition(macro.getSignature(), macro.getExpansion());
}
}
- public IMacro addDefinition(char[] key, char[] value) {
- throw new UnsupportedOperationException();
- }
public void setScanComments(boolean val) {
}
- public IMacro addDefinition(char[] name, char[][] params, char[] expansion) {
- throw new UnsupportedOperationException();
- }
- public org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver getLocationResolver() {
+ public ILocationResolver getLocationResolver() {
return fLocationMap;
}
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IIndexBasedCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IIndexBasedCodeReaderFactory.java
index cb122357ccc..33494940bdf 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IIndexBasedCodeReaderFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/IIndexBasedCodeReaderFactory.java
@@ -8,7 +8,7 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
+package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java
index b0b5e5f9971..a335791b57a 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ILocationResolver.java
@@ -30,7 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
* Interface between the ast and the location-resolver for resolving offsets.
* @since 5.0
*/
-public interface ILocationResolver extends org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver {
+public interface ILocationResolver {
/**
* Introduces the ast translation unit to the location resolver. Must be called before any tokens from the
@@ -75,9 +75,8 @@ public interface ILocationResolver extends org.eclipse.cdt.internal.core.parser.
/**
* @see IASTTranslationUnit#getContainingFilename()
- * mstodo- old location resolver, should be renamed
*/
- String getContainingFilename(int sequenceNumber);
+ String getContainingFilePath(int sequenceNumber);
/**
* @see IASTTranslationUnit#getDependencyTree()
@@ -140,4 +139,9 @@ public interface ILocationResolver extends org.eclipse.cdt.internal.core.parser.
* @param offset
*/
boolean isPartOfTranslationUnitFile(int sequenceNumber);
+
+ /**
+ * Same as {@link #getMappedFileLocation(int, int)} for the given array of consecutive node locations.
+ */
+ IASTFileLocation flattenLocations(IASTNodeLocation[] nodeLocations);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
index 1372153d326..8108e59b679 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/LocationMap.java
@@ -345,7 +345,7 @@ public class LocationMap implements ILocationResolver {
return fCurrentContext.getSequenceNumberForOffset(offset, offset < fLastChildInsertionOffset);
}
- public String getContainingFilename(int sequenceNumber) {
+ public String getContainingFilePath(int sequenceNumber) {
LocationCtx ctx= fRootContext.findSurroundingContext(sequenceNumber, 1);
return new String(ctx.getFilePath());
}
@@ -554,13 +554,4 @@ public class LocationMap implements ILocationResolver {
public ASTPreprocessorSelectionResult getPreprocessorNode(String path, int offset, int length) {
throw new UnsupportedOperationException();
}
-
- // mstodo- old location resolver
- public char[] getUnpreprocessedSignature(IASTNodeLocation[] locations) {
- throw new UnsupportedOperationException();
- }
- // mstodo- old location resolver
- public IASTName[] getMacroExpansions() {
- throw new UnsupportedOperationException();
- }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java
index 793462f989c..4d3e840eed5 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java
@@ -17,12 +17,13 @@ import org.eclipse.cdt.core.parser.IToken;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
/**
* Utility to parse macro definitions and create the macro objects for the preprocessor.
* @since 5.0
*/
-class MacroDefinitionParser {
+public class MacroDefinitionParser {
private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
/**
@@ -58,12 +59,42 @@ class MacroDefinitionParser {
return "[" + fIndex + "]"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
+ public static char[] getExpansion(char[] expansionImage, int offset, int endOffset) {
+ TokenList tl= new TokenList();
+ Lexer lex= new Lexer(expansionImage, offset, endOffset, new LexerOptions(), ILexerLog.NULL, null);
+ try {
+ new MacroDefinitionParser().parseExpansion(lex, ILexerLog.NULL, null, new char[][]{}, tl);
+ } catch (OffsetLimitReachedException e) {
+ }
+
+ StringBuffer buf= new StringBuffer();
+ Token t= tl.first();
+ if (t == null) {
+ return CharArrayUtils.EMPTY;
+ }
+ endOffset= t.getOffset();
+ for (; t != null; t= (Token) t.getNext()) {
+ if (endOffset < t.getOffset()) {
+ buf.append(' ');
+ }
+ buf.append(t.getCharImage());
+ endOffset= t.getEndOffset();
+ }
+ final int length= buf.length();
+ final char[] expansion= new char[length];
+ buf.getChars(0, length, expansion, 0);
+ return expansion;
+ }
private int fHasVarArgs;
private int fExpansionOffset;
private int fExpansionEndOffset;
private Token fNameToken;
+ MacroDefinitionParser() {
+ }
+
/**
* In case the name was successfully parsed, the name token is returned.
* Otherwise the return value is undefined.
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java
index 1cac776b61a..b3d21189337 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/PreprocessorMacro.java
@@ -15,7 +15,6 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
@@ -145,24 +144,7 @@ class ObjectStyleMacro extends PreprocessorMacro {
}
public char[] getExpansion() {
- TokenList tl= getTokens(new MacroDefinitionParser(), new LexerOptions());
- StringBuffer buf= new StringBuffer();
- Token t= tl.first();
- if (t == null) {
- return CharArrayUtils.EMPTY;
- }
- int endOffset= t.getOffset();
- for (; t != null; t= (Token) t.getNext()) {
- if (endOffset < t.getOffset()) {
- buf.append(' ');
- }
- buf.append(t.getCharImage());
- endOffset= t.getEndOffset();
- }
- final int length= buf.length();
- final char[] expansion= new char[length];
- buf.getChars(0, length, expansion, 0);
- return expansion;
+ return MacroDefinitionParser.getExpansion(fExpansion, fExpansionOffset, fEndOffset);
}
public char[] getExpansionImage() {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerProblemFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java
index 0a5a1080c7f..e4dd39f1e4b 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerProblemFactory.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerProblemFactory.java
@@ -6,10 +6,10 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
+ * IBM Rational Software - Initial API and implementation
+ * Anton Leherbauer (Wind River Systems)
*******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
+package org.eclipse.cdt.internal.core.parser.scanner;
import org.eclipse.cdt.core.parser.IProblem;
import org.eclipse.cdt.internal.core.parser.problem.BaseProblemFactory;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java
index 474a721a706..6396b7ee0b2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerUtility.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/ScannerUtility.java
@@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * IBM Rational Software - Initial API and implementation
+ * IBM Rational Software - Initial API and implementation
*******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
+package org.eclipse.cdt.internal.core.parser.scanner;
import java.io.File;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java
deleted file mode 100644
index 017f8257951..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/BaseScanner.java
+++ /dev/null
@@ -1,4267 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial implementation
- * Markus Schorn (Wind River Systems)
- * Bryan Wilkinson (QNX) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=151207
- * Anton Leherbauer (Wind River Systems)
- * Emanuel Graf (IFS)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
-import org.eclipse.cdt.core.parser.CodeReader;
-import org.eclipse.cdt.core.parser.EndOfFileException;
-import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
-import org.eclipse.cdt.core.parser.IGCCToken;
-import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.core.parser.IParserLogService;
-import org.eclipse.cdt.core.parser.IPreprocessorDirective;
-import org.eclipse.cdt.core.parser.IProblem;
-import org.eclipse.cdt.core.parser.IScanner;
-import org.eclipse.cdt.core.parser.IScannerInfo;
-import org.eclipse.cdt.core.parser.IToken;
-import org.eclipse.cdt.core.parser.Keywords;
-import org.eclipse.cdt.core.parser.OffsetLimitReachedException;
-import org.eclipse.cdt.core.parser.ParseError;
-import org.eclipse.cdt.core.parser.ParserLanguage;
-import org.eclipse.cdt.core.parser.ParserMode;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.core.parser.util.CharArraySet;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.core.parser.util.CharTable;
-import org.eclipse.cdt.internal.core.parser.token.SimpleToken;
-
-/**
- * @author Doug Schaefer
- *
- */
-abstract class BaseScanner implements IScanner {
- static boolean cacheIdentifiers = true;
-
- protected static final char[] ONE = "1".toCharArray(); //$NON-NLS-1$
-
- protected static final char[] ELLIPSIS_CHARARRAY = "...".toCharArray(); //$NON-NLS-1$
-
- protected static final char[] VA_ARGS_CHARARRAY = "__VA_ARGS__".toCharArray(); //$NON-NLS-1$
-
- protected final IToken eocToken = new SimpleToken(IToken.tEOC, Integer.MAX_VALUE, null, Integer.MAX_VALUE);
-
- /**
- * @author jcamelon
- *
- */
- protected static class InclusionData {
-
- public final Object inclusion;
- public final CodeReader reader;
- public final boolean includeOnce;
-
- /**
- * @param reader
- * @param inclusion
- * @param includeOnce
- */
- public InclusionData(CodeReader reader, Object inclusion, boolean includeOnce) {
- this.reader = reader;
- this.inclusion = inclusion;
- this.includeOnce= includeOnce;
- }
-
- public String toString() {
- return reader.toString();
- }
- }
-
- protected static class MacroData {
- public MacroData(int start, int end, IMacro macro) {
- this.startOffset = start;
- this.endOffset = end;
- this.macro = macro;
- }
-
- private final int startOffset;
- private final int endOffset;
-
- public final IMacro macro;
-
- public String toString() {
- return macro.toString();
- }
-
- public int getStartOffset() {
- return startOffset;
- }
- public int getLength() {
- return endOffset-startOffset;
- }
- }
-
- protected static class FunctionMacroData extends MacroData{
- private CharArrayObjectMap arguments;
- public FunctionMacroData(int start, int end, IMacro macro, CharArrayObjectMap argmap) {
- super(start,end, macro);
- arguments = argmap;
- }
-
- public CharArrayObjectMap getActualArgs() {
- return arguments;
- }
- }
-
- protected interface IIncludeFileTester {
- Object checkFile(String path, String fileName);
- }
-
- final private IIncludeFileTester createCodeReaderTester= new IIncludeFileTester() {
- public Object checkFile(String path, String fileName) {
- return createReader(path, fileName);
- }
- };
-
- protected ParserLanguage language;
-
- protected IParserLogService log;
-
- protected CharArrayObjectMap definitions = new CharArrayObjectMap(512);
-
- protected String[] includePaths;
- protected String[] quoteIncludePaths;
-
- /** Set of already included files */
- protected CharArraySet includedFiles= new CharArraySet(32);
-
- int count;
-
- protected ExpressionEvaluator expressionEvaluator;
-
- // The context stack
- protected static final int bufferInitialSize = 8;
-
- protected int bufferStackPos = -1;
-
- protected char[][] bufferStack = new char[bufferInitialSize][];
-
- protected Object[] bufferData = new Object[bufferInitialSize];
-
- protected int[] bufferPos = new int[bufferInitialSize];
-
- protected int[] bufferLimit = new int[bufferInitialSize];
-
- int[] lineNumbers = new int[bufferInitialSize];
-
- protected int[] lineOffsets = new int[bufferInitialSize];
-
- //branch tracking
- protected int branchStackPos = -1;
-
- protected int[] branches = new int[bufferInitialSize];
-
- //states
- final static protected int BRANCH_IF = 1;
-
- final static protected int BRANCH_ELIF = 2;
-
- final static protected int BRANCH_ELSE = 3;
-
- final static protected int BRANCH_END = 4;
-
- // Utility
- protected static String[] EMPTY_STRING_ARRAY = new String[0];
-
- protected static char[] EMPTY_CHAR_ARRAY = new char[0];
-
- protected static EndOfFileException EOF = new EndOfFileException();
-
- protected ParserMode parserMode;
-
- protected boolean isInitialized = false;
- protected boolean macroFilesInitialized = false;
-
- protected final char[] suffixes;
-
- protected final boolean support$Initializers;
-
- protected final boolean supportMinAndMax;
-
- protected boolean scanComments;
-
- protected IToken[] commentsFromInactiveCode = new IToken[0];
-
- protected final CharArrayIntMap additionalKeywords;
-
- protected final CharArrayIntMap additionalPPKeywords;
-
- public BaseScanner(CodeReader reader, IScannerInfo info,
- ParserMode parserMode, ParserLanguage language,
- IParserLogService log, IScannerExtensionConfiguration configuration) {
-
- this.parserMode = parserMode;
- this.language = language;
- this.log = log;
- this.scanComments = false;
-
- if (configuration.supportAdditionalNumericLiteralSuffixes() != null)
- suffixes = configuration.supportAdditionalNumericLiteralSuffixes();
- else
- suffixes = EMPTY_CHAR_ARRAY;
- support$Initializers = configuration.support$InIdentifiers();
- supportMinAndMax = configuration.supportMinAndMaxOperators();
-
- if (language == ParserLanguage.C)
- keywords = ckeywords;
- else
- keywords = cppkeywords;
-
- additionalKeywords = configuration.getAdditionalKeywords();
- additionalPPKeywords= configuration.getAdditionalPreprocessorKeywords();
-
- setupBuiltInMacros(configuration);
-
- if (info.getDefinedSymbols() != null) {
- Map symbols = info.getDefinedSymbols();
- String[] keys = (String[]) symbols.keySet().toArray(
- EMPTY_STRING_ARRAY);
- for (int i = 0; i < keys.length; ++i) {
- String symbolName = keys[i];
- Object value = symbols.get(symbolName);
-
- if (value instanceof String) {
- if (configuration.initializeMacroValuesTo1()
- && ((String) value).trim().equals(EMPTY_STRING))
- addDefinition(symbolName.toCharArray(), ONE);
- else
- addDefinition(symbolName.toCharArray(),
- ((String) value).toCharArray());
- }
- }
- }
- includePaths= quoteIncludePaths= info.getIncludePaths();
- }
-
- /**
- * @param reader
- * @param info
- */
- protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
- if (info instanceof IExtendedScannerInfo) {
- extendedScannerInfoSetup(reader, info);
- } else {
- macroFilesInitialized = true;
- pushContext(reader.buffer, reader);
- isInitialized = true;
- }
- }
-
- /**
- * @param reader
- * @param info
- */
- protected void extendedScannerInfoSetup(CodeReader reader, IScannerInfo info) {
- IExtendedScannerInfo einfo = (IExtendedScannerInfo) info;
- // setup separate include path for quote includes.
- String[] qip= einfo.getLocalIncludePath();
- if (qip != null && qip.length > 0) {
- quoteIncludePaths= new String[qip.length + includePaths.length];
- System.arraycopy(qip, 0, quoteIncludePaths, 0, qip.length);
- System.arraycopy(includePaths, 0, quoteIncludePaths, qip.length, includePaths.length);
- }
-
- //
- final String[] macroFiles = einfo.getMacroFiles();
- if (macroFiles != null) {
- for (int i = 0; i < macroFiles.length; ++i) {
- CodeReader r= findInclusion(macroFiles[i], true, false, null);
- if (r != null) {
- pushContext(r.buffer, r);
- while (true) {
- try {
- nextToken();
- } catch (EndOfFileException e) {
- finished = false;
- break;
- }
- }
- }
- }
- }
-
- macroFilesInitialized = true;
- pushContext(reader.buffer, reader);
-
- final String[] preIncludeFiles= einfo.getIncludeFiles();
- if (parserMode != ParserMode.QUICK_PARSE && preIncludeFiles != null) {
- for (int i = 0; i < preIncludeFiles.length; i++) {
- final String file = preIncludeFiles[i];
- CodeReader r= findInclusion(file, true, false, null);
- if (r != null) {
- int o = getCurrentOffset() + 1;
- int l = getLineNumber(o);
- Object incObj = createInclusionConstruct(file.toCharArray(), r.filename, false, o,
- l, o, o, l, o, l, true);
- InclusionData d = new InclusionData(r, incObj, false);
- pushContext(r.buffer, d);
- }
- }
- }
- isInitialized = true;
- }
-
- protected void pushContext(char[] buffer) {
- if (++bufferStackPos == bufferStack.length) {
- int size = bufferStack.length * 2;
-
- char[][] oldBufferStack = bufferStack;
- bufferStack = new char[size][];
- System.arraycopy(oldBufferStack, 0, bufferStack, 0,
- oldBufferStack.length);
-
- Object[] oldBufferData = bufferData;
- bufferData = new Object[size];
- System.arraycopy(oldBufferData, 0, bufferData, 0,
- oldBufferData.length);
-
- int[] oldBufferPos = bufferPos;
- bufferPos = new int[size];
- System
- .arraycopy(oldBufferPos, 0, bufferPos, 0,
- oldBufferPos.length);
-
- int[] oldBufferLimit = bufferLimit;
- bufferLimit = new int[size];
- System.arraycopy(oldBufferLimit, 0, bufferLimit, 0,
- oldBufferLimit.length);
-
- int[] oldLineNumbers = lineNumbers;
- lineNumbers = new int[size];
- System.arraycopy(oldLineNumbers, 0, lineNumbers, 0,
- oldLineNumbers.length);
-
- int[] oldLineOffsets = lineOffsets;
- lineOffsets = new int[size];
- System.arraycopy(oldLineOffsets, 0, lineOffsets, 0,
- oldLineOffsets.length);
-
- }
-
- bufferStack[bufferStackPos] = buffer;
- bufferPos[bufferStackPos] = -1;
- lineNumbers[bufferStackPos] = 1;
- lineOffsets[bufferStackPos] = 0;
- bufferLimit[bufferStackPos] = buffer.length;
- }
-
- protected void pushContext(char[] buffer, Object data) {
- if (data instanceof InclusionData) {
- InclusionData inclusionData= (InclusionData)data;
- if (isCircularInclusion( inclusionData ))
- return;
- if (inclusionData.includeOnce && isRepeatedInclusion(inclusionData))
- return;
- includedFiles.put(inclusionData.reader.filename);
- }
- pushContext(buffer);
- bufferData[bufferStackPos] = data;
-
- }
-
- protected boolean isCircularInclusion(InclusionData data) {
- for (int i = 0; i < bufferStackPos; ++i) {
- if (bufferData[i] instanceof CodeReader
- && CharArrayUtils.equals(
- ((CodeReader) bufferData[i]).filename,
- data.reader.filename)) {
- return true;
- } else if (bufferData[i] instanceof InclusionData
- && CharArrayUtils
- .equals(
- ((InclusionData) bufferData[i]).reader.filename,
- data.reader.filename)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Check if the given inclusion was already included before.
- *
- * @param inclusionData
- * @return
- */
- private boolean isRepeatedInclusion(InclusionData inclusionData) {
- return includedFiles.containsKey(inclusionData.reader.filename);
- }
-
-
- protected Object popContext() {
- //NOTE - do not set counters to 0 or -1 or something
- //Subclasses may require those values in their popContext()
- bufferStack[bufferStackPos] = null;
-
- Object result = bufferData[bufferStackPos];
- bufferData[bufferStackPos] = null;
- --bufferStackPos;
-
- return result;
- }
-
- public IMacro addDefinition(char[] key, char[] value) {
- int idx = CharArrayUtils.indexOf('(', key);
- if (idx == -1) {
- IMacro macro = new ObjectStyleMacro(key, value);
- definitions.put(key, macro);
- return macro;
- } else {
- pushContext(key);
- bufferPos[bufferStackPos] = idx;
- char[][] args = null;
- try {
- args = extractMacroParameters(0, EMPTY_STRING_CHAR_ARRAY, false);
- } finally {
- popContext();
- }
-
- if (args != null) {
- key = CharArrayUtils.extract(key, 0, idx);
- return addDefinition(key, args, value);
- } else
- return null;
- }
- }
-
- public IMacro addDefinition(char[] name, char[][] params, char[] expansion) {
- IMacro macro = new FunctionStyleMacro(name, expansion, params);
- definitions.put(name, macro);
- return macro;
- }
-
- public void addDefinition(IMacro macro) {
- definitions.put(macro.getName(), macro);
- }
-
- public int getCount() {
- return count;
- }
-
- public Map getDefinitions() {
- CharArrayObjectMap objMap = getRealDefinitions();
- int size = objMap.size();
- Map hashMap = new HashMap(size);
- for (int i = 0; i < size; i++) {
- hashMap.put(String.valueOf(objMap.keyAt(i)), objMap.getAt(i));
- }
-
- return hashMap;
- }
-
- public CharArrayObjectMap getRealDefinitions() {
- return definitions;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.parser.IScanner#getIncludePaths()
- */
- public String[] getIncludePaths() {
- return includePaths;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.parser.IScanner#isOnTopContext()
- */
- public boolean isOnTopContext() {
- for (int i = 1; i <= bufferStackPos; ++i)
- if (bufferData[i] instanceof InclusionData)
- return false;
- return true;
- }
-
- protected IToken lastToken;
-
- protected IToken nextToken;
-
- protected boolean finished = false;
-
- protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
- protected static final char[] EMPTY_STRING_CHAR_ARRAY = new char[0];
-
- protected boolean isCancelled = false;
-
- public synchronized void cancel() {
- isCancelled = true;
- int index = bufferStackPos < 0 ? 0 : bufferStackPos;
- bufferPos[index] = bufferLimit[index];
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.parser.IScanner#nextToken()
- */
- public IToken nextToken() throws EndOfFileException {
- if (nextToken == null && !finished) {
- nextToken= doFetchToken();
- if (nextToken == null) {
- finished = true;
- }
- }
-
- beforeSecondFetchToken();
-
- if (finished) {
- if (contentAssistMode) {
- if (lastToken != null)
- lastToken.setNext(nextToken);
- lastToken = nextToken;
- nextToken = eocToken;
- return lastToken;
- }
-
- if (isCancelled == true)
- throw new ParseError(
- ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
-
- if (offsetBoundary == -1)
- throwEOF();
- throwOLRE();
- }
-
- if (lastToken != null)
- lastToken.setNext(nextToken);
- IToken oldToken = lastToken;
- lastToken = nextToken;
-
- nextToken = doFetchToken();
-
- if (nextToken == null) {
- finished = true;
- } else if (nextToken.getType() == IToken.tCOMPLETION) {
- finished = true;
- } else if (nextToken.getType() == IToken.tPOUNDPOUND) {
- // time for a pasting
- IToken token2 = doFetchToken();
- if (token2 == null) {
- nextToken = null;
- finished = true;
- } else {
- char[] pb = CharArrayUtils.concat(lastToken.getCharImage(),
- token2.getCharImage());
- pushContext(pb);
- lastToken = oldToken;
- nextToken = null;
- return nextToken();
- }
- } else if (lastToken != null
- && (lastToken.getType() == IToken.tSTRING || lastToken
- .getType() == IToken.tLSTRING)) {
- while (nextToken != null
- && (nextToken.getType() == IToken.tSTRING || nextToken
- .getType() == IToken.tLSTRING)) {
- // Concatenate the adjacent strings
- int tokenType = IToken.tSTRING;
- if (lastToken.getType() == IToken.tLSTRING
- || nextToken.getType() == IToken.tLSTRING)
- tokenType = IToken.tLSTRING;
- lastToken = newToken(tokenType, CharArrayUtils.concat(lastToken
- .getCharImage(), nextToken.getCharImage()));
- if (oldToken != null)
- oldToken.setNext(lastToken);
- nextToken = doFetchToken();
- }
- }
-
- return lastToken;
- }
-
- private IToken doFetchToken() throws EndOfFileException {
- IToken result= null;
- try {
- result = fetchToken();
- } catch (OffsetLimitReachedException olre) {
- if (contentAssistMode) {
- String prefix= olre.getPrefix();
- if (prefix != null) {
- result= newToken(IToken.tCOMPLETION, prefix.toCharArray());
- } else {
- result= newToken(IToken.tCOMPLETION);
- }
- } else {
- throw olre;
- }
- } catch (ArrayIndexOutOfBoundsException e) {
- if (isCancelled) {
- throw new ParseError(ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
- }
- errorHandle();
- throw e;
- } catch (RuntimeException e) {
- errorHandle();
- throw e;
- } catch (Error e) {
- errorHandle();
- throw e;
- }
- return result;
- }
-
- /**
- * @throws EndOfFileException
- */
- protected void throwEOF() throws EndOfFileException {
- throw EOF;
- }
-
- /**
- *
- */
- protected void beforeSecondFetchToken() {
- }
-
- /**
- *
- */
- protected void errorHandle() {
- if( bufferStackPos > 0 )
- ++bufferPos[bufferStackPos];
- }
-
- /**
- *
- */
- protected void throwOLRE() throws OffsetLimitReachedException {
- if (lastToken != null && lastToken.getEndOffset() != offsetBoundary)
- throw new OffsetLimitReachedException((IToken) null);
- throw new OffsetLimitReachedException(lastToken);
- }
-
- // Return null to signify end of file
- protected IToken fetchToken() throws EndOfFileException {
- ++count;
- while (bufferStackPos >= 0) {
- if (isCancelled == true)
- throw new ParseError(
- ParseError.ParseErrorKind.TIMEOUT_OR_CANCELLED);
-
- //return the stored comments
- if(commentsFromInactiveCode.length > 0 && commentsFromInactiveCode[0] != null){
- IToken commentToken = commentsFromInactiveCode[0];
- ArrayUtil.remove(commentsFromInactiveCode, commentToken);
- return commentToken;
- }
-
- // Find the first thing we would care about
- skipOverWhiteSpaceFetchToken();
-
- if (++bufferPos[bufferStackPos] >= bufferLimit[bufferStackPos]) {
- // We're at the end of a context, pop it off and try again
- popContext();
- continue;
- }
-
- // Tokens don't span buffers, stick to our current one
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int pos = bufferPos[bufferStackPos];
-
- switch (buffer[pos]) {
- case '\r':
- case '\n':
- continue;
-
- case 'L':
- if (pos + 1 < limit && buffer[pos + 1] == '"')
- return scanString();
- if (pos + 1 < limit && buffer[pos + 1] == '\'')
- return scanCharLiteral();
-
- IToken t = scanIdentifier();
- if (t instanceof MacroExpansionToken)
- continue;
- return t;
-
- case '"':
- return scanString();
-
- case '\'':
- return scanCharLiteral();
-
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- case 'g':
- case 'h':
- case 'i':
- case 'j':
- case 'k':
- case 'l':
- case 'm':
- case 'n':
- case 'o':
- case 'p':
- case 'q':
- case 'r':
- case 's':
- case 't':
- case 'u':
- case 'v':
- case 'w':
- case 'x':
- case 'y':
- case 'z':
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':
- case 'G':
- case 'H':
- case 'I':
- case 'J':
- case 'K':
- case 'M':
- case 'N':
- case 'O':
- case 'P':
- case 'Q':
- case 'R':
- case 'S':
- case 'T':
- case 'U':
- case 'V':
- case 'W':
- case 'X':
- case 'Y':
- case 'Z':
- case '_':
- t = scanIdentifier();
- if (t instanceof MacroExpansionToken)
- continue;
- return t;
-
- case '\\':
- if (pos + 1 < limit
- && (buffer[pos + 1] == 'u' || buffer[pos + 1] == 'U')) {
- t = scanIdentifier();
- if (t instanceof MacroExpansionToken)
- continue;
- return t;
- }
- handleProblem(IProblem.SCANNER_BAD_CHARACTER,
- bufferPos[bufferStackPos], new char[] { '\\' });
- continue;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- return scanNumber();
-
- case '.':
- if (pos + 1 < limit) {
- switch (buffer[pos + 1]) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- return scanNumber();
-
- case '.':
- if (pos + 2 < limit) {
- if (buffer[pos + 2] == '.') {
- bufferPos[bufferStackPos] += 2;
- return newToken(IToken.tELLIPSIS);
- }
- }
- case '*':
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tDOTSTAR);
- }
- }
- return newToken(IToken.tDOT);
-
- case '#':
- if (pos + 1 < limit && buffer[pos + 1] == '#') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tPOUNDPOUND);
- }
-
- // Should really check to make sure this is the first
- // non whitespace character on the line
- handlePPDirective(pos);
- continue;
-
- case '{':
- return newToken(IToken.tLBRACE);
-
- case '}':
- return newToken(IToken.tRBRACE);
-
- case '[':
- return newToken(IToken.tLBRACKET);
-
- case ']':
- return newToken(IToken.tRBRACKET);
-
- case '(':
- return newToken(IToken.tLPAREN);
-
- case ')':
- return newToken(IToken.tRPAREN);
-
- case ';':
- return newToken(IToken.tSEMI);
-
- case ':':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == ':'
- && getLanguage() == ParserLanguage.CPP) {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tCOLONCOLON);
- }
- }
- return newToken(IToken.tCOLON);
-
- case '?':
- return newToken(IToken.tQUESTION);
-
- case '+':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '+') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tINCR);
- } else if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tPLUSASSIGN);
- }
- }
- return newToken(IToken.tPLUS);
-
- case '-':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '>') {
- if (pos + 2 < limit) {
- if (buffer[pos + 2] == '*') {
- bufferPos[bufferStackPos] += 2;
- return newToken(IToken.tARROWSTAR);
- }
- }
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tARROW);
- } else if (buffer[pos + 1] == '-') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tDECR);
- } else if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tMINUSASSIGN);
- }
- }
- return newToken(IToken.tMINUS);
-
- case '*':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tSTARASSIGN);
- }
- }
- return newToken(IToken.tSTAR);
-
- case '/':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tDIVASSIGN);
- } else if (buffer[pos + 1] == '/' || buffer[pos + 1] == '*') {
- return scanComment();
- }
- }
- return newToken(IToken.tDIV);
-
- case '%':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tMODASSIGN);
- }
- }
- return newToken(IToken.tMOD);
-
- case '^':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tXORASSIGN);
- }
- }
- return newToken(IToken.tXOR);
-
- case '&':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '&') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tAND);
- } else if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tAMPERASSIGN);
- }
- }
- return newToken(IToken.tAMPER);
-
- case '|':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '|') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tOR);
- } else if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tBITORASSIGN);
- }
- }
- return newToken(IToken.tBITOR);
-
- case '~':
- return newToken(IToken.tCOMPL);
-
- case '!':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tNOTEQUAL);
- }
- }
- return newToken(IToken.tNOT);
-
- case '=':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tEQUAL);
- }
- }
- return newToken(IToken.tASSIGN);
-
- case '<':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tLTEQUAL);
- } else if (buffer[pos + 1] == '<') {
- if (pos + 2 < limit) {
- if (buffer[pos + 2] == '=') {
- bufferPos[bufferStackPos] += 2;
- return newToken(IToken.tSHIFTLASSIGN);
- }
- }
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tSHIFTL);
- } else if (buffer[pos + 1] == '?' && supportMinAndMax) {
- ++bufferPos[bufferStackPos];
- return newToken(IGCCToken.tMIN, CharArrayUtils.extract(
- buffer, pos, 2));
- }
- }
- return newToken(IToken.tLT);
-
- case '>':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tGTEQUAL);
- } else if (buffer[pos + 1] == '>') {
- if (pos + 2 < limit) {
- if (buffer[pos + 2] == '=') {
- bufferPos[bufferStackPos] += 2;
- return newToken(IToken.tSHIFTRASSIGN);
- }
- }
- ++bufferPos[bufferStackPos];
- return newToken(IToken.tSHIFTR);
- } else if (buffer[pos + 1] == '?' && supportMinAndMax) {
- ++bufferPos[bufferStackPos];
- return newToken(IGCCToken.tMAX, CharArrayUtils.extract(
- buffer, pos, 2));
- }
-
- }
- return newToken(IToken.tGT);
-
- case ',':
- return newToken(IToken.tCOMMA);
-
- default:
- if (Character.isLetter(buffer[pos]) || buffer[pos] == '_'
- || (support$Initializers && buffer[pos] == '$')) {
- t = scanIdentifier();
- if (t instanceof MacroExpansionToken)
- continue;
- return t;
- }
-
- // skip over anything we don't handle
- char [] x = new char [1];
- x[0] = buffer[pos];
- handleProblem( IASTProblem.SCANNER_BAD_CHARACTER, pos, x );
- }
- }
-
- // We've run out of contexts, our work is done here
- if (contentAssistMode) {
- return new SimpleToken(IToken.tCOMPLETION, Integer.MAX_VALUE, null, Integer.MAX_VALUE);
- }
- return null;
- }
-
- protected CharTable ident = new CharTable(1024);
- protected int idents = 0;
-
- protected IToken scanIdentifier() {
- char[] buffer = bufferStack[bufferStackPos];
- boolean escapedNewline = false;
- int start = bufferPos[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int len = 1;
-
- while (++bufferPos[bufferStackPos] < limit) {
- char c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
- || (c >= '0' && c <= '9')
- || Character.isUnicodeIdentifierPart(c)) {
- ++len;
- continue;
- } else if (c == '\\' && (bufferPos[bufferStackPos] + 1 < limit)) {
- if (buffer[bufferPos[bufferStackPos] + 1] == '\n') {
- // escaped newline
- ++bufferPos[bufferStackPos];
- len += 2;
- escapedNewline = true;
- continue;
- }
- if (buffer[bufferPos[bufferStackPos] + 1] == '\r') {
- // escaped newline
- if(buffer[bufferPos[bufferStackPos] + 2] == '\n') {
- ++bufferPos[bufferStackPos];
- ++bufferPos[bufferStackPos];
- len += 3;
- escapedNewline = true;
- continue;
- }
- }
- if ((buffer[bufferPos[bufferStackPos] + 1] == 'u')
- || buffer[bufferPos[bufferStackPos] + 1] == 'U') {
- ++bufferPos[bufferStackPos];
- len += 2;
- continue;
- }
- } else if ((support$Initializers && c == '$')) {
- ++len;
- continue;
- }
- break;
- }
-
- --bufferPos[bufferStackPos];
-
- if(escapedNewline) {
- buffer = removedEscapedNewline(buffer, start, len);
- start = 0;
- len = buffer.length;
- }
-
- if (contentAssistMode && bufferStackPos == 0 && bufferPos[bufferStackPos] + 1 == limit) {
- // return the text as a content assist token
- if(escapedNewline)
- return newToken(IToken.tCOMPLETION, buffer);
- return newToken(IToken.tCOMPLETION, CharArrayUtils.extract(buffer, start, bufferPos[bufferStackPos] - start + 1));
- }
-
- // Check for macro expansion
- Object expObject = definitions.get(buffer, start, len);
-
- if (expObject != null && !isLimitReached()
- && shouldExpandMacro((IMacro) expObject)) {
- boolean expanding = true;
- if (expObject instanceof FunctionStyleMacro) {
- if (handleFunctionStyleMacro((FunctionStyleMacro) expObject,
- true) == null)
- expanding = false;
- } else if (expObject instanceof ObjectStyleMacro) {
- ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject;
- char[] expText = expMacro.getExpansion();
- if (expText.length > 0) {
- final int endOffset= bufferPos[bufferStackPos]+1;
- final int startOffset= endOffset - expMacro.name.length;
- pushContext(expText, new MacroData(startOffset, endOffset, expMacro));
- }
- } else if (expObject instanceof DynamicStyleMacro) {
- DynamicStyleMacro expMacro = (DynamicStyleMacro) expObject;
- char[] expText = expMacro.execute();
- if (expText.length > 0) {
- final int endOffset= bufferPos[bufferStackPos]+1;
- final int startOffset= endOffset - expMacro.name.length;
- pushContext(expText, new MacroData(startOffset, endOffset, expMacro));
- }
-
- } else if (expObject instanceof char[]) {
- char[] expText = (char[]) expObject;
- if (expText.length > 0)
- pushContext(expText);
- }
- if (expanding)
- return EXPANSION_TOKEN;
- }
-
- int tokenType = keywords.get(buffer, start, len);
- if (tokenType != keywords.undefined)
- return newToken(tokenType);
-
- int keyLoc = additionalKeywords.getKeyLocation(buffer, start, len);
- if (keyLoc != additionalKeywords.undefined)
- return newToken(additionalKeywords.get(keyLoc), additionalKeywords.keyAt(keyLoc));
-
- // we have a identifier
- if (cacheIdentifiers)
- return newToken(IToken.tIDENTIFIER, ident.keyAt(ident.addIndex(buffer, start, len)));
- else
- return newToken(IToken.tIDENTIFIER, escapedNewline ? buffer : CharArrayUtils.extract(buffer, start, len));
- }
-
- /**
- * @param buffer
- * @param start
- * @param len
- * @param expObject
- * @return
- */
- protected boolean shouldExpandMacro(IMacro macro) {
- return shouldExpandMacro(macro, bufferStackPos, bufferData, offsetBoundary, bufferPos, bufferStack);
- }
-
- protected static boolean shouldExpandMacro(IMacro macro, int bufferStackPos, Object [] bufferData, int offsetBoundary, int [] bufferPos, char [][]bufferStack )
- {
- // but not if it has been expanded on the stack already
- // i.e. recursion avoidance
- if (macro != null && !isLimitReached(offsetBoundary, bufferStackPos, bufferPos, bufferStack ))
- for (int stackPos = bufferStackPos; stackPos >= 0; --stackPos)
- if (bufferData[stackPos] != null
- && bufferData[stackPos] instanceof MacroData
- && CharArrayUtils.equals(macro.getName(),
- ((MacroData) bufferData[stackPos]).macro
- .getName())) {
- return false;
- }
- return true;
- }
-
- /**
- * @return
- */
- protected final boolean isLimitReached() {
- return isLimitReached(offsetBoundary, bufferStackPos, bufferPos, bufferStack);
- }
-
- /**
- * @param offsetBoundary
- * @param bufferStackPos
- * @param bufferPos
- * @param bufferStack
- * @return
- */
- protected final static boolean isLimitReached(int offsetBoundary, int bufferStackPos, int [] bufferPos, char [][]bufferStack ) {
- if (offsetBoundary == -1 || bufferStackPos != 0)
- return false;
- if (bufferPos[bufferStackPos] == offsetBoundary - 1)
- return true;
- if (bufferPos[bufferStackPos] == offsetBoundary) {
- int c = bufferStack[bufferStackPos][bufferPos[bufferStackPos]];
- if (c == '\n' || c == ' ' || c == '\t' || c == '\r')
- return true;
- }
- return false;
- }
-
-
- protected IToken scanString() {
- char[] buffer = bufferStack[bufferStackPos];
-
- int tokenType = IToken.tSTRING;
- if (buffer[bufferPos[bufferStackPos]] == 'L') {
- ++bufferPos[bufferStackPos];
- tokenType = IToken.tLSTRING;
- }
-
- int stringStart = bufferPos[bufferStackPos] + 1;
- int stringLen = 0;
- boolean escaped = false;
- boolean foundClosingQuote = false;
- while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
- ++stringLen;
- char c = buffer[bufferPos[bufferStackPos]];
- if (c == '"') {
- if (!escaped) {
- foundClosingQuote = true;
- break;
- }
- } else if (c == '\\') {
- escaped = !escaped;
- continue;
- } else if (c == '\n') {
- //unescaped end of line before end of string
- if (!escaped)
- break;
- } else if (c == '\r') {
- if (bufferPos[bufferStackPos] + 1 < bufferLimit[bufferStackPos]
- && buffer[bufferPos[bufferStackPos] + 1] == '\n') {
- ++bufferPos[bufferStackPos];
- if (!escaped)
- break;
- }
- }
- escaped = false;
- }
- --stringLen;
-
- // We should really throw an exception if we didn't get the terminating
- // quote before the end of buffer
- char[] result = CharArrayUtils.extract(buffer, stringStart, stringLen);
- if (!foundClosingQuote) {
- handleProblem(IProblem.SCANNER_UNBOUNDED_STRING, stringStart,
- result);
- }
- return newToken(tokenType, result);
- }
-
- protected IToken scanCharLiteral() {
- char[] buffer = bufferStack[bufferStackPos];
- int start = bufferPos[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- int tokenType = IToken.tCHAR;
- int length = 1;
- if (buffer[bufferPos[bufferStackPos]] == 'L') {
- ++bufferPos[bufferStackPos];
- tokenType = IToken.tLCHAR;
- ++length;
- }
-
- if (start >= limit) {
- return newToken(tokenType, EMPTY_CHAR_ARRAY);
- }
-
- boolean escaped = false;
- while (++bufferPos[bufferStackPos] < limit) {
- ++length;
- int pos = bufferPos[bufferStackPos];
- if (buffer[pos] == '\'') {
- if (!escaped)
- break;
- } else if (buffer[pos] == '\\') {
- escaped = !escaped;
- continue;
- }
- escaped = false;
- }
-
- if (bufferPos[bufferStackPos] == limit) {
- handleProblem(IProblem.SCANNER_BAD_CHARACTER, start, CharArrayUtils
- .extract(buffer, start, length));
- return newToken(tokenType, EMPTY_CHAR_ARRAY);
- }
-
- char[] image = length > 0 ? CharArrayUtils.extract(buffer, start,
- length) : EMPTY_CHAR_ARRAY;
-
- return newToken(tokenType, image);
- }
-
- /**
- * @param scanner_bad_character
- */
- protected abstract void handleProblem(int id, int offset, char[] arg);
-
- /**
- * @param i
- * @return
- */
- protected int getLineNumber(int offset) {
- if (parserMode == ParserMode.COMPLETION_PARSE)
- return -1;
- int index = getCurrentFileIndex();
- if (offset >= bufferLimit[index])
- return -1;
-
- int lineNum = lineNumbers[index];
- int startingPoint = lineOffsets[index];
-
- for (int i = startingPoint; i < offset; ++i) {
- if (bufferStack[index][i] == '\n')
- ++lineNum;
- }
- if (startingPoint < offset) {
- lineNumbers[index] = lineNum;
- lineOffsets[index] = offset;
- }
- return lineNum;
- }
-
- protected IToken scanNumber() throws EndOfFileException {
- char[] buffer = bufferStack[bufferStackPos];
- int start = bufferPos[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- boolean isFloat = buffer[start] == '.';
- boolean hasExponent = false;
-
- boolean isHex = false;
- boolean isOctal = false;
- boolean isMalformedOctal = false;
-
- if (buffer[start] == '0' && start + 1 < limit) {
- switch (buffer[start + 1]) {
- case 'x':
- case 'X':
- isHex = true;
- ++bufferPos[bufferStackPos];
- break;
- default:
- if (buffer[start + 1] > '0' && buffer[start + 1] < '7')
- isOctal = true;
- else if (buffer[start + 1] == '8' || buffer[start + 1] == '9') {
- isOctal = true;
- isMalformedOctal = true;
- }
- }
- }
-
- while (++bufferPos[bufferStackPos] < limit) {
- int pos = bufferPos[bufferStackPos];
- switch (buffer[pos]) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if ((buffer[pos] == '8' || buffer[pos] == '9') && isOctal) {
- isMalformedOctal = true;
- break;
- }
-
- continue;
-
- case '.':
- if (isLimitReached())
- handleNoSuchCompletion();
-
- if (isFloat) {
- // second dot
- handleProblem(IProblem.SCANNER_BAD_FLOATING_POINT, start,
- null);
- break;
- }
-
- isFloat = true;
- continue;
-
- case 'E':
- case 'e':
- if (isHex)
- // a hex 'e'
- continue;
-
- if (hasExponent)
- // second e
- break;
-
- if (pos + 1 >= limit)
- // ending on the e?
- break;
-
- switch (buffer[pos + 1]) {
- case '+':
- case '-':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- // looks like a good exponent
- isFloat = true;
- hasExponent = true;
- ++bufferPos[bufferStackPos];
- continue;
- default:
- // no exponent number?
- break;
- }
- break;
-
- case 'a':
- case 'A':
- case 'b':
- case 'B':
- case 'c':
- case 'C':
- case 'd':
- case 'D':
- if (isHex)
- continue;
-
- // not ours
- break;
-
- case 'f':
- case 'F':
- if (isHex)
- continue;
-
- // must be float suffix
- ++bufferPos[bufferStackPos];
-
- if (bufferPos[bufferStackPos] < buffer.length
- && buffer[bufferPos[bufferStackPos]] == 'i')
- continue; // handle GCC extension 5.10 Complex Numbers
-
- break; // fix for 77281 (used to be continue)
-
- case 'p':
- case 'P':
- // Hex float exponent prefix
- if (!isFloat || !isHex) {
- --bufferPos[bufferStackPos];
- break;
- }
-
- if (hasExponent)
- // second p
- break;
-
- if (pos + 1 >= limit)
- // ending on the p?
- break;
-
- switch (buffer[pos + 1]) {
- case '+':
- case '-':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- // looks like a good exponent
- isFloat = true;
- hasExponent = true;
- ++bufferPos[bufferStackPos];
- continue;
- default:
- // no exponent number?
- break;
- }
- break;
-
- case 'u':
- case 'U':
- case 'L':
- case 'l':
- // unsigned suffix
- suffixLoop: while (++bufferPos[bufferStackPos] < limit) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case 'U':
- case 'u':
- case 'l':
- case 'L':
- break;
- default:
-
- break suffixLoop;
- }
- }
- break;
-
- default:
- boolean success = false;
- for (int iter = 0; iter < suffixes.length; iter++)
- if (buffer[pos] == suffixes[iter]) {
- success = true;
- break;
- }
- if (success)
- continue;
- }
-
- // If we didn't continue in the switch, we're done
- break;
- }
-
- --bufferPos[bufferStackPos];
-
- char[] result = CharArrayUtils.extract(buffer, start,
- bufferPos[bufferStackPos] - start + 1);
- int tokenType = isFloat ? IToken.tFLOATINGPT : IToken.tINTEGER;
-
- if (tokenType == IToken.tINTEGER && isHex && result.length == 2) {
- handleProblem(IProblem.SCANNER_BAD_HEX_FORMAT, start, result);
- } else if (tokenType == IToken.tINTEGER && isOctal && isMalformedOctal) {
- handleProblem(IProblem.SCANNER_BAD_OCTAL_FORMAT, start, result);
- }
-
- return newToken(tokenType, result);
- }
-
- protected boolean branchState(int state) {
- if (state != BRANCH_IF && branchStackPos == -1)
- return false;
-
- switch (state) {
- case BRANCH_IF:
- if (++branchStackPos == branches.length) {
- int[] temp = new int[branches.length << 1];
- System.arraycopy(branches, 0, temp, 0, branches.length);
- branches = temp;
- }
- branches[branchStackPos] = BRANCH_IF;
- return true;
- case BRANCH_ELIF:
- case BRANCH_ELSE:
- switch (branches[branchStackPos]) {
- case BRANCH_IF:
- case BRANCH_ELIF:
- branches[branchStackPos] = state;
- return true;
- default:
- return false;
- }
- case BRANCH_END:
- switch (branches[branchStackPos]) {
- case BRANCH_IF:
- case BRANCH_ELSE:
- case BRANCH_ELIF:
- --branchStackPos;
- return true;
- default:
- return false;
- }
- }
- return false;
- }
-
- protected void handlePPDirective(int pos) throws EndOfFileException {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int startingLineNumber = getLineNumber(pos);
- skipOverWhiteSpace();
- if (isLimitReached())
- handleCompletionOnPreprocessorDirective("#"); //$NON-NLS-1$
-
- // find the directive
- int start = ++bufferPos[bufferStackPos];
-
- // if new line or end of buffer, we're done
- if (start >= limit || buffer[start] == '\n')
- return;
-
- char c = buffer[start];
- if ((c >= 'a' && c <= 'z')) {
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z') || c == '_')
- continue;
- break;
- }
- --bufferPos[bufferStackPos];
- int len = bufferPos[bufferStackPos] - start + 1;
- if (isLimitReached())
- handleCompletionOnPreprocessorDirective(new String(buffer, pos,
- len + 1));
-
- int end;
- int type = ppKeywords.get(buffer, start, len);
- if (type == ppKeywords.undefined && additionalPPKeywords != null) {
- type= additionalPPKeywords.get(buffer, start, len);
- }
- if (type != IPreprocessorDirective.ppInvalid) {
- switch (type) {
- case IPreprocessorDirective.ppInclude:
- handlePPInclude(pos, false, startingLineNumber, true);
- return;
- case IPreprocessorDirective.ppInclude_next:
- handlePPInclude(pos, true, startingLineNumber, true);
- return;
- case IPreprocessorDirective.ppImport:
- handlePPInclude(pos, false, startingLineNumber, true);
- return;
- case IPreprocessorDirective.ppDefine:
- handlePPDefine(pos, startingLineNumber);
- return;
- case IPreprocessorDirective.ppUndef:
- handlePPUndef(pos);
- return;
- case IPreprocessorDirective.ppIfdef:
- handlePPIfdef(pos, true);
- return;
- case IPreprocessorDirective.ppIfndef:
- handlePPIfdef(pos, false);
- return;
- case IPreprocessorDirective.ppIf:
- start = bufferPos[bufferStackPos]+1;
- skipToNewLine();
- end= bufferPos[bufferStackPos]+1;
- len = end - start;
- if (isLimitReached())
- handleCompletionOnExpression(CharArrayUtils.extract(
- buffer, start, len));
- branchState(BRANCH_IF);
-
- if (expressionEvaluator.evaluate(buffer, start, len,
- definitions,
- getLineNumber(start),
- getCurrentFilename()) == 0) {
- processIf(pos, end, false);
- skipOverConditionalCode(true);
- if (isLimitReached())
- handleInvalidCompletion();
- } else {
- processIf(pos, end, true);
- }
- return;
- case IPreprocessorDirective.ppElse:
- case IPreprocessorDirective.ppElif:
- // Condition must have been true, skip over the rest
-
- if (branchState(type == IPreprocessorDirective.ppElse ? BRANCH_ELSE : BRANCH_ELIF)) {
- skipToNewLine();
- if (type == IPreprocessorDirective.ppElse)
- processElse(pos, bufferPos[bufferStackPos] + 1,
- false);
- else
- processElsif(pos, bufferPos[bufferStackPos] + 1, false);
- skipOverConditionalCode(false);
- } else {
- handleProblem(
- IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
- start, ppKeywords.findKey(buffer, start, len));
- skipToNewLine();
- }
-
- if (isLimitReached())
- handleInvalidCompletion();
- return;
- case IPreprocessorDirective.ppError:
- case IPreprocessorDirective.ppWarning:
- skipOverWhiteSpace();
- start = bufferPos[bufferStackPos] + 1;
- skipToNewLine();
- end= bufferPos[bufferStackPos] + 1;
- boolean isWarning= type == IPreprocessorDirective.ppWarning;
- handleProblem(isWarning ? IProblem.PREPROCESSOR_POUND_WARNING : IProblem.PREPROCESSOR_POUND_ERROR, start,
- CharArrayUtils.extract(buffer, start, end-start));
- if (isWarning) {
- processWarning(pos, end);
- } else {
- processError(pos, end);
- }
- return;
- case IPreprocessorDirective.ppEndif:
- skipToNewLine();
- if (branchState(BRANCH_END)) {
- processEndif(pos, bufferPos[bufferStackPos] + 1);
- }
- else {
- handleProblem(
- IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
- start, ppKeywords.findKey(buffer, start, len));
- }
- return;
- case IPreprocessorDirective.ppPragma:
- skipToNewLine();
- processPragma(pos, bufferPos[bufferStackPos]+1);
- return;
- case IPreprocessorDirective.ppIgnore:
- skipToNewLine();
- return;
- }
- }
- } else {
- // ignore preprocessor output lines of the form
- // # <linenum> "<filename>" flags
- if (c >= '0' && c <= '9' && start > pos+1) {
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= '0' && c <= '9'))
- continue;
- break;
- }
- if (bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if (c == ' ' || c == '\t') {
- // now we have # <linenum>
- // skip the rest
- skipToNewLine();
- return;
- }
- }
- --bufferPos[bufferStackPos];
- }
- }
- // directive was not handled, create a problem
- handleProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, start,
- new String(buffer, start, getCurrentOffset() - start + 1).toCharArray());
- skipToNewLine();
- }
-
- /**
- * @param startPos
- * @param endPos
- */
- protected abstract void processPragma(int startPos, int endPos);
-
- /**
- * @param pos
- * @param i
- */
- protected abstract void processEndif(int pos, int i);
-
- /**
- * @param startPos
- * @param endPos
- */
- protected abstract void processError(int startPos, int endPos);
-
- /**
- * Process #warning directive.
- *
- * @param startPos
- * @param endPos
- */
- protected void processWarning(int startPos, int endPos) {
- // default: do nothing
- }
-
- protected abstract void processElsif(int startPos, int endPos, boolean taken);
-
- protected abstract void processElse(int startPos, int endPos, boolean taken);
-
- /**
- * @param pos
- * @param i
- * @param b
- */
- protected abstract void processIf(int startPos, int endPos, boolean taken);
-
- protected void handlePPInclude(int pos2, boolean include_next, int startingLineNumber, boolean active) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- skipOverWhiteSpace();
- int startOffset = pos2;
- int pos = ++bufferPos[bufferStackPos];
- if (pos >= limit)
- return;
-
- boolean local = false;
- String filename = null;
-
- int endOffset = startOffset;
- int nameOffset = 0;
- int nameEndOffset = 0;
-
- int nameLine = 0, endLine = 0;
- char c = buffer[pos];
- int start;
- int length;
-
- switch (c) {
- case '\n':
- return;
- case '"':
- nameLine = getLineNumber(bufferPos[bufferStackPos]);
- local = true;
- start = bufferPos[bufferStackPos] + 1;
- length = 0;
- for (length=0; ++bufferPos[bufferStackPos] < limit; length++) {
- c = buffer[bufferPos[bufferStackPos]];
- if (c == '"') {
- filename = new String(buffer, start, length);
- break;
- }
- else if (c == '\n' || c == '\r') {
- break;
- }
- }
-
- nameOffset = start;
- nameEndOffset = start + length;
- endOffset = start + length + 1;
- break;
- case '<':
- nameLine = getLineNumber(bufferPos[bufferStackPos]);
- local = false;
- start = bufferPos[bufferStackPos] + 1;
-
- for (length=0; ++bufferPos[bufferStackPos] < limit; length++) {
- c = buffer[bufferPos[bufferStackPos]];
- if (c == '>') {
- filename= new String(buffer, start, length);
- break;
- }
- else if (c == '\n' || c == '\r') {
- break;
- }
- }
- endOffset = start + length + 1;
- nameOffset = start;
- nameEndOffset = start + length;
- break;
- default:
- // handle macro expansions
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || c == '_' || (c >= '0' && c <= '9')
- || Character.isUnicodeIdentifierPart(c)) {
- continue;
- } else if (c == '\\'
- && bufferPos[bufferStackPos] + 1 < buffer.length
- && buffer[bufferPos[bufferStackPos] + 1] == '\n') {
- // escaped newline
- ++bufferPos[bufferStackPos];
- continue;
- }
- break;
- }
- nameOffset= pos;
- int len= bufferPos[bufferStackPos] - nameOffset;
- nameEndOffset= nameOffset + len;
- endOffset= nameEndOffset;
- bufferPos[bufferStackPos]--;
-
- Object expObject = definitions.get(buffer, nameOffset, len);
-
- if (expObject != null) {
- char[] t = null;
- if (expObject instanceof FunctionStyleMacro) {
- t = handleFunctionStyleMacro(
- (FunctionStyleMacro) expObject, false);
- } else if (expObject instanceof ObjectStyleMacro) {
- t = ((ObjectStyleMacro) expObject).getExpansion();
- }
- if (t != null) {
- t = replaceArgumentMacros(t);
- if (t.length >= 2) {
- if (t[0] == '"' && t[t.length-1] == '"') {
- local = true;
- filename = new String(t, 1, t.length-2);
- } else if (t[0] == '<' && t[t.length-1] == '>') {
- local = false;
- filename = new String(t, 1, t.length-2);
- }
- }
- }
- }
- break;
- }
-
- if (filename == null || filename == EMPTY_STRING) {
- if (active) {
- handleProblem(IProblem.PREPROCESSOR_INVALID_DIRECTIVE, startOffset,
- new String(buffer, startOffset, nameEndOffset - startOffset).toCharArray());
- return;
- }
- filename= new String(buffer, nameOffset, nameEndOffset - nameOffset);
- }
- char[] fileNameArray = filename.toCharArray();
-
- // TODO else we need to do macro processing on the rest of the line
- endLine = getLineNumber(bufferPos[bufferStackPos]);
- skipToNewLine();
-
- if (parserMode == ParserMode.QUICK_PARSE && active) {
- final Object inc= createInclusionConstruct(
- fileNameArray, EMPTY_CHAR_ARRAY, local, startOffset, startingLineNumber,
- nameOffset, nameEndOffset, nameLine, endOffset, endLine, false);
- quickParsePushPopInclusion(inc);
- }
- else {
- CodeReader reader= null;
- if (active) {
- final File currentDir= local || include_next ? new File(String.valueOf(getCurrentFilename())).getParentFile() : null;
- reader= findInclusion(filename, local, include_next, currentDir);
- if (reader != null) {
- final Object inc = createInclusionConstruct(
- fileNameArray, reader.filename, local, startOffset, startingLineNumber,
- nameOffset, nameEndOffset, nameLine, endOffset, endLine, false);
- pushContext(reader.buffer, new InclusionData(reader, inc, false));
- }
- }
- if (reader == null) {
- processInclude(fileNameArray, local, include_next, active, startOffset, nameOffset, nameEndOffset, endOffset, startingLineNumber, nameLine, endLine);
- if (active) {
- handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset, fileNameArray);
- }
- }
- }
- }
-
- /**
- * Process an include directive without following the inclusion.
- */
- protected void processInclude(char[] fileName, boolean local, boolean include_next, boolean active, int startOffset, int nameOffset,
- int nameEndOffset, int endOffset, int startingLineNumber, int nameLine, int endLine) {
- // default: do nothing
- }
-
- private CodeReader findInclusion(final String filename, final boolean quoteInclude,
- final boolean includeNext, final File currentDir) {
- return (CodeReader) findInclusion(filename, quoteInclude, includeNext, currentDir, createCodeReaderTester);
- }
-
- protected Object findInclusion(final String filename, final boolean quoteInclude,
- final boolean includeNext, final File currentDirectory, final IIncludeFileTester tester) {
- Object reader = null;
- // filename is an absolute path or it is a Linux absolute path on a windows machine
- if (new File(filename).isAbsolute() || filename.startsWith("/")) { //$NON-NLS-1$
- return tester.checkFile( EMPTY_STRING, filename );
- }
-
- if (currentDirectory != null && quoteInclude && !includeNext) {
- // Check to see if we find a match in the current directory
- String absolutePath = currentDirectory.getAbsolutePath();
- reader = tester.checkFile(absolutePath, filename);
- if (reader != null) {
- return reader;
- }
- }
-
- // if we're not include_next, then we are looking for the first occurrence of
- // the file, otherwise, we ignore all the paths before the current directory
- String[] includePathsToUse = quoteInclude ? quoteIncludePaths : includePaths;
- if (includePathsToUse != null ) {
- int startpos = 0;
- if (includeNext && currentDirectory != null) {
- startpos = findIncludePos(includePathsToUse, currentDirectory) + 1;
- }
- for (int i = startpos; i < includePathsToUse.length; ++i) {
- reader = tester.checkFile(includePathsToUse[i], filename);
- if (reader != null) {
- return reader;
- }
- }
- }
- return null;
- }
-
- protected abstract CodeReader createReader(String path, String fileName);
-
-
- private int findIncludePos(String[] paths, File currentDirectory) {
- for (int i = 0; i < paths.length; ++i)
- try {
- String path = new File(paths[i]).getCanonicalPath();
- String parent = currentDirectory.getCanonicalPath();
- if (path.equals(parent))
- return i;
- } catch (IOException e) {
- }
-
- return -1;
- }
-
- /**
- * @param finalPath
- * @return
- */
- protected abstract CodeReader createReaderDuple(String finalPath);
-
- /**
- * @param inclusion
- */
- protected abstract void quickParsePushPopInclusion(Object inclusion);
-
- /**
- * @param fileName
- * @param local
- * @param startOffset
- * @param startingLineNumber
- * @param nameOffset
- * @param nameEndOffset
- * @param nameLine
- * @param endOffset
- * @param endLine
- * @param isForced
- * @param reader
- * @return
- */
- protected abstract Object createInclusionConstruct(char[] fileName,
- char[] filenamePath, boolean local, int startOffset,
- int startingLineNumber, int nameOffset, int nameEndOffset,
- int nameLine, int endOffset, int endLine, boolean isForced);
-
- static int countIt = 0;
- protected void handlePPDefine(int pos2, int startingLineNumber) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- int startingOffset = pos2;
- int endingLine = 0, nameLine = 0;
- skipOverWhiteSpace();
-
- // get the Identifier
- int idstart = ++bufferPos[bufferStackPos];
- if (idstart >= limit)
- return;
-
- char c = buffer[idstart];
- if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || Character
- .isUnicodeIdentifierPart(c))) {
- handleProblem(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN, idstart,
- null);
- skipToNewLine();
- return;
- }
-
- int idlen = 1;
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
- || (c >= '0' && c <= '9')
- || Character.isUnicodeIdentifierPart(c)) {
- ++idlen;
- continue;
- }
- break;
- }
- --bufferPos[bufferStackPos];
- nameLine = getLineNumber(bufferPos[bufferStackPos]);
- char[] name = new char[idlen];
- System.arraycopy(buffer, idstart, name, 0, idlen);
-
- // Now check for function style macro to store the arguments
- char[][] arglist = null;
- int pos = bufferPos[bufferStackPos];
- if (pos + 1 < limit && buffer[pos + 1] == '(') {
- ++bufferPos[bufferStackPos];
- arglist = extractMacroParameters(idstart, name, true);
- if (arglist == null)
- return;
- }
-
- // Capture the replacement text
-
- // Set the offsets to the current position in case there
- // is no replacement sequence (bug #184804)
- int textend = bufferPos[bufferStackPos];
- int textstart = textend + 1;
-
- int varArgDefinitionInd = -1;
- skipOverWhiteSpace();
-
- // if there is a replacement sequence then adjust the offsets accordingly
- if(bufferPos[bufferStackPos] + 1 < limit
- && buffer[bufferPos[bufferStackPos] + 1] != '\n') {
- textend = bufferPos[bufferStackPos];
- textstart = textend + 1;
- }
-
- boolean encounteredComment = false;
- boolean usesVarArgInDefinition = false;
- while (bufferPos[bufferStackPos] + 1 < limit
- && buffer[bufferPos[bufferStackPos] + 1] != '\n') {
-
- if (CharArrayUtils.equals(buffer, bufferPos[bufferStackPos] + 1,
- VA_ARGS_CHARARRAY.length, VA_ARGS_CHARARRAY)) {
- usesVarArgInDefinition = true; // __VA_ARGS__ is in definition,
- // used
- // to check C99 6.10.3-5
- varArgDefinitionInd = bufferPos[bufferStackPos] + 1;
- }
-
- //16.3.2-1 Each # preprocessing token in the replacement list for a
- // function-like-macro shall
- //be followed by a parameter as the next preprocessing token
- if (arglist != null && !skipOverNonWhiteSpace(true)) {
- ++bufferPos[bufferStackPos]; //advances us to the #
- if (skipOverWhiteSpace())
- encounteredComment = true;
-
- boolean isArg = false;
- if (bufferPos[bufferStackPos] + 1 < limit) {
- ++bufferPos[bufferStackPos]; //advances us past the # (or
- // last
- // whitespace)
- for (int i = 0; i < arglist.length && arglist[i] != null; i++) {
- if (bufferPos[bufferStackPos] + arglist[i].length - 1 < limit) {
- if (arglist[i].length > 3
- && arglist[i][arglist[i].length - 3] == '.'
- && arglist[i][arglist[i].length - 2] == '.'
- && arglist[i][arglist[i].length - 3] == '.') {
- char[] varArgName = new char[arglist[i].length - 3];
- System.arraycopy(arglist[i], 0, varArgName, 0,
- arglist[i].length - 3);
- if (CharArrayUtils.equals(buffer,
- bufferPos[bufferStackPos],
- varArgName.length, varArgName)) {
- isArg = true;
- //advance us to the end of the arg
- bufferPos[bufferStackPos] += arglist[i].length - 4;
- break;
- }
- } else if (CharArrayUtils.equals(buffer,
- bufferPos[bufferStackPos],
- arglist[i].length, arglist[i])
- || (CharArrayUtils.equals(arglist[i],
- ELLIPSIS_CHARARRAY) && CharArrayUtils
- .equals(buffer,
- bufferPos[bufferStackPos],
- VA_ARGS_CHARARRAY.length,
- VA_ARGS_CHARARRAY))) {
- isArg = true;
- //advance us to the end of the arg
- bufferPos[bufferStackPos] += arglist[i].length - 1;
- break;
- }
- }
- }
- }
- if (!isArg)
- handleProblem(IProblem.PREPROCESSOR_MACRO_PASTING_ERROR,
- bufferPos[bufferStackPos], null);
- } else {
- skipOverNonWhiteSpace();
- }
- textend = bufferPos[bufferStackPos];
- if(scanComments && (buffer[textend+1]=='/'
- && (buffer[textend+2]=='/'||buffer[textend+2]=='*'))) {
-
- if (skipOverWhiteSpaceAndParseComments())
- encounteredComment = true;
- } else {
- if (skipOverWhiteSpace())
- encounteredComment = true;
- }
- }
-
- int textlen = textend - textstart + 1;
- endingLine = getLineNumber(bufferPos[bufferStackPos]);
- char[] text = EMPTY_CHAR_ARRAY;
- if (textlen > 0) {
- text = new char[textlen];
- System.arraycopy(buffer, textstart, text, 0, textlen);
-// countIt++;
-// System.out.println(countIt);
- }
-
- if (encounteredComment)
- text = removeCommentFromBuffer(text);
- text = removedEscapedNewline(text, 0, text.length);
-
- IMacro result = null;
- if (arglist == null)
- result = new ObjectStyleMacro(name, text);
- else
- result = new FunctionStyleMacro(name, text, arglist);
-
- // Throw it in
- definitions.put(name, result);
-
- if (usesVarArgInDefinition
- && definitions.get(name) instanceof FunctionStyleMacro
- && !((FunctionStyleMacro) definitions.get(name)).hasVarArgs())
- handleProblem(IProblem.PREPROCESSOR_INVALID_VA_ARGS,
- varArgDefinitionInd, null);
-
- int idend = idstart + idlen;
- int textEnd = textstart + textlen;
- processMacro(name, startingOffset, startingLineNumber, idstart, idend,
- nameLine, textEnd, endingLine, result);
- }
-
- /**
- * @param name
- * @param startingOffset
- * @param startingLineNumber
- * @param idstart
- * @param idend
- * @param nameLine
- * @param textEnd
- * @param endingLine
- * @param macro
- * TODO
- */
- protected abstract void processMacro(char[] name, int startingOffset,
- int startingLineNumber, int idstart, int idend, int nameLine,
- int textEnd, int endingLine,
- org.eclipse.cdt.core.parser.IMacro macro);
-
- protected char[][] extractMacroParameters(int idstart, char[] name,
- boolean reportProblems) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- if (bufferPos[bufferStackPos] >= limit
- || buffer[bufferPos[bufferStackPos]] != '(')
- return null;
-
- char c;
- char[][] arglist = new char[4][];
- int currarg = -1;
- while (bufferPos[bufferStackPos] < limit) {
- skipOverWhiteSpace();
- if (++bufferPos[bufferStackPos] >= limit) {
- if (reportProblems) {
- handleProblem(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN,
- idstart, name);
- }
- return null;
- }
- c = buffer[bufferPos[bufferStackPos]];
- int argstart = bufferPos[bufferStackPos];
- if (c == ')') {
- break;
- } else if (c == ',') {
- continue;
- } else if (c == '.' && bufferPos[bufferStackPos] + 1 < limit
- && buffer[bufferPos[bufferStackPos] + 1] == '.'
- && bufferPos[bufferStackPos] + 2 < limit
- && buffer[bufferPos[bufferStackPos] + 2] == '.') {
- bufferPos[bufferStackPos]--; // move back and let
- // skipOverIdentifier
- // handle the ellipsis
- } else if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || c == '_' || Character.isUnicodeIdentifierPart(c))) {
- if (reportProblems) {
- handleProblem(IProblem.PREPROCESSOR_INVALID_MACRO_DEFN,
- idstart, name);
-
- // yuck
- skipToNewLine();
- return null;
- }
- }
-
- skipOverIdentifier();
- if (++currarg == arglist.length) {
- char[][] oldarglist = arglist;
- arglist = new char[oldarglist.length * 2][];
- System.arraycopy(oldarglist, 0, arglist, 0, oldarglist.length);
- }
- int arglen = bufferPos[bufferStackPos] - argstart + 1;
- char[] arg = new char[arglen];
- System.arraycopy(buffer, argstart, arg, 0, arglen);
- arglist[currarg] = arg;
- }
-
- return arglist;
- }
-
- /**
- * @param text
- * @return
- */
- protected char[] removedEscapedNewline(char[] text, int start, int len) {
- if (CharArrayUtils.indexOf('\n', text, start, start + len) == -1)
- return text;
- char[] result = new char[len];
- Arrays.fill(result, ' ');
- int counter = 0;
- for (int i = start; i < start + len; ++i) {
- if (text[i] == '\\' && i + 1 < text.length && text[i + 1] == '\n')
- ++i;
- else if (text[i] == '\\' && i + 1 < text.length
- && text[i + 1] == '\r' && i + 2 < text.length
- && text[i + 2] == '\n')
- i += 2;
- else
- result[counter++] = text[i];
- }
- return CharArrayUtils.trim(result);
- }
-
- /**
- * Remove line and block comments from the given char array.
- * @param text the char array
- * @return a char array without comment
- */
- protected char[] removeCommentFromBuffer(char[] text) {
- char[] result = new char[text.length];
- Arrays.fill(result, ' ');
- int resultCount = 0;
- boolean insideString= false;
- boolean insideSingleQuote= false;
- boolean escaped= false;
- // either a single-line or multi-line comment was found
- forLoop: for (int i = 0; i < text.length; ++i) {
- final char c= text[i];
- switch (c) {
- case '/':
- if (!insideString && !insideSingleQuote && i + 1 < text.length) {
- final char c2= text[i + 1];
- if (c2 == '/') {
- // done
- break forLoop;
- } else if (c2 == '*') {
- i += 2;
- while (i < text.length
- && !(text[i] == '*' && i + 1 < text.length && text[i + 1] == '/'))
- ++i;
- ++i;
- continue;
- }
- }
- escaped= false;
- break;
- case '\\':
- escaped = !escaped;
- break;
- case '"':
- if (!insideSingleQuote) {
- insideString= insideString ? escaped : true;
- }
- escaped= false;
- break;
- case '\'':
- if (!insideString) {
- insideSingleQuote= insideSingleQuote ? escaped : true;
- }
- escaped= false;
- break;
- case '\t':
- if (!insideString && !insideSingleQuote) {
- result[resultCount++]= ' ';
- continue;
- }
- escaped= false;
- break;
- default:
- escaped= false;
- }
- result[resultCount++] = c;
- }
- return CharArrayUtils.trim(result);
- }
-
- protected void handlePPUndef(int pos) throws EndOfFileException {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- skipOverWhiteSpace();
-
- // get the Identifier
- int idstart = ++bufferPos[bufferStackPos];
- if (idstart >= limit)
- return;
-
- char c = buffer[idstart];
- if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || Character
- .isUnicodeIdentifierPart(c))) {
- skipToNewLine();
- return;
- }
-
- int idlen = 1;
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || c == '_'
- || (c >= '0' && c <= '9' || Character
- .isUnicodeIdentifierPart(c))) {
- ++idlen;
- continue;
- }
- break;
-
- }
- --bufferPos[bufferStackPos];
-
- if (isLimitReached())
- handleCompletionOnDefinition(new String(buffer, idstart, idlen));
-
- skipToNewLine();
-
-
- Object definition = definitions.remove(buffer, idstart, idlen);
- processUndef(pos, bufferPos[bufferStackPos]+1, CharArrayUtils.extract(buffer, idstart, idlen ), idstart, definition);
- }
-
- /**
- * @param pos
- * @param endPos
- * @param symbol TODO
- * @param namePos TODO
- * @param definition TODO
- */
- protected abstract void processUndef(int pos, int endPos, char[] symbol, int namePos, Object definition);
-
- protected void handlePPIfdef(int pos, boolean positive)
- throws EndOfFileException {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- if (isLimitReached())
- handleCompletionOnDefinition(EMPTY_STRING);
-
- skipOverWhiteSpace();
-
- if (isLimitReached())
- handleCompletionOnDefinition(EMPTY_STRING);
-
- // get the Identifier
- int idstart = ++bufferPos[bufferStackPos];
- if (idstart >= limit)
- return;
-
- char c = buffer[idstart];
- if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || Character
- .isUnicodeIdentifierPart(c))) {
- skipToNewLine();
- return;
- }
-
- int idlen = 1;
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || c == '_'
- || (c >= '0' && c <= '9' || Character
- .isUnicodeIdentifierPart(c))) {
- ++idlen;
- continue;
- }
- break;
-
- }
- --bufferPos[bufferStackPos];
-
- if (isLimitReached())
- handleCompletionOnDefinition(new String(buffer, idstart, idlen));
-
- skipToNewLine();
-
- branchState(BRANCH_IF);
-
- if ((definitions.get(buffer, idstart, idlen) != null) == positive) {
- processIfdef(pos, bufferPos[bufferStackPos]+1, positive, true);
- return;
- }
-
- processIfdef(pos, bufferPos[bufferStackPos]+1, positive, false);
- // skip over this group
- skipOverConditionalCode(true);
- if (isLimitReached())
- handleInvalidCompletion();
- }
-
- protected abstract void processIfdef(int startPos, int endPos,
- boolean positive, boolean taken);
-
- // checkelse - if potential for more, otherwise skip to endif
- protected void skipOverConditionalCode(boolean checkelse) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int nesting = 0;
-
- while (bufferPos[bufferStackPos] < limit) {
-
- skipOverWhiteSpaceFetchToken();
-
- if (++bufferPos[bufferStackPos] >= limit)
- return;
-
- char c = buffer[bufferPos[bufferStackPos]];
- if (c == '#') {
- int startPos = bufferPos[bufferStackPos];
- skipOverWhiteSpace();
-
- // find the directive
- int start = ++bufferPos[bufferStackPos];
-
- // if new line or end of buffer, we're done
- if (start >= limit || buffer[start] == '\n')
- continue;
-
- c = buffer[start];
- if ((c >= 'a' && c <= 'z')) {
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z'))
- continue;
- break;
- }
- --bufferPos[bufferStackPos];
- int len = bufferPos[bufferStackPos] - start + 1;
- int type = ppKeywords.get(buffer, start, len);
- if (type != ppKeywords.undefined) {
- switch (type) {
- case IPreprocessorDirective.ppIfdef:
- case IPreprocessorDirective.ppIfndef:
- case IPreprocessorDirective.ppIf:
- ++nesting;
- branchState(BRANCH_IF);
- skipToNewLine();
- if (type == IPreprocessorDirective.ppIfdef)
- processIfdef(startPos,
- bufferPos[bufferStackPos]+1, true, false);
- else if (type == IPreprocessorDirective.ppIfndef)
- processIfdef(startPos,
- bufferPos[bufferStackPos]+1, false, false);
- else
- processIf(startPos, bufferPos[bufferStackPos]+1,
- false);
- break;
- case IPreprocessorDirective.ppElse:
- if (branchState(BRANCH_ELSE)) {
- skipToNewLine();
- if (checkelse && nesting == 0) {
- processElse(startPos,
- bufferPos[bufferStackPos]+1, true);
- return;
- }
- processElse(startPos,
- bufferPos[bufferStackPos]+1, false);
- } else {
- //problem, ignore this one.
- handleProblem(
- IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
- start, ppKeywords.findKey(buffer,
- start, len));
- skipToNewLine();
- }
- break;
- case IPreprocessorDirective.ppElif:
- if (branchState(BRANCH_ELIF)) {
- if (checkelse && nesting == 0) {
- // check the condition
- start = bufferPos[bufferStackPos] + 1;
- skipToNewLine();
- int end= bufferPos[bufferStackPos] + 1;
- len= end - start;
- if (expressionEvaluator
- .evaluate(
- buffer,
- start,
- len,
- definitions,
- getLineNumber(start),
- getCurrentFilename()) != 0) {
- // condition passed, we're good
- processElsif(startPos, end, true);
- return;
- }
- processElsif(startPos, end, false);
- } else {
- skipToNewLine();
- processElsif(startPos, bufferPos[bufferStackPos] + 1, false);
- }
- } else {
- //problem, ignore this one.
- handleProblem(
- IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
- start, ppKeywords.findKey(buffer,
- start, len));
- skipToNewLine();
- }
- break;
- case IPreprocessorDirective.ppEndif:
- if (branchState(BRANCH_END)) {
- processEndif(startPos,
- bufferPos[bufferStackPos] + 1);
- if (nesting > 0) {
- --nesting;
- } else {
- skipToNewLine();
- return;
- }
- } else {
- //problem, ignore this one.
- handleProblem(
- IProblem.PREPROCESSOR_UNBALANCE_CONDITION,
- start, ppKeywords.findKey(buffer,
- start, len));
- skipToNewLine();
- }
- break;
- case IPreprocessorDirective.ppInclude:
- handlePPInclude(startPos, false, getLineNumber(startPos), false);
- break;
- case IPreprocessorDirective.ppInclude_next:
- handlePPInclude(startPos, true, getLineNumber(startPos), false);
- break;
- case IPreprocessorDirective.ppImport:
- handlePPInclude(startPos, true, getLineNumber(startPos), false);
- break;
- }
- }
- }
- } else if (c != '\n')
- if(scanComments){
- skipToNewLineAndCollectComments();
- }else{
- skipToNewLine();
- }
- }
- }
-
- protected boolean skipOverWhiteSpace() {
- return skipOverWhiteSpaceAndParseComments();
- }
-
- protected boolean skipOverWhiteSpaceFetchToken() {
-
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- int pos = bufferPos[bufferStackPos];
-
- boolean encounteredComment = false;
- while (++bufferPos[bufferStackPos] < limit) {
- pos = bufferPos[bufferStackPos];
- switch (buffer[pos]) {
- case ' ':
- case '\t':
- case '\r':
- continue;
- case '/':
- if (!scanComments) {
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '/') {
- // C++ comment, skip rest of line
- skipToNewLine(true);
- return false;
- } else if (buffer[pos + 1] == '*') {
- // C comment, find closing */
- for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) {
- pos = bufferPos[bufferStackPos];
- if (buffer[pos] == '*' && pos + 1 < limit
- && buffer[pos + 1] == '/') {
- ++bufferPos[bufferStackPos];
- encounteredComment = true;
- break;
- }
- }
- continue;
- }
- }
- }
- break;
- case '\\':
- if (pos + 1 < limit && buffer[pos + 1] == '\n') {
- // \n is a whitespace
- ++bufferPos[bufferStackPos];
- continue;
- }
- if (pos + 1 < limit && buffer[pos + 1] == '\r') {
- if (pos + 2 < limit && buffer[pos + 2] == '\n') {
- bufferPos[bufferStackPos] += 2;
- continue;
- }
- }
- break;
- }
-
- // fell out of switch without continuing, we're done
- --bufferPos[bufferStackPos];
- return encounteredComment;
- }
- --bufferPos[bufferStackPos];
- return encounteredComment;
- }
-
- protected boolean skipOverWhiteSpaceAndParseComments() {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- int pos = bufferPos[bufferStackPos];
- // if( pos > 0 && pos < limit && buffer[pos] == '\n')
- // return false;
- boolean encounteredComment = false;
- while (++bufferPos[bufferStackPos] < limit) {
- pos = bufferPos[bufferStackPos];
- switch (buffer[pos]) {
- case ' ':
- case '\t':
- case '\r':
- continue;
- case '/':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '/' || buffer[pos + 1] == '*') {
- IToken comment = scanComment();
- if(comment.getType() == IToken.tBLOCKCOMMENT){
- encounteredComment=true;
- }
- continue;
- }
- }
- break;
- case '\\':
- if (pos + 1 < limit && buffer[pos + 1] == '\n') {
- // \n is a whitespace
- ++bufferPos[bufferStackPos];
- continue;
- }
- if (pos + 1 < limit && buffer[pos + 1] == '\r') {
- if (pos + 2 < limit && buffer[pos + 2] == '\n') {
- bufferPos[bufferStackPos] += 2;
- continue;
- }
- }
- break;
- }
- // fell out of switch without continuing, we're done
- --bufferPos[bufferStackPos];
- return encounteredComment;
- }
- --bufferPos[bufferStackPos];
- return encounteredComment;
- }
-
- protected int indexOfNextNonWhiteSpace(char[] buffer, int start, int limit) {
- if (start < 0 || start >= buffer.length || limit > buffer.length)
- return -1;
-
- int pos = start + 1;
- while (pos < limit) {
- switch (buffer[pos++]) {
- case ' ':
- case '\t':
- case '\r':
- continue;
- case '/':
- if (pos < limit) {
- if (buffer[pos] == '/') {
- // C++ comment, skip rest of line
- while (++pos < limit) {
- switch (buffer[pos]) {
- case '\\':
- ++pos;
- break;
- case '\n':
- break;
- }
- }
- } else if (buffer[pos] == '*') {
- // C comment, find closing */
- while (++pos < limit) {
- if (buffer[pos] == '*' && pos + 1 < limit
- && buffer[pos + 1] == '/') {
- pos += 2;
- break;
- }
- }
- }
- }
- continue;
- case '\\':
- if (pos < limit && (buffer[pos] == '\n' || buffer[pos] == '\r')) {
- ++pos;
- continue;
- }
- }
- // fell out of switch without continuing, we're done
- return --pos;
- }
- return pos;
- }
-
- protected void skipOverNonWhiteSpace() {
- skipOverNonWhiteSpace(false);
- }
-
- protected boolean skipOverNonWhiteSpace(boolean stopAtPound) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- while (++bufferPos[bufferStackPos] < limit) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case ' ':
- case '\t':
- case '\r':
- case '\n':
- --bufferPos[bufferStackPos];
- return true;
- case '/':
- int pos = bufferPos[bufferStackPos];
- if (pos + 1 < limit && (buffer[pos + 1] == '/')
- || (buffer[pos + 1] == '*')) {
- --bufferPos[bufferStackPos];
- return true;
- }
- break;
-
- case '\\':
- pos = bufferPos[bufferStackPos];
- if (pos + 1 < limit && buffer[pos + 1] == '\n') {
- // \n is whitespace
- --bufferPos[bufferStackPos];
- return true;
- }
- if (pos + 1 < limit && buffer[pos + 1] == '\r') {
- if (pos + 2 < limit && buffer[pos + 2] == '\n') {
- bufferPos[bufferStackPos] += 2;
- continue;
- }
- }
- break;
- case '"':
- boolean escaped = false;
- if (bufferPos[bufferStackPos] - 1 > 0
- && buffer[bufferPos[bufferStackPos] - 1] == '\\')
- escaped = true;
- loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case '\\':
- escaped = !escaped;
- continue;
- case '"':
- if (escaped) {
- escaped = false;
- continue;
- }
- break loop;
- case '\n':
- if (!escaped)
- break loop;
- case '/':
- if (escaped
- && (bufferPos[bufferStackPos] + 1 < limit)
- && (buffer[bufferPos[bufferStackPos] + 1] == '/' || buffer[bufferPos[bufferStackPos] + 1] == '*')) {
- --bufferPos[bufferStackPos];
- return true;
- }
-
- default:
- escaped = false;
- }
- }
- //if we hit the limit here, then the outer while loop will
- // advance
- //us 2 past the end and we'll back up one and still be past the
- // end,
- //so back up here as well to leave us at the last char.
- if (bufferPos[bufferStackPos] == bufferLimit[bufferStackPos])
- bufferPos[bufferStackPos]--;
- break;
- case '\'':
- escaped = false;
- loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case '\\':
- escaped = !escaped;
- continue;
- case '\'':
- if (escaped) {
- escaped = false;
- continue;
- }
- break loop;
- default:
- escaped = false;
- }
- }
- if (bufferPos[bufferStackPos] == bufferLimit[bufferStackPos])
- bufferPos[bufferStackPos]--;
-
- break;
- case '#':
- if (stopAtPound) {
- if (bufferPos[bufferStackPos] + 1 >= limit
- || buffer[bufferPos[bufferStackPos] + 1] != '#') {
- --bufferPos[bufferStackPos];
- return false;
- }
- ++bufferPos[bufferStackPos];
- }
- break;
- }
- }
- --bufferPos[bufferStackPos];
- return true;
- }
-
- protected int skipOverMacroArg() {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int argEnd = bufferPos[bufferStackPos]--;
- int nesting = 0;
- while (++bufferPos[bufferStackPos] < limit) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case '(':
- ++nesting;
- break;
- case ')':
- if (nesting == 0) {
- --bufferPos[bufferStackPos];
- return argEnd;
- }
- --nesting;
- break;
- case ',':
- if (nesting == 0) {
- --bufferPos[bufferStackPos];
- return argEnd;
- }
- break;
- // fix for 95119
- case '\'':
- boolean escapedChar = false;
- loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case '\\':
- escapedChar = !escapedChar;
- continue;
- case '\'':
- if (escapedChar) {
- escapedChar = false;
- continue;
- }
- break loop;
- default:
- escapedChar = false;
- }
- }
- break;
- case '"':
- boolean escaped = false;
- loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case '\\':
- escaped = !escaped;
- continue;
- case '"':
- if (escaped) {
- escaped = false;
- continue;
- }
- break loop;
- default:
- escaped = false;
- }
- }
- break;
- }
- argEnd = bufferPos[bufferStackPos];
- skipOverWhiteSpace();
- }
- --bufferPos[bufferStackPos];
- // correct argEnd when reaching limit, (bug 179383)
- if (argEnd==limit) {
- argEnd--;
- }
- return argEnd;
- }
-
- protected void skipOverIdentifier() {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- while (++bufferPos[bufferStackPos] < limit) {
- char c = buffer[bufferPos[bufferStackPos]];
- if (c == '.' && bufferPos[bufferStackPos] + 1 < limit
- && buffer[bufferPos[bufferStackPos] + 1] == '.'
- && bufferPos[bufferStackPos] + 2 < limit
- && buffer[bufferPos[bufferStackPos] + 2] == '.') {
- // encountered "..." make sure it's the last argument, if not
- // raise
- // IProblem
-
- bufferPos[bufferStackPos] += 2;
- int end = bufferPos[bufferStackPos];
-
- while (++bufferPos[bufferStackPos] < limit) {
- char c2 = buffer[bufferPos[bufferStackPos]];
-
- if (c2 == ')') { // good
- bufferPos[bufferStackPos] = end; // point at the end of
- // ... to
- // get the argument
- return;
- }
-
- switch (c2) {
- case ' ':
- case '\t':
- case '\r':
- continue;
- case '\\':
- if (bufferPos[bufferStackPos] + 1 < limit
- && buffer[bufferPos[bufferStackPos] + 1] == '\n') {
- // \n is a whitespace
- ++bufferPos[bufferStackPos];
- continue;
- }
- if (bufferPos[bufferStackPos] + 1 < limit
- && buffer[bufferPos[bufferStackPos] + 1] == '\r') {
- if (bufferPos[bufferStackPos] + 2 < limit
- && buffer[bufferPos[bufferStackPos] + 2] == '\n') {
- bufferPos[bufferStackPos] += 2;
- continue;
- }
- }
- break;
- default:
- // bad
- handleProblem(
- IProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST,
- bufferPos[bufferStackPos], String.valueOf(c2)
- .toCharArray());
- return;
- }
- }
- // "..." was the last macro argument
- break;
- } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || c == '_' || (c >= '0' && c <= '9')
- || Character.isUnicodeIdentifierPart(c)) {
- continue;
- }
- break; // found the end of the argument
- }
-
- --bufferPos[bufferStackPos];
- }
-
- protected void skipToNewLine() {
- skipToNewLine(false);
- }
-
- /**
- * Skips everything up to the next newline.
- */
- protected void skipToNewLine(boolean insideComment) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int pos = bufferPos[bufferStackPos];
-
- boolean escaped = false;
- boolean insideString= false;
- boolean insideSingleQuote= false;
- while (++pos < limit) {
- char ch= buffer[pos];
- switch (ch) {
- case '/':
- if (insideComment || insideString || insideSingleQuote) {
- break;
- }
- if (pos + 1 < limit) {
- char c= buffer[pos + 1];
- if (c == '*') {
- pos+=2;
- while (++pos < limit) {
- if (buffer[pos-1] == '*' && buffer[pos] == '/') {
- pos++;
- break;
- }
- }
- pos--;
- break;
- }
- else if (c == '/') {
- insideComment= true;
- }
- }
- break;
- case '\\':
- escaped = !escaped;
- continue;
- case '"':
- if (!insideComment && !insideSingleQuote) {
- insideString= insideString ? escaped : true;
- }
- break;
- case '\'':
- if (!insideComment && !insideString) {
- insideSingleQuote= insideSingleQuote ? escaped : true;
- }
- break;
- case '\n':
- if (escaped) {
- break;
- }
- bufferPos[bufferStackPos]= pos-1;
- return;
- case '\r':
- if (pos+1 < limit && buffer[pos+1] == '\n') {
- if (escaped) {
- pos++;
- break;
- }
- bufferPos[bufferStackPos]= pos-1;
- return;
- }
- break;
- default:
- break;
- }
- escaped = false;
- }
- bufferPos[bufferStackPos]= pos-1;
- }
-
- protected void skipToNewLineAndCollectComments() {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int pos = bufferPos[bufferStackPos];
-
- boolean escaped = false;
- boolean insideString= false;
- boolean insideSingleQuote= false;
- for (;pos < limit;++pos) {
- char ch= buffer[pos];
- switch (ch) {
- case '/':
- if (insideString || insideSingleQuote) {
- break;
- }
- if (pos + 1 < limit) {
- char c= buffer[pos + 1];
- if (c == '*'||c == '/') {
- bufferPos[bufferStackPos] = pos;
- IToken comment = scanComment();
- commentsFromInactiveCode = (IToken[]) ArrayUtil.append(comment.getClass(), commentsFromInactiveCode, comment);
- pos = bufferPos[bufferStackPos];
- }
- }
- break;
- case '\\':
- escaped = !escaped;
- continue;
- case '"':
- if (!insideSingleQuote) {
- insideString= insideString ? escaped : true;
- }
- break;
- case '\'':
- if (!insideString) {
- insideSingleQuote= insideSingleQuote ? escaped : true;
- }
- break;
- case '\n':
- if (escaped) {
- break;
- }
- bufferPos[bufferStackPos]= pos;
- return;
- case '\r':
- if (pos+1 < limit && buffer[pos+1] == '\n') {
- if (escaped) {
- pos++;
- break;
- }
- bufferPos[bufferStackPos]= pos;
- return;
- }
- break;
- default:
- break;
- }
- escaped = false;
- }
- bufferPos[bufferStackPos]= pos;
- }
-
- protected char[] handleFunctionStyleMacro(FunctionStyleMacro macro,
- boolean pushContext) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- int start = bufferPos[bufferStackPos] - macro.name.length + 1;
- skipOverWhiteSpace();
- while (bufferPos[bufferStackPos] < limit
- && buffer[bufferPos[bufferStackPos]] == '\\'
- && bufferPos[bufferStackPos] + 1 < buffer.length
- && buffer[bufferPos[bufferStackPos] + 1] == '\n') {
- bufferPos[bufferStackPos] += 2;
- skipOverWhiteSpace();
- }
-
- if (++bufferPos[bufferStackPos] >= limit) {
- //allow a macro boundary cross here, but only if the caller was
- // prepared to accept a bufferStackPos change
- if (pushContext) {
- int idx = -1;
- int stackpPos = bufferStackPos;
- while (bufferData[stackpPos] != null
- && bufferData[stackpPos] instanceof MacroData) {
- stackpPos--;
- if (stackpPos < 0)
- return EMPTY_CHAR_ARRAY;
- idx = indexOfNextNonWhiteSpace(bufferStack[stackpPos],
- bufferPos[stackpPos], bufferLimit[stackpPos]);
- if (idx >= bufferLimit[stackpPos])
- continue;
- if (idx > 0 && bufferStack[stackpPos][idx] == '(')
- break;
- bufferPos[bufferStackPos]--;
- return null;
- }
- if (idx == -1) {
- bufferPos[bufferStackPos]--;
- return null;
- }
-
- MacroData data;
- IMacro popMacro= macro;
- do {
- data= (MacroData) bufferData[bufferStackPos];
- popContextForFunctionMacroName(popMacro);
- popMacro= data.macro;
- } while (bufferStackPos > stackpPos);
-
- bufferPos[bufferStackPos] = idx;
- buffer = bufferStack[bufferStackPos];
- limit = bufferLimit[bufferStackPos];
- start = data.startOffset;
- } else {
- bufferPos[bufferStackPos]--;
- return null;
- }
- }
-
- // fix for 107150: the scanner stops at the \n or \r after skipOverWhiteSpace() take that into consideration
- while (bufferPos[bufferStackPos] + 1 < limit && (buffer[bufferPos[bufferStackPos]] == '\n' || buffer[bufferPos[bufferStackPos]] == '\r')) {
- bufferPos[bufferStackPos]++; // skip \n or \r
- skipOverWhiteSpace(); // skip any other spaces after the \n
-
- if (bufferPos[bufferStackPos] + 1 < limit && buffer[bufferPos[bufferStackPos]] != '(' && buffer[bufferPos[bufferStackPos] + 1] == '(')
- bufferPos[bufferStackPos]++; // advance to ( if necessary
- }
-
- if (buffer[bufferPos[bufferStackPos]] != '(') {
- bufferPos[bufferStackPos]--;
- return null;
- }
-
- char[][] arglist = macro.arglist;
- int currarg = 0;
- CharArrayObjectMap argmap = new CharArrayObjectMap(arglist.length);
-
- while (bufferPos[bufferStackPos] < limit) {
- skipOverWhiteSpace();
-
- if (bufferPos[bufferStackPos] + 1 >= limit)
- break;
-
- if (buffer[++bufferPos[bufferStackPos]] == ')') {
- if (currarg > 0 && argmap.size() <= currarg) {
- argmap.put(arglist[currarg], EMPTY_CHAR_ARRAY);
- }
- break; // end of macro
- }
- if (buffer[bufferPos[bufferStackPos]] == ',') {
- if (argmap.size() <= currarg) {
- argmap.put(arglist[currarg], EMPTY_CHAR_ARRAY);
- }
- currarg++;
- continue;
- }
-
- if ((currarg >= arglist.length || arglist[currarg] == null)
- && !macro.hasVarArgs() && !macro.hasGCCVarArgs()) {
- // too many args and no variable argument
- handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
- bufferPos[bufferStackPos], macro.name);
- break;
- }
-
- int argstart = bufferPos[bufferStackPos];
-
- int argend = -1;
- if ((macro.hasGCCVarArgs() || macro.hasVarArgs()) && currarg == macro.getVarArgsPosition()) {
- // there are varargs and the other parameters have been accounted
- // for, the rest will replace __VA_ARGS__ or name where
- // "name..." is the parameter
- for (;;) {
- argend= skipOverMacroArg();
- skipOverWhiteSpace();
- // to continue we need at least a comma and another char.
- if (bufferPos[bufferStackPos]+2 >= limit) {
- break;
- }
- if (buffer[++bufferPos[bufferStackPos]] == ')') {
- bufferPos[bufferStackPos]--;
- break;
- }
- // it's a comma
- bufferPos[bufferStackPos]++;
- }
- } else {
- argend = skipOverMacroArg();
- }
-
- char[] arg = EMPTY_CHAR_ARRAY;
- int arglen = argend - argstart + 1;
- if (arglen > 0) {
- arg = new char[arglen];
- System.arraycopy(buffer, argstart, arg, 0, arglen);
- }
-
- argmap.put(arglist[currarg], arg);
- }
-
- int numRequiredArgs = arglist.length;
- for (int i = 0; i < arglist.length; i++) {
- if (arglist[i] == null) {
- numRequiredArgs = i;
- break;
- }
- }
-
- /* Don't require a match for the vararg placeholder */
- /* Workaround for bugzilla 94365 */
- if (macro.hasGCCVarArgs()|| macro.hasVarArgs())
- numRequiredArgs--;
-
- if (argmap.size() < numRequiredArgs) {
- handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
- bufferPos[bufferStackPos], macro.name);
- }
-
- char[] result = null;
- if (macro instanceof DynamicFunctionStyleMacro) {
- result = ((DynamicFunctionStyleMacro) macro).execute(argmap);
- } else {
- CharArrayObjectMap replacedArgs = new CharArrayObjectMap(argmap
- .size());
- int size = expandFunctionStyleMacro(macro.getExpansion(), argmap,
- replacedArgs, null);
- result = new char[size];
- expandFunctionStyleMacro(macro.getExpansion(), argmap, replacedArgs,
- result);
- }
- if (pushContext)
- {
- pushContext(result, new FunctionMacroData(start, bufferPos[bufferStackPos] + 1,
- macro, argmap));
- }
- return result;
- }
-
- /**
- * Called when the buffer limit is reached while expanding a function style macro.
- * This special case might be handled differently by subclasses.
- *
- * @param macro
- */
- protected void popContextForFunctionMacroName(IMacro macro) {
- // do the default
- popContext();
- }
-
- protected char[] replaceArgumentMacros(char[] arg) {
- int limit = arg.length;
- int start = -1, end = -1;
- Object expObject = null;
- for (int pos = 0; pos < limit; pos++) {
- char c = arg[pos];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
- || Character.isLetter(c)
- || (support$Initializers && c == '$')) {
- start = pos;
- while (++pos < limit) {
- c = arg[pos];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || c == '_' || (c >= '0' && c <= '9')
- || (support$Initializers && c == '$')
- || Character.isUnicodeIdentifierPart(c)) {
- continue;
- }
- break;
- }
- end = pos - 1;
- }
- else if (c == '"') {
- boolean escaped= false;
- while (++pos < limit) {
- c = arg[pos];
- if (!escaped && c == '"') {
- break;
- }
- if (c == '\\') {
- escaped= !escaped;
- }
- else {
- escaped= false;
- }
- }
- }
- else if (c == '\'') {
- boolean escaped= false;
- while (++pos < limit) {
- c = arg[pos];
- if (!escaped && c == '\'') {
- break;
- }
- if (c == '\\') {
- escaped= !escaped;
- }
- else {
- escaped= false;
- }
- }
- }
-
- if (start != -1 && end >= start) {
- //Check for macro expansion
- expObject = definitions.get(arg, start, (end - start + 1));
- if (expObject == null || !shouldExpandMacro((IMacro) expObject)) {
- expObject = null;
- start = -1;
- continue;
- }
- //else, break and expand macro
- break;
- }
- }
-
- if (expObject == null)
- {
- return arg;
- }
-
-
- char[] expansion = null;
- if (expObject instanceof FunctionStyleMacro) {
- FunctionStyleMacro expMacro = (FunctionStyleMacro) expObject;
- pushContext((start == 0) ? arg : CharArrayUtils.extract(arg, start,
- arg.length - start));
- bufferPos[bufferStackPos] += end - start + 1;
- expansion = handleFunctionStyleMacro(expMacro, false);
- end = bufferPos[bufferStackPos] + start;
- popContext();
- } else if (expObject instanceof ObjectStyleMacro) {
- ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject;
- expansion = expMacro.getExpansion();
- } else if (expObject instanceof char[]) {
- expansion = (char[]) expObject;
- } else if (expObject instanceof DynamicStyleMacro) {
- DynamicStyleMacro expMacro = (DynamicStyleMacro) expObject;
- expansion = expMacro.execute();
- }
-
- if (expansion != null) {
- int newlength = start + expansion.length + (limit - end - 1);
- char[] result = new char[newlength];
- System.arraycopy(arg, 0, result, 0, start);
- System.arraycopy(expansion, 0, result, start, expansion.length);
- if (arg.length > end + 1)
- System.arraycopy(arg, end + 1, result,
- start + expansion.length, limit - end - 1);
-
-
- beforeReplaceAllMacros();
- //we need to put the macro on the context stack in order to detect
- // recursive macros
- pushContext(EMPTY_CHAR_ARRAY,
- new MacroData(start, start
- + ((IMacro) expObject).getName().length,
- (IMacro) expObject));
- arg = replaceArgumentMacros(result); //rescan for more macros
- popContext();
- afterReplaceAllMacros();
- }
-
- return arg;
- }
-
-
- /**
- * Hook for subclasses.
- */
- protected void afterReplaceAllMacros() {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Hook for subclasses.
- */
- protected void beforeReplaceAllMacros() {
- // TODO Auto-generated method stub
-
- }
-
- protected int expandFunctionStyleMacro(char[] expansion,
- CharArrayObjectMap argmap, CharArrayObjectMap replacedArgs,
- char[] result) {
-
- // The current position in the expansion string that we are looking at
- int pos = -1;
- // The last position in the expansion string that was copied over
- int lastcopy = -1;
- // The current write offset in the result string - also tells us the
- // length of the result string
- int outpos = 0;
- // The first character in the current block of white space - there are
- // times when we don't
- // want to copy over the whitespace
- int wsstart = -1;
- //whether or not we are on the second half of the ## operator
- boolean prevConcat = false;
- //for handling ##
- char[] prevArg = null;
- int prevArgStart = -1;
- int prevArgLength = -1;
- int prevArgTarget = 0;
-
- int limit = expansion.length;
-
- while (++pos < limit) {
- char c = expansion[pos];
-
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
- || (c >= '0' && c < '9')
- || Character.isUnicodeIdentifierPart(c)) {
-
- wsstart = -1;
- int idstart = pos;
- while (++pos < limit) {
- c = expansion[pos];
- if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || (c >= '0' && c <= '9') || c == '_' || Character
- .isUnicodeIdentifierPart(c))) {
- break;
- }
- }
- --pos;
-
- char[] repObject = (char[]) argmap.get(expansion, idstart, pos
- - idstart + 1);
-
- int next = indexOfNextNonWhiteSpace(expansion, pos, limit);
- boolean nextIsPoundPound = (next + 1 < limit
- && expansion[next] == '#' && expansion[next + 1] == '#');
-
- if (prevConcat && prevArgStart > -1 && prevArgLength > 0) {
- int l1 = prevArg != null ? prevArg.length : prevArgLength;
- int l2 = repObject != null ? repObject.length : pos
- - idstart + 1;
- char[] newRep = new char[l1 + l2];
- if (prevArg != null)
- System.arraycopy(prevArg, 0, newRep, 0, l1);
- else
- System
- .arraycopy(expansion, prevArgStart, newRep, 0,
- l1);
-
- if (repObject != null)
- System.arraycopy(repObject, 0, newRep, l1, l2);
- else
- System.arraycopy(expansion, idstart, newRep, l1, l2);
- idstart = prevArgStart;
- repObject = newRep;
- }
- if (repObject != null) {
- // copy what we haven't so far
- if (++lastcopy < idstart) {
- int n = idstart - lastcopy;
- if (result != null) {
- // the outpos may be set back when prevConcat is true, so make sure we
- // stay in bounds.
- if (prevConcat && outpos+n > result.length) {
- n= result.length- outpos;
- }
- System.arraycopy(expansion, lastcopy, result,
- outpos, n);
- }
- outpos += n;
- }
-
- if (prevConcat)
- outpos = prevArgTarget;
-
- if (!nextIsPoundPound) {
- //16.3.1 completely macro replace the arguments before
- // substituting them in
- char[] rep = (char[]) ((replacedArgs != null) ? replacedArgs
- .get(repObject)
- : null);
-
- if (rep != null)
- repObject = rep;
- else {
- rep = replaceArgumentMacros(repObject);
- if (replacedArgs != null)
- replacedArgs.put(repObject, rep);
- repObject = rep;
- }
-
- if (result != null )
- System.arraycopy(repObject, 0, result, outpos, repObject.length);
- }
- outpos += repObject.length;
-
- lastcopy = pos;
- }
-
- prevArg = repObject;
- prevArgStart = idstart;
- prevArgLength = pos - idstart + 1;
- prevArgTarget = repObject != null ? outpos - repObject.length
- : outpos + idstart - lastcopy - 1;
- prevConcat = false;
- } else if (c == '"') {
-
- // skip over strings
- wsstart = -1;
- boolean escaped = false;
- while (++pos < limit) {
- c = expansion[pos];
- if (c == '"') {
- if (!escaped)
- break;
- } else if (c == '\\') {
- escaped = !escaped;
- }
- escaped = false;
- }
- prevConcat = false;
- } else if (c == '\'') {
-
- // skip over character literals
- wsstart = -1;
- boolean escaped = false;
- while (++pos < limit) {
- c = expansion[pos];
- if (c == '\'') {
- if (!escaped)
- break;
- } else if (c == '\\') {
- escaped = !escaped;
- }
- escaped = false;
- }
- prevConcat = false;
- } else if (c == ' ' || c == '\t') {
- // obvious whitespace
- if (wsstart < 0)
- wsstart = pos;
- } else if (c == '/' && pos + 1 < limit) {
-
- // less than obvious, comments are whitespace
- c = expansion[pos+1];
- if (c == '/') {
- // copy up to here or before the last whitespace
- ++pos;
- ++lastcopy;
- int n = wsstart < 0 ? pos - 1 - lastcopy : wsstart
- - lastcopy;
- if (result != null)
- System
- .arraycopy(expansion, lastcopy, result, outpos,
- n);
- outpos += n;
-
- // skip the rest
- lastcopy = expansion.length - 1;
- } else if (c == '*') {
- ++pos;
- if (wsstart < 1)
- wsstart = pos - 1;
- while (++pos < limit) {
- if (expansion[pos] == '*' && pos + 1 < limit
- && expansion[pos + 1] == '/') {
- ++pos;
- break;
- }
- }
- } else
- wsstart = -1;
-
- } else if (c == '\\' && pos + 1 < limit
- && expansion[pos + 1] == 'n') {
- // skip over this
- ++pos;
-
- } else if (c == '#') {
-
- if (pos + 1 < limit && expansion[pos + 1] == '#') {
- prevConcat = true;
- ++pos;
- // skip whitespace
- if (wsstart < 0)
- wsstart = pos - 1;
- while (++pos < limit) {
- switch (expansion[pos]) {
- case ' ':
- case '\t':
- continue;
-
- case '/':
- if (pos + 1 < limit) {
- c = expansion[pos + 1];
- if (c == '/')
- // skip over everything
- pos = expansion.length;
- else if (c == '*') {
- ++pos;
- while (++pos < limit) {
- if (expansion[pos] == '*'
- && pos + 1 < limit
- && expansion[pos + 1] == '/') {
- ++pos;
- break;
- }
- }
- continue;
- }
- }
- }
- break;
- }
- --pos;
- } else {
- prevConcat = false;
- // stringify
-
- // copy what we haven't so far
- if (++lastcopy < pos) {
- int n = pos - lastcopy;
- if (result != null)
- System.arraycopy(expansion, lastcopy, result,
- outpos, n);
- outpos += n;
- }
-
- // skip whitespace
- while (++pos < limit) {
- switch (expansion[pos]) {
- case ' ':
- case '\t':
- continue;
- case '/':
- if (pos + 1 < limit) {
- c = expansion[pos + 1];
- if (c == '/')
- // skip over everything
- pos = expansion.length;
- else if (c == '*') {
- ++pos;
- while (++pos < limit) {
- if (expansion[pos] == '*'
- && pos + 1 < limit
- && expansion[pos + 1] == '/') {
- ++pos;
- break;
- }
- }
- continue;
- }
- }
- //TODO handle comments
- }
- break;
- }
-
- // grab the identifier
- c = expansion[pos];
- int idstart = pos;
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'X')
- || c == '_' || Character.isUnicodeIdentifierPart(c)) {
- while (++pos < limit) {
- c = expansion[pos];
- if (!((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'X')
- || (c >= '0' && c <= '9') || c == '_' || Character
- .isUnicodeIdentifierPart(c)))
- break;
- }
- } // else TODO something
- --pos;
- int idlen = pos - idstart + 1;
- char[] argvalue = (char[]) argmap.get(expansion, idstart,
- idlen);
- if (argvalue != null) {
- //16.3.2-2 ... a \ character is inserted before each "
- // and \
- // character
- //of a character literal or string literal
-
- //technically, we are also supposed to replace each
- // occurence
- // of whitespace
- //(including comments) in the argument with a single
- // space.
- // But, at this time
- //we don't really care what the contents of the string
- // are,
- // just that we get the string
- //so we won't bother doing that
- if (result != null) {
- result[outpos++] = '"';
- for (int i = 0; i < argvalue.length; i++) {
- if (argvalue[i] == '"' || argvalue[i] == '\\')
- result[outpos++] = '\\';
- if (argvalue[i] == '\r' || argvalue[i] == '\n')
- result[outpos++] = ' ';
- else
- result[outpos++] = argvalue[i];
- }
- result[outpos++] = '"';
- } else {
- for (int i = 0; i < argvalue.length; i++) {
- if (argvalue[i] == '"' || argvalue[i] == '\\')
- ++outpos;
- ++outpos;
- }
- outpos += 2;
- }
- }
- lastcopy = pos;
- wsstart = -1;
- }
- } else {
- prevConcat = false;
- // not sure what it is but it sure ain't whitespace
- wsstart = -1;
- }
-
- }
-
- if (wsstart < 0 && ++lastcopy < expansion.length) {
- int n = expansion.length - lastcopy;
- if (result != null)
- System.arraycopy(expansion, lastcopy, result, outpos, n);
- outpos += n;
- }
-
- return outpos;
- }
-
- // standard built-ins
- protected static final ObjectStyleMacro __cplusplus = new ObjectStyleMacro(
- "__cplusplus".toCharArray(), ONE); //$NON-NLS-1$
-
- protected static final ObjectStyleMacro __STDC__ = new ObjectStyleMacro(
- "__STDC__".toCharArray(), ONE); //$NON-NLS-1$
-
- protected static final ObjectStyleMacro __STDC_HOSTED__ = new ObjectStyleMacro(
- "__STDC_HOSTED_".toCharArray(), ONE); //$NON-NLS-1$
-
- protected static final ObjectStyleMacro __STDC_VERSION__ = new ObjectStyleMacro(
- "__STDC_VERSION_".toCharArray(), "199901L".toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$
-
- protected final DynamicStyleMacro __FILE__ = new DynamicStyleMacro(
- "__FILE__".toCharArray()) { //$NON-NLS-1$
-
- public char[] execute() {
- StringBuffer buffer = new StringBuffer("\""); //$NON-NLS-1$
- buffer.append(getCurrentFilename());
- buffer.append('\"');
- return buffer.toString().toCharArray();
- }
- };
-
- protected final DynamicStyleMacro __DATE__ = new DynamicStyleMacro(
- "__DATE__".toCharArray()) { //$NON-NLS-1$
-
- protected final void append(StringBuffer buffer, int value) {
- if (value < 10)
- buffer.append("0"); //$NON-NLS-1$
- buffer.append(value);
- }
-
- public char[] execute() {
- StringBuffer buffer = new StringBuffer("\""); //$NON-NLS-1$
- Calendar cal = Calendar.getInstance();
- buffer.append(cal.get(Calendar.MONTH));
- buffer.append(" "); //$NON-NLS-1$
- append(buffer, cal.get(Calendar.DAY_OF_MONTH));
- buffer.append(" "); //$NON-NLS-1$
- buffer.append(cal.get(Calendar.YEAR));
- buffer.append("\""); //$NON-NLS-1$
- return buffer.toString().toCharArray();
- }
- };
-
- protected final DynamicStyleMacro __TIME__ = new DynamicStyleMacro(
- "__TIME__".toCharArray()) { //$NON-NLS-1$
-
- protected final void append(StringBuffer buffer, int value) {
- if (value < 10)
- buffer.append("0"); //$NON-NLS-1$
- buffer.append(value);
- }
-
- public char[] execute() {
- StringBuffer buffer = new StringBuffer("\""); //$NON-NLS-1$
- Calendar cal = Calendar.getInstance();
- append(buffer, cal.get(Calendar.HOUR));
- buffer.append(":"); //$NON-NLS-1$
- append(buffer, cal.get(Calendar.MINUTE));
- buffer.append(":"); //$NON-NLS-1$
- append(buffer, cal.get(Calendar.SECOND));
- buffer.append("\""); //$NON-NLS-1$
- return buffer.toString().toCharArray();
- }
- };
-
- protected final DynamicStyleMacro __LINE__ = new DynamicStyleMacro(
- "__LINE__".toCharArray()) { //$NON-NLS-1$
-
- public char[] execute() {
- int lineNumber = lineNumbers[bufferStackPos];
- return Long.toString(lineNumber).toCharArray();
- }
- };
-
- protected int offsetBoundary = -1;
-
- protected boolean contentAssistMode = false;
-
- protected void setupBuiltInMacros(IScannerExtensionConfiguration config) {
-
- definitions.put(__STDC__.name, __STDC__);
- definitions.put(__FILE__.name, __FILE__);
- definitions.put(__DATE__.name, __DATE__);
- definitions.put(__TIME__.name, __TIME__);
- definitions.put(__LINE__.name, __LINE__);
-
- if (language == ParserLanguage.CPP)
- definitions.put(__cplusplus.name, __cplusplus);
- else {
- definitions.put(__STDC_HOSTED__.name, __STDC_HOSTED__);
- definitions.put(__STDC_VERSION__.name, __STDC_VERSION__);
- }
-
- CharArrayObjectMap toAdd = config.getAdditionalMacros();
- for (int i = 0; i < toAdd.size(); ++i)
- definitions.put(toAdd.keyAt(i), toAdd.getAt(i));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.parser.IScanner#setOffsetBoundary(int)
- */
- public final void setOffsetBoundary(int offset) {
- offsetBoundary = offset;
- bufferLimit[0] = offset;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IScanner#setContentAssistMode(int)
- */
- public void setContentAssistMode(int offset) {
- setOffsetBoundary(offset);
- contentAssistMode = true;
- }
-
- /**
- * Turns on/off comment parsing.
- * @since 4.0
- */
- public void setScanComments(boolean val) {
- scanComments= val;
- }
-
- protected ParserLanguage getLanguage() {
- return language;
- }
-
- protected CodeReader getMainReader() {
- if (bufferData != null && bufferData[0] != null
- && bufferData[0] instanceof CodeReader)
- return ((CodeReader) bufferData[0]);
- return null;
- }
-
- public char[] getMainFilename() {
- if (bufferData != null && bufferData[0] != null
- && bufferData[0] instanceof CodeReader)
- return ((CodeReader) bufferData[0]).filename;
-
- return EMPTY_CHAR_ARRAY;
- }
-
- protected final char[] getCurrentFilename() {
- for (int i = bufferStackPos; i >= 0; --i) {
- if (bufferData[i] instanceof InclusionData)
- return ((InclusionData) bufferData[i]).reader.filename;
- if (bufferData[i] instanceof CodeReader)
- return ((CodeReader) bufferData[i]).filename;
- }
- return EMPTY_CHAR_ARRAY;
- }
-
- protected final int getCurrentFileIndex() {
- for (int i = bufferStackPos; i >= 0; --i) {
- if (bufferData[i] instanceof InclusionData
- || bufferData[i] instanceof CodeReader)
- return i;
- }
- return 0;
- }
-
- protected final CharArrayIntMap keywords;
-
- protected static CharArrayIntMap ckeywords;
-
- protected static CharArrayIntMap cppkeywords;
-
- protected static CharArrayIntMap ppKeywords;
-
- protected static final char[] TAB = { '\t' };
-
- protected static final char[] SPACE = { ' ' };
-
- private static final MacroExpansionToken EXPANSION_TOKEN = new MacroExpansionToken();
-
- static {
- CharArrayIntMap words = new CharArrayIntMap(40, -1);
-
- // Common keywords
- words.put(Keywords.cAUTO, IToken.t_auto);
- words.put(Keywords.cBREAK, IToken.t_break);
- words.put(Keywords.cCASE, IToken.t_case);
- words.put(Keywords.cCHAR, IToken.t_char);
- words.put(Keywords.cCONST, IToken.t_const);
- words.put(Keywords.cCONTINUE, IToken.t_continue);
- words.put(Keywords.cDEFAULT, IToken.t_default);
- words.put(Keywords.cDO, IToken.t_do);
- words.put(Keywords.cDOUBLE, IToken.t_double);
- words.put(Keywords.cELSE, IToken.t_else);
- words.put(Keywords.cENUM, IToken.t_enum);
- words.put(Keywords.cEXTERN, IToken.t_extern);
- words.put(Keywords.cFLOAT, IToken.t_float);
- words.put(Keywords.cFOR, IToken.t_for);
- words.put(Keywords.cGOTO, IToken.t_goto);
- words.put(Keywords.cIF, IToken.t_if);
- words.put(Keywords.cINLINE, IToken.t_inline);
- words.put(Keywords.cINT, IToken.t_int);
- words.put(Keywords.cLONG, IToken.t_long);
- words.put(Keywords.cREGISTER, IToken.t_register);
- words.put(Keywords.cRETURN, IToken.t_return);
- words.put(Keywords.cSHORT, IToken.t_short);
- words.put(Keywords.cSIGNED, IToken.t_signed);
- words.put(Keywords.cSIZEOF, IToken.t_sizeof);
- words.put(Keywords.cSTATIC, IToken.t_static);
- words.put(Keywords.cSTRUCT, IToken.t_struct);
- words.put(Keywords.cSWITCH, IToken.t_switch);
- words.put(Keywords.cTYPEDEF, IToken.t_typedef);
- words.put(Keywords.cUNION, IToken.t_union);
- words.put(Keywords.cUNSIGNED, IToken.t_unsigned);
- words.put(Keywords.cVOID, IToken.t_void);
- words.put(Keywords.cVOLATILE, IToken.t_volatile);
- words.put(Keywords.cWHILE, IToken.t_while);
- words.put(Keywords.cASM, IToken.t_asm);
-
- // ANSI C keywords
- ckeywords = (CharArrayIntMap) words.clone();
- ckeywords.put(Keywords.cRESTRICT, IToken.t_restrict);
- ckeywords.put(Keywords.c_BOOL, IToken.t__Bool);
- ckeywords.put(Keywords.c_COMPLEX, IToken.t__Complex);
- ckeywords.put(Keywords.c_IMAGINARY, IToken.t__Imaginary);
-
- // C++ Keywords
- cppkeywords = words;
- cppkeywords.put(Keywords.cBOOL, IToken.t_bool);
- cppkeywords.put(Keywords.cCATCH, IToken.t_catch);
- cppkeywords.put(Keywords.cCLASS, IToken.t_class);
- cppkeywords.put(Keywords.cCONST_CAST, IToken.t_const_cast);
- cppkeywords.put(Keywords.cDELETE, IToken.t_delete);
- cppkeywords.put(Keywords.cDYNAMIC_CAST, IToken.t_dynamic_cast);
- cppkeywords.put(Keywords.cEXPLICIT, IToken.t_explicit);
- cppkeywords.put(Keywords.cEXPORT, IToken.t_export);
- cppkeywords.put(Keywords.cFALSE, IToken.t_false);
- cppkeywords.put(Keywords.cFRIEND, IToken.t_friend);
- cppkeywords.put(Keywords.cMUTABLE, IToken.t_mutable);
- cppkeywords.put(Keywords.cNAMESPACE, IToken.t_namespace);
- cppkeywords.put(Keywords.cNEW, IToken.t_new);
- cppkeywords.put(Keywords.cOPERATOR, IToken.t_operator);
- cppkeywords.put(Keywords.cPRIVATE, IToken.t_private);
- cppkeywords.put(Keywords.cPROTECTED, IToken.t_protected);
- cppkeywords.put(Keywords.cPUBLIC, IToken.t_public);
- cppkeywords.put(Keywords.cREINTERPRET_CAST, IToken.t_reinterpret_cast);
- cppkeywords.put(Keywords.cSTATIC_CAST, IToken.t_static_cast);
- cppkeywords.put(Keywords.cTEMPLATE, IToken.t_template);
- cppkeywords.put(Keywords.cTHIS, IToken.t_this);
- cppkeywords.put(Keywords.cTHROW, IToken.t_throw);
- cppkeywords.put(Keywords.cTRUE, IToken.t_true);
- cppkeywords.put(Keywords.cTRY, IToken.t_try);
- cppkeywords.put(Keywords.cTYPEID, IToken.t_typeid);
- cppkeywords.put(Keywords.cTYPENAME, IToken.t_typename);
- cppkeywords.put(Keywords.cUSING, IToken.t_using);
- cppkeywords.put(Keywords.cVIRTUAL, IToken.t_virtual);
- cppkeywords.put(Keywords.cWCHAR_T, IToken.t_wchar_t);
-
- // C++ operator alternative
- cppkeywords.put(Keywords.cAND, IToken.t_and);
- cppkeywords.put(Keywords.cAND_EQ, IToken.t_and_eq);
- cppkeywords.put(Keywords.cBITAND, IToken.t_bitand);
- cppkeywords.put(Keywords.cBITOR, IToken.t_bitor);
- cppkeywords.put(Keywords.cCOMPL, IToken.t_compl);
- cppkeywords.put(Keywords.cNOT, IToken.t_not);
- cppkeywords.put(Keywords.cNOT_EQ, IToken.t_not_eq);
- cppkeywords.put(Keywords.cOR, IToken.t_or);
- cppkeywords.put(Keywords.cOR_EQ, IToken.t_or_eq);
- cppkeywords.put(Keywords.cXOR, IToken.t_xor);
- cppkeywords.put(Keywords.cXOR_EQ, IToken.t_xor_eq);
-
- // Preprocessor keywords
- ppKeywords = new CharArrayIntMap(16, IPreprocessorDirective.ppInvalid);
- ppKeywords.put(Keywords.cIF, IPreprocessorDirective.ppIf);
- ppKeywords.put(Keywords.cIFDEF, IPreprocessorDirective.ppIfdef);
- ppKeywords.put(Keywords.cIFNDEF, IPreprocessorDirective.ppIfndef);
- ppKeywords.put(Keywords.cELIF, IPreprocessorDirective.ppElif);
- ppKeywords.put(Keywords.cELSE, IPreprocessorDirective.ppElse);
- ppKeywords.put(Keywords.cENDIF, IPreprocessorDirective.ppEndif);
- ppKeywords.put(Keywords.cINCLUDE, IPreprocessorDirective.ppInclude);
- ppKeywords.put(Keywords.cDEFINE, IPreprocessorDirective.ppDefine);
- ppKeywords.put(Keywords.cUNDEF, IPreprocessorDirective.ppUndef);
- ppKeywords.put(Keywords.cERROR, IPreprocessorDirective.ppError);
- ppKeywords.put(Keywords.cPRAGMA, IPreprocessorDirective.ppPragma);
- ppKeywords.put(Keywords.cLINE, IPreprocessorDirective.ppIgnore);
- }
-
- /**
- * @param definition
- */
- protected void handleCompletionOnDefinition(String definition)
- throws EndOfFileException {
- throw new OffsetLimitReachedException(definition);
- }
-
- /**
- * @param expression2
- */
- protected void handleCompletionOnExpression(char[] buffer)
- throws EndOfFileException {
-
- int lastSpace = CharArrayUtils.lastIndexOf(SPACE, buffer);
- int lastTab = CharArrayUtils.lastIndexOf(TAB, buffer);
- int max = lastSpace > lastTab ? lastSpace : lastTab;
-
- char[] prefix = CharArrayUtils.trim(CharArrayUtils.extract(buffer, max,
- buffer.length - max));
- for (int i = 0; i < prefix.length; ++i) {
- char c = prefix[i];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'
- || (c >= '0' && c <= '9')
- || Character.isUnicodeIdentifierPart(c))
- continue;
- handleInvalidCompletion();
- }
- throw new OffsetLimitReachedException(new String(prefix));
- }
-
- protected void handleNoSuchCompletion() throws EndOfFileException {
- throw new OffsetLimitReachedException(EMPTY_STRING);
- }
-
- protected void handleInvalidCompletion() throws EndOfFileException {
- throw new OffsetLimitReachedException(EMPTY_STRING);
- }
-
- protected void handleCompletionOnPreprocessorDirective(String prefix)
- throws EndOfFileException {
- throw new OffsetLimitReachedException(prefix);
- }
-
- protected int getCurrentOffset() {
- return bufferPos[bufferStackPos];
- }
- protected IToken scanComment() {
- char[] buffer = bufferStack[bufferStackPos];
- final int limit = bufferLimit[bufferStackPos];
-
- int pos = bufferPos[bufferStackPos];
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '/') {
- // C++ comment
- int commentLength = 0;
- while (++bufferPos[bufferStackPos] < limit) {
- if (buffer[bufferPos[bufferStackPos]] == '\n'||buffer[bufferPos[bufferStackPos]] == '\r') {
- break;
- }
- ++commentLength;
- }
- // leave the new line there
- --bufferPos[bufferStackPos];
- return newToken(IToken.tCOMMENT, CharArrayUtils.extract(buffer,
- pos, bufferPos[bufferStackPos] - pos + 1));
- } else if (buffer[pos + 1] == '*') {
- // C comment, find closing */
- int start = pos;
- for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos]+1 < limit; ++bufferPos[bufferStackPos]) {
- pos = bufferPos[bufferStackPos];
- if (buffer[pos] == '*' && buffer[pos + 1] == '/') {
- ++bufferPos[bufferStackPos];
- break;
- }
- }
- return newToken(IToken.tBLOCKCOMMENT, CharArrayUtils.extract(
- buffer, start, bufferPos[bufferStackPos] - start + 1));
- }
- }
- return null;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer buffer = new StringBuffer("Scanner @ file:"); //$NON-NLS-1$
- buffer.append(getCurrentFilename());
- buffer.append(" line: "); //$NON-NLS-1$
- buffer.append(getLineNumber(getCurrentOffset()));
- return buffer.toString();
- }
-
- protected abstract IToken newToken(int signal);
-
- protected abstract IToken newToken(int signal, char[] buffer);
-
- public void setComputeImageLocations(boolean val) {
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java
deleted file mode 100644
index 6daff852a6c..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DOMScanner.java
+++ /dev/null
@@ -1,1413 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Anton Leherbauer (Wind River Systems)
- * Emanuel Graf (IFS)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.cdt.core.dom.ICodeReaderFactory;
-import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.core.dom.parser.IScannerExtensionConfiguration;
-import org.eclipse.cdt.core.parser.CodeReader;
-import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.core.parser.IParserLogService;
-import org.eclipse.cdt.core.parser.IScannerInfo;
-import org.eclipse.cdt.core.parser.IToken;
-import org.eclipse.cdt.core.parser.ITokenDuple;
-import org.eclipse.cdt.core.parser.Keywords;
-import org.eclipse.cdt.core.parser.ParserLanguage;
-import org.eclipse.cdt.core.parser.ParserMode;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-
-/**
- * @author jcamelon
- * @deprecated will be removed in 5.0
- */
-public class DOMScanner extends BaseScanner {
- private static final Class CHAR_ARRAY_CLASS = new char[]{}.getClass();
-
- public static final String PROP_VALUE = "DOMScanner"; //$NON-NLS-1$
-
- private final IScannerPreprocessorLog locationMap = new LocationMap();
- private final IIncludeFileTester createPathTester= new IIncludeFileTester() {
- public Object checkFile(String path, String fileName) {
- path= ScannerUtility.createReconciledPath(path, fileName);
- if (new File(path).exists()) {
- return path;
- }
- return null;
- }
- };
-
- protected final ICodeReaderFactory codeReaderFactory;
- protected int[] bufferDelta = new int[bufferInitialSize];
-
- private static class DOMInclusion {
- public final char[] pt;
- public final int o;
- public final int nameOffset;
- public final int nameEndoffset;
- public final char[] name;
- public boolean systemInclude;
-
- /**
- *
- */
- public DOMInclusion(char[] path, int offset, int nameOffset, int nameEndoffset, char[] name, boolean systemInclude) {
- this.pt = path;
- this.o = offset;
- this.nameOffset= nameOffset;
- this.nameEndoffset= nameEndoffset;
- this.name= name;
- this.systemInclude= systemInclude;
- }
- }
-
- /**
- * @param reader
- * @param info
- * @param parserMode
- * @param language
- * @param log
- * @param readerFactory
- * TODO
- * @param requestor
- */
- public DOMScanner(CodeReader reader, IScannerInfo info,
- ParserMode parserMode, ParserLanguage language,
- IParserLogService log,
- IScannerExtensionConfiguration configuration,
- ICodeReaderFactory readerFactory) {
- super(reader, info, parserMode, language, log, configuration);
- this.expressionEvaluator = new ExpressionEvaluator(null);
- this.codeReaderFactory = readerFactory;
- postConstructorSetup(reader, info);
- }
-
- private void registerMacros() {
- for( int i = 0; i < definitions.size(); ++i )
- {
- registerMacro((IMacro)definitions.get(definitions.keyAt(i)));
- }
- }
-
- private void registerMacro(IMacro m) {
- if (m == null)
- return;
- if (m instanceof ObjectStyleMacro && ((ObjectStyleMacro)m).attachment != null)
- return;
-
- if (m instanceof DynamicStyleMacro) {
- DynamicStyleMacro macro = (DynamicStyleMacro) m;
- macro.attachment = locationMap.registerBuiltinDynamicStyleMacro( macro );
- } else if (m instanceof DynamicFunctionStyleMacro) {
- DynamicFunctionStyleMacro macro = (DynamicFunctionStyleMacro) m;
- macro.attachment = locationMap.registerBuiltinDynamicFunctionStyleMacro( macro );
- } else if (m instanceof FunctionStyleMacro) {
- FunctionStyleMacro macro = (FunctionStyleMacro) m;
- macro.attachment = locationMap.registerBuiltinFunctionStyleMacro( macro );
- } else if (m instanceof ObjectStyleMacro) {
- ObjectStyleMacro macro = (ObjectStyleMacro) m;
- macro.attachment = locationMap.registerBuiltinObjectStyleMacro( macro );
- }
- }
-
- public void addDefinition(IMacro macro) {
- super.addDefinition(macro);
- registerMacro(macro);
- }
-
- public ILocationResolver getLocationResolver() {
- if (locationMap instanceof ILocationResolver)
- return (ILocationResolver) locationMap;
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createInclusionConstruct(char[],
- * char[], boolean, int, int, int, int, int, int, int, boolean)
- */
- protected Object createInclusionConstruct(char[] fileName,
- char[] filenamePath, boolean local, int startOffset,
- int startingLineNumber, int nameOffset, int nameEndOffset,
- int nameLine, int endOffset, int endLine, boolean isForced) {
- return new DOMInclusion(filenamePath, getGlobalOffset(startOffset),
- getGlobalOffset(nameOffset), getGlobalOffset(nameEndOffset),
- fileName, !local);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processMacro(char[],
- * int, int, int, int, int, int, int)
- */
- protected void processMacro(char[] name, int startingOffset,
- int startingLineNumber, int idstart, int idend, int nameLine,
- int textEnd, int endingLine, IMacro macro) {
- IScannerPreprocessorLog.IMacroDefinition m = null;
- if (macro instanceof FunctionStyleMacro)
- m = locationMap.defineFunctionStyleMacro(
- (FunctionStyleMacro) macro, getGlobalOffset(startingOffset),
- getGlobalOffset(idstart), getGlobalOffset(idend),
- getGlobalOffset(textEnd));
- else if (macro instanceof ObjectStyleMacro)
- m = locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
- getGlobalOffset(startingOffset), getGlobalOffset(idstart),
- getGlobalOffset(idend), getGlobalOffset(textEnd));
- if (m != null && macro instanceof ObjectStyleMacro)
- ((ObjectStyleMacro) macro).attachment = m;
-
- }
-
- /*
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processInclude(char[], boolean, boolean, int, int, int, int, int, int, int)
- */
- protected void processInclude(char[] filename, boolean local, boolean include_next, boolean active,
- int startOffset, int nameOffset, int nameEndOffset, int endOffset, int startingLineNumber,
- int nameLine, int endLine) {
- char[] pchars= null;
- final File currentDir= local || include_next ? new File(String.valueOf(getCurrentFilename())).getParentFile() : null;
- String path= (String) findInclusion(new String(filename), local, include_next, currentDir, createPathTester);
- if (path != null) {
- if (codeReaderFactory instanceof IIndexBasedCodeReaderFactory) {
- // fast indexer
- if (((IIndexBasedCodeReaderFactory) codeReaderFactory).hasFileBeenIncludedInCurrentTranslationUnit(path)) {
- pchars= path.toCharArray();
- }
- }
- else {
- // full indexer
- pchars= path.toCharArray();
- if (!includedFiles.containsKey(pchars)) {
- // not a hidden dependency, don't report it.
- pchars= null;
- }
- }
- }
- locationMap.encounterPoundInclude(getGlobalOffset(startOffset), getGlobalOffset(nameOffset),
- getGlobalOffset(nameEndOffset), getGlobalOffset(endOffset),
- filename, pchars, !local, active);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#createReaderDuple(java.lang.String)
- */
- protected CodeReader createReaderDuple(String finalPath) {
- return codeReaderFactory.createCodeReaderForInclusion(this, finalPath);
- }
-
- protected void pushContext(char[] buffer) {
- // called before the constructor, so check for bufferDelta to be
- // initialized.
- if (bufferDelta != null) {
- initBufferDelta(bufferStackPos + 1);
- }
- super.pushContext(buffer);
- }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#pushContext(char[],
- * java.lang.Object)
- */
- protected void pushContext(char[] buffer, Object data) {
- initBufferDelta(bufferStackPos + 1);
-
- if (data instanceof InclusionData) {
-
- InclusionData inclusionData = ((InclusionData) data);
- if (log.isTracing()) {
- StringBuffer b = new StringBuffer("Entering inclusion "); //$NON-NLS-1$
- b.append(((InclusionData) data).reader.filename);
- log.traceLog(b.toString());
- }
- if( ! isCircularInclusion( (InclusionData) data ))
- {
- DOMInclusion inc = ((DOMInclusion) inclusionData.inclusion);
- locationMap.startInclusion(((InclusionData) data).reader, inc.o, getGlobalOffset(getCurrentOffset())+1,
- inc.nameOffset, inc.nameEndoffset, inc.name, inc.systemInclude);
- bufferDelta[bufferStackPos + 1] = 0;
- includedFiles.put(inc.pt);
- }
- }
-
- else if (data instanceof MacroData) {
- MacroData d = (MacroData) data;
- if (d.macro instanceof FunctionStyleMacro && fsmCount == 0) {
- FunctionMacroData fd = (FunctionMacroData)d;
- FunctionStyleMacro fsm = (FunctionStyleMacro) d.macro;
- char[][] actualArgs= (char[][]) fd.getActualArgs().valueArray(CHAR_ARRAY_CLASS);
- locationMap.startFunctionStyleExpansion(fsm.attachment,
- fsm.arglist, getGlobalOffset(d.getStartOffset()),
- getGlobalOffset(d.getStartOffset() + d.getLength()), actualArgs);
- bufferDelta[bufferStackPos + 1] = 0;
- } else if (d.macro instanceof ObjectStyleMacro && fsmCount == 0) {
- ObjectStyleMacro osm = (ObjectStyleMacro) d.macro;
- int startOffset= getGlobalOffset(d.getStartOffset());
- int endOffset= startOffset+d.getLength();
- locationMap.startObjectStyleMacroExpansion(osm.attachment,
- startOffset, endOffset);
- bufferDelta[bufferStackPos + 1] = 0;
- }
- }
- else if( data instanceof CodeReader && !macroFilesInitialized )
- {
- int resolved = getGlobalOffset(0, 0);
- CodeReader codeReader = (CodeReader) data;
- locationMap.startInclusion( codeReader, resolved, resolved, resolved, resolved, CharArrayUtils.EMPTY, true);
- }
-
- super.pushContext(buffer, data);
- }
-
- private void initBufferDelta(int size) {
- if (size >= bufferDelta.length) {
- size = Math.max(bufferDelta.length * 2, size);
- int[] oldBufferDelta = bufferDelta;
- bufferDelta = new int[size];
- System.arraycopy(oldBufferDelta, 0, bufferDelta, 0,
- oldBufferDelta.length);
- }
- }
-
- /*
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContextForFunctionMacroName(org.eclipse.cdt.core.parser.IMacro)
- */
- protected void popContextForFunctionMacroName(IMacro macro) {
- // fix the delta before popping
- bufferDelta[bufferStackPos] -= macro.getName().length;
- popContext();
- }
-
- protected int fsmCount = 0;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#popContext()
- */
- protected Object popContext() {
- Object result = super.popContext();
- int bufferEndOffset = Math.min(bufferPos[bufferStackPos+1] + 1, bufferLimit[bufferStackPos+1]);
-
- if (result instanceof CodeReader) {
- CodeReader codeReader = (CodeReader) result;
- if( isInitialized ) {
- locationMap.endTranslationUnit(bufferDelta[0] + codeReader.buffer.length);
- }
- else {
- // handling of macro-file
- bufferDelta[0] += codeReader.buffer.length;
- locationMap.endInclusion(codeReader, getGlobalOffset(0,0));
- }
-
- }
- else if (result instanceof InclusionData) {
- CodeReader codeReader = ((InclusionData) result).reader;
- if (log.isTracing()) {
- StringBuffer buffer = new StringBuffer("Exiting inclusion "); //$NON-NLS-1$
- buffer.append(codeReader.filename);
- log.traceLog(buffer.toString());
- }
-
- int endOffset = getGlobalOffset(bufferStackPos+1, bufferEndOffset);
- locationMap.endInclusion(codeReader, endOffset);
- bufferDelta[bufferStackPos] += bufferDelta[bufferStackPos + 1] + bufferEndOffset;
- }
- else if (result instanceof MacroData) {
- int endOffset = getGlobalOffset(bufferStackPos + 1, bufferEndOffset);
- MacroData data = (MacroData) result;
- if (data.macro instanceof FunctionStyleMacro && fsmCount == 0) {
- locationMap.endFunctionStyleExpansion(((FunctionStyleMacro)data.macro).attachment, endOffset);
- bufferDelta[bufferStackPos]+= bufferDelta[bufferStackPos + 1] + bufferEndOffset;
- }
- else if (data.macro instanceof ObjectStyleMacro && fsmCount == 0) {
- locationMap.endObjectStyleMacroExpansion(((ObjectStyleMacro)data.macro).attachment, endOffset);
- bufferDelta[bufferStackPos]+= bufferDelta[bufferStackPos + 1] + bufferEndOffset;
- }
- }
- return result;
- }
-
- protected IToken newToken(int signal) {
- return new _BasicToken(signal,
- getGlobalOffset(bufferPos[bufferStackPos] + 1));
- }
-
- protected IToken newToken(int signal, char[] buffer) {
- IToken i = new _ImagedToken(signal, buffer,
- getGlobalOffset(bufferPos[bufferStackPos] + 1));
- if (buffer != null && buffer.length == 0 && signal != IToken.tSTRING
- && signal != IToken.tLSTRING)
- bufferPos[bufferStackPos] += 1; // TODO - remove this hack at some
- // point
-
- return i;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#quickParsePushPopInclusion(java.lang.Object)
- */
- protected void quickParsePushPopInclusion(Object inclusion) {
- // do nothing
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#handleProblem(int,
- * int, char[])
- */
- protected void handleProblem(int id, int offset, char[] arg) {
- IASTProblem problem = new ScannerASTProblem(id, arg, true, false);
- int o = getGlobalOffset(offset);
- ((ScannerASTProblem) problem).setOffsetAndLength(o,
- getGlobalOffset(getCurrentOffset() + 1) - o);
- locationMap.encounterProblem(problem);
- }
-
- /**
- * works only if bufferOffset is past the last context inserted in the current one.
- */
- private int getGlobalOffset(int bufferOffset) {
- return getGlobalOffset(bufferStackPos, bufferOffset);
- }
-
- private int getGlobalOffset(int stackPos, int offset) {
- if (stackPos < 0)
- return offset;
- offset+= bufferDelta[stackPos];
- for (int i = stackPos - 1; i >= 0; --i) {
- offset+= Math.min(bufferPos[i]+1, bufferLimit[i]) + bufferDelta[i];
- }
- return offset;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#postConstructorSetup(org.eclipse.cdt.core.parser.CodeReader,
- * org.eclipse.cdt.core.parser.IScannerInfo)
- */
- protected void postConstructorSetup(CodeReader reader, IScannerInfo info) {
- super.postConstructorSetup(reader, info);
- locationMap.startTranslationUnit(getMainReader());
- registerMacros();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIfdef(int,
- * int, boolean, boolean)
- */
- protected void processIfdef(int startPos, int endPos, boolean positive,
- boolean taken) {
- final char[] condition= extractPreprocessorCondition(bufferStack[bufferStackPos], startPos, endPos);
- if (positive){
- locationMap.encounterPoundIfdef(getGlobalOffset(startPos),
- getGlobalOffset(endPos), taken, condition);
- }
- else{
- locationMap.encounterPoundIfndef(getGlobalOffset(startPos),
- getGlobalOffset(endPos), taken, condition);
- }
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processIf(int,
- * int, boolean)
- */
- protected void processIf(int startPos, int endPos, boolean taken) {
- final char[] condition= extractPreprocessorCondition(bufferStack[bufferStackPos], startPos, endPos);
- locationMap.encounterPoundIf(getGlobalOffset(startPos),
- getGlobalOffset(endPos), taken, condition);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElsif(int,
- * int, boolean)
- */
- protected void processElsif(int startPos, int endPos, boolean taken) {
- final char[] condition= extractPreprocessorCondition(bufferStack[bufferStackPos], startPos, endPos);
- locationMap.encounterPoundElif(getGlobalOffset(startPos),
- getGlobalOffset(endPos), taken, condition);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processElse(int,
- * int, boolean)
- */
- protected void processElse(int startPos, int endPos, boolean taken) {
- locationMap.encounterPoundElse(getGlobalOffset(startPos),
- getGlobalOffset(endPos), taken);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processUndef(int,
- * int)
- */
- protected void processUndef(int pos, int endPos, char[] symbol,
- int namePos, Object definition) {
- final IScannerPreprocessorLog.IMacroDefinition macroDefinition = (definition instanceof ObjectStyleMacro) ? ((ObjectStyleMacro) definition).attachment
- : null;
- locationMap.encounterPoundUndef(getGlobalOffset(pos),
- getGlobalOffset(endPos), symbol, namePos, macroDefinition);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processError(int,
- * int)
- */
- protected void processError(int startPos, int endPos) {
- final char[] msg= extractPreprocessorCondition(bufferStack[bufferStackPos], startPos, endPos);
- locationMap.encounterPoundError(getGlobalOffset(startPos),
- getGlobalOffset(endPos), msg);
- }
-
- /*
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processWarning(int, int)
- */
- protected void processWarning(int startPos, int endPos) {
- final char[] msg= extractPreprocessorCondition(bufferStack[bufferStackPos], startPos, endPos);
- locationMap.encounterPoundWarning(getGlobalOffset(startPos),
- getGlobalOffset(endPos), msg);
- }
-
- private char[] extractPreprocessorCondition(final char[] buffer, int from, int to) {
- if (buffer[from] == '#') {
- from= skipWhiteSpace(buffer, from+1, to);
- from= skipNonWhiteSpace(buffer, from, to);
- from= skipWhiteSpace(buffer, from, to);
- to= reverseSkipWhiteSpace(buffer, to-1, from-1)+1;
- return CharArrayUtils.extract(buffer, from, to-from);
- }
- return CharArrayUtils.EMPTY;
- }
-
-
- private int skipWhiteSpace(char[] buffer, int from, int to) {
- while (from < to) {
- char c= buffer[from];
- switch(c) {
- case ' ': case '\r': case '\n': case '\t':
- break;
- default:
- return from;
- }
- from++;
- }
- return from;
- }
-
- private int skipNonWhiteSpace(char[] buffer, int from, int to) {
- while (from < to) {
- char c= buffer[from];
- switch(c) {
- case ' ': case '\r': case '\n': case '\t':
- return from;
- }
- from++;
- }
- return from;
- }
-
- private int reverseSkipWhiteSpace(char[] buffer, int from, int to) {
- while (from > to) {
- char c= buffer[from];
- switch(c) {
- case ' ': case '\r': case '\n': case '\t':
- break;
- default:
- return from;
- }
- from--;
- }
- return from;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processEndif(int,
- * int)
- */
- protected void processEndif(int startPos, int endPos) {
- locationMap.encounterPoundEndIf(getGlobalOffset(startPos), getGlobalOffset(endPos));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner#processPragma(int,
- * int)
- */
- protected void processPragma(int startPos, int endPos) {
- final char[] msg= extractPreprocessorCondition(bufferStack[bufferStackPos], startPos, endPos);
- locationMap.encounterPoundPragma(getGlobalOffset(startPos), getGlobalOffset(endPos), msg);
- }
-
- protected void beforeReplaceAllMacros() {
- ++fsmCount;
- }
-
- protected void afterReplaceAllMacros() {
- --fsmCount;
- }
-
- protected CodeReader createReader(String path, String fileName){
- String finalPath = ScannerUtility.createReconciledPath(path, fileName);
- CodeReader reader = createReaderDuple(finalPath);
- return reader;
- }
-
- private static class _BasicToken implements IToken, ITokenDuple {
-
- public _BasicToken( int type, int endOffset )
- {
- setType( type );
- setOffsetByLength( endOffset );
- }
-
- public String toString() {
- return getImage();
- }
-
- public int getType() { return type; }
-
- public void setType(int i) {
- type = i;
- }
-
- public int getLineNumber() {
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getFilename()
- */
- public char[] getFilename() {
- return EMPTY_CHAR_ARRAY;
- }
-
- public int getEndOffset() { return getOffset() + getLength(); }
-
- private int type;
- private IToken next = null;
- private int offset;
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object other) {
- if( other == null ) return false;
- if( !( other instanceof IToken ) )
- return false;
- if( ((IToken)other).getType() != getType() )
- return false;
- if( !CharArrayUtils.equals( ((IToken)other).getCharImage(), getCharImage() ) )
- return false;
- if( getOffset() != ((IToken)other).getOffset() )
- return false;
- if( getEndOffset() != ((IToken)other).getEndOffset() )
- return false;
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#isKeyword()
- */
- public boolean canBeAPrefix() {
- switch( getType() )
- {
- case tIDENTIFIER:
- case tCOMPL:
- return true;
- default:
- if( getType() >= t_and && getType() <= t_xor_eq ) return true;
- if( getType() >= t__Bool && getType() <= t_restrict ) return true;
- }
- return false;
- }
-
- public boolean looksLikeExpression()
- {
- switch( getType() )
- {
- case IToken.tINTEGER:
- case IToken.t_false:
- case IToken.t_true:
- case IToken.tSTRING:
- case IToken.tLSTRING:
- case IToken.tFLOATINGPT:
- case IToken.tCHAR:
- case IToken.tAMPER:
- case IToken.tDOT:
- case IToken.tLPAREN:
- case IToken.tMINUS:
- case IToken.tSTAR:
- case IToken.tPLUS:
- case IToken.tNOT:
- case IToken.tCOMPL:
- return true;
- default:
- break;
- }
- return false;
- }
-
- public boolean isOperator()
- {
- switch( getType() )
- {
- case IToken.t_new:
- case IToken.t_delete:
- case IToken.tPLUS:
- case IToken.tMINUS:
- case IToken.tSTAR:
- case IToken.tDIV:
- case IToken.tXOR:
- case IToken.tMOD:
- case IToken.tAMPER:
- case IToken.tBITOR:
- case IToken.tCOMPL:
- case IToken.tNOT:
- case IToken.tASSIGN:
- case IToken.tLT:
- case IToken.tGT:
- case IToken.tPLUSASSIGN:
- case IToken.tMINUSASSIGN:
- case IToken.tSTARASSIGN:
- case IToken.tDIVASSIGN:
- case IToken.tMODASSIGN:
- case IToken.tBITORASSIGN:
- case IToken.tAMPERASSIGN:
- case IToken.tXORASSIGN:
- case IToken.tSHIFTL:
- case IToken.tSHIFTR:
- case IToken.tSHIFTLASSIGN:
- case IToken.tSHIFTRASSIGN:
- case IToken.tEQUAL:
- case IToken.tNOTEQUAL:
- case IToken.tLTEQUAL:
- case IToken.tGTEQUAL:
- case IToken.tAND:
- case IToken.tOR:
- case IToken.tINCR:
- case IToken.tDECR:
- case IToken.tCOMMA:
- case IToken.tARROW:
- case IToken.tARROWSTAR:
- return true;
- default:
- return false;
- }
- }
-
- public boolean isPointer()
- {
- return (getType() == IToken.tAMPER || getType() == IToken.tSTAR);
- }
-
-
-
- public final IToken getNext() { return next; }
- public void setNext(IToken t) {
- // guard against endless loop
- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=180172
- assert t != this : "Token recursion"; //$NON-NLS-1$
- if (t != this)
- next = t;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple)
- */
- public boolean contains(ITokenDuple duple) {
- return ( duple.getFirstToken() == duple.getLastToken() ) && ( duple.getFirstToken() == this );
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#extractNameFromTemplateId()
- */
- public char[] extractNameFromTemplateId(){
- return getCharImage();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#findLastTokenType(int)
- */
- public int findLastTokenType(int t) {
- if( getType() == t ) return 0;
- return -1;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getFirstToken()
- */
- public IToken getFirstToken() {
- return this;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getLastSegment()
- */
- public ITokenDuple getLastSegment() {
- return this;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getLastToken()
- */
- public IToken getLastToken() {
- return this;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getLeadingSegments()
- */
- public ITokenDuple getLeadingSegments() {
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentCount()
- */
- public int getSegmentCount() {
- return 1;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
- */
- public int getStartOffset() {
- return getOffset();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getSubrange(int, int)
- */
- public ITokenDuple getSubrange(int startIndex, int endIndex) {
- if( startIndex == 0 && endIndex == 0 ) return this;
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getTemplateIdArgLists()
- */
- public List[] getTemplateIdArgLists() {
- // TODO Auto-generated method stub
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getToken(int)
- */
- public IToken getToken(int index) {
- if( index == 0 ) return this;
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#isIdentifier()
- */
- public boolean isIdentifier() {
- return ( getType() == IToken.tIDENTIFIER );
- }
-
-
- private class SingleIterator implements Iterator
- {
- boolean hasNext = true;
- /* (non-Javadoc)
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return hasNext;
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#next()
- */
- public Object next() {
- hasNext = false;
- return _BasicToken.this;
- }
-
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#iterator()
- */
- public Iterator iterator() {
- return new SingleIterator();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#length()
- */
- public int length() {
- return 1;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#syntaxOfName()
- */
- public boolean syntaxOfName() {
- return ( getType() == IToken.tIDENTIFIER );
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#toQualifiedName()
- */
- public String[] toQualifiedName() {
- String [] qualifiedName = new String[1];
- qualifiedName[0] = getImage();
- return qualifiedName;
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentIterator()
- */
- public ITokenDuple[] getSegments() {
- ITokenDuple [] r = new ITokenDuple[0];
- r[0] = this;
- return r;
- }
-
-
- // All the tokens generated by the macro expansion
- // will have dimensions (offset and length) equal to the expanding symbol.
- public int getOffset() {
- return offset;
- }
-
- public int getLength() {
- return getCharImage().length;
- }
-
- protected void setOffsetByLength( int endOffset )
- {
- this.offset = endOffset - getLength();
- }
-
- public String getImage() {
- switch ( getType() ) {
- case IToken.tCOLONCOLON :
- return "::" ; //$NON-NLS-1$
- case IToken.tCOLON :
- return ":" ; //$NON-NLS-1$
- case IToken.tSEMI :
- return ";" ; //$NON-NLS-1$
- case IToken.tCOMMA :
- return "," ; //$NON-NLS-1$
- case IToken.tQUESTION :
- return "?" ; //$NON-NLS-1$
- case IToken.tLPAREN :
- return "(" ; //$NON-NLS-1$
- case IToken.tRPAREN :
- return ")" ; //$NON-NLS-1$
- case IToken.tLBRACKET :
- return "[" ; //$NON-NLS-1$
- case IToken.tRBRACKET :
- return "]" ; //$NON-NLS-1$
- case IToken.tLBRACE :
- return "{" ; //$NON-NLS-1$
- case IToken.tRBRACE :
- return "}"; //$NON-NLS-1$
- case IToken.tPLUSASSIGN :
- return "+="; //$NON-NLS-1$
- case IToken.tINCR :
- return "++" ; //$NON-NLS-1$
- case IToken.tPLUS :
- return "+"; //$NON-NLS-1$
- case IToken.tMINUSASSIGN :
- return "-=" ; //$NON-NLS-1$
- case IToken.tDECR :
- return "--" ; //$NON-NLS-1$
- case IToken.tARROWSTAR :
- return "->*" ; //$NON-NLS-1$
- case IToken.tARROW :
- return "->" ; //$NON-NLS-1$
- case IToken.tMINUS :
- return "-" ; //$NON-NLS-1$
- case IToken.tSTARASSIGN :
- return "*=" ; //$NON-NLS-1$
- case IToken.tSTAR :
- return "*" ; //$NON-NLS-1$
- case IToken.tMODASSIGN :
- return "%=" ; //$NON-NLS-1$
- case IToken.tMOD :
- return "%" ; //$NON-NLS-1$
- case IToken.tXORASSIGN :
- return "^=" ; //$NON-NLS-1$
- case IToken.tXOR :
- return "^" ; //$NON-NLS-1$
- case IToken.tAMPERASSIGN :
- return "&=" ; //$NON-NLS-1$
- case IToken.tAND :
- return "&&" ; //$NON-NLS-1$
- case IToken.tAMPER :
- return "&" ; //$NON-NLS-1$
- case IToken.tBITORASSIGN :
- return "|=" ; //$NON-NLS-1$
- case IToken.tOR :
- return "||" ; //$NON-NLS-1$
- case IToken.tBITOR :
- return "|" ; //$NON-NLS-1$
- case IToken.tCOMPL :
- return "~" ; //$NON-NLS-1$
- case IToken.tNOTEQUAL :
- return "!=" ; //$NON-NLS-1$
- case IToken.tNOT :
- return "!" ; //$NON-NLS-1$
- case IToken.tEQUAL :
- return "==" ; //$NON-NLS-1$
- case IToken.tASSIGN :
- return "=" ; //$NON-NLS-1$
- case IToken.tSHIFTL :
- return "<<" ; //$NON-NLS-1$
- case IToken.tLTEQUAL :
- return "<=" ; //$NON-NLS-1$
- case IToken.tLT :
- return "<"; //$NON-NLS-1$
- case IToken.tSHIFTRASSIGN :
- return ">>=" ; //$NON-NLS-1$
- case IToken.tSHIFTR :
- return ">>" ; //$NON-NLS-1$
- case IToken.tGTEQUAL :
- return ">=" ; //$NON-NLS-1$
- case IToken.tGT :
- return ">" ; //$NON-NLS-1$
- case IToken.tSHIFTLASSIGN :
- return "<<=" ; //$NON-NLS-1$
- case IToken.tELLIPSIS :
- return "..." ; //$NON-NLS-1$
- case IToken.tDOTSTAR :
- return ".*" ; //$NON-NLS-1$
- case IToken.tDOT :
- return "." ; //$NON-NLS-1$
- case IToken.tDIVASSIGN :
- return "/=" ; //$NON-NLS-1$
- case IToken.tDIV :
- return "/" ; //$NON-NLS-1$
- case IToken.t_and :
- return Keywords.AND;
- case IToken.t_and_eq :
- return Keywords.AND_EQ ;
- case IToken.t_asm :
- return Keywords.ASM ;
- case IToken.t_auto :
- return Keywords.AUTO ;
- case IToken.t_bitand :
- return Keywords.BITAND ;
- case IToken.t_bitor :
- return Keywords.BITOR ;
- case IToken.t_bool :
- return Keywords.BOOL ;
- case IToken.t_break :
- return Keywords.BREAK ;
- case IToken.t_case :
- return Keywords.CASE ;
- case IToken.t_catch :
- return Keywords.CATCH ;
- case IToken.t_char :
- return Keywords.CHAR ;
- case IToken.t_class :
- return Keywords.CLASS ;
- case IToken.t_compl :
- return Keywords.COMPL ;
- case IToken.t_const :
- return Keywords.CONST ;
- case IToken.t_const_cast :
- return Keywords.CONST_CAST ;
- case IToken.t_continue :
- return Keywords.CONTINUE ;
- case IToken.t_default :
- return Keywords.DEFAULT ;
- case IToken.t_delete :
- return Keywords.DELETE ;
- case IToken.t_do :
- return Keywords.DO;
- case IToken.t_double :
- return Keywords.DOUBLE ;
- case IToken.t_dynamic_cast :
- return Keywords.DYNAMIC_CAST ;
- case IToken.t_else :
- return Keywords.ELSE;
- case IToken.t_enum :
- return Keywords.ENUM ;
- case IToken.t_explicit :
- return Keywords.EXPLICIT ;
- case IToken.t_export :
- return Keywords.EXPORT ;
- case IToken.t_extern :
- return Keywords.EXTERN;
- case IToken.t_false :
- return Keywords.FALSE;
- case IToken.t_float :
- return Keywords.FLOAT;
- case IToken.t_for :
- return Keywords.FOR;
- case IToken.t_friend :
- return Keywords.FRIEND;
- case IToken.t_goto :
- return Keywords.GOTO;
- case IToken.t_if :
- return Keywords.IF ;
- case IToken.t_inline :
- return Keywords.INLINE ;
- case IToken.t_int :
- return Keywords.INT ;
- case IToken.t_long :
- return Keywords.LONG ;
- case IToken.t_mutable :
- return Keywords.MUTABLE ;
- case IToken.t_namespace :
- return Keywords.NAMESPACE ;
- case IToken.t_new :
- return Keywords.NEW ;
- case IToken.t_not :
- return Keywords.NOT ;
- case IToken.t_not_eq :
- return Keywords.NOT_EQ;
- case IToken.t_operator :
- return Keywords.OPERATOR ;
- case IToken.t_or :
- return Keywords.OR ;
- case IToken.t_or_eq :
- return Keywords.OR_EQ;
- case IToken.t_private :
- return Keywords.PRIVATE ;
- case IToken.t_protected :
- return Keywords.PROTECTED ;
- case IToken.t_public :
- return Keywords.PUBLIC ;
- case IToken.t_register :
- return Keywords.REGISTER ;
- case IToken.t_reinterpret_cast :
- return Keywords.REINTERPRET_CAST ;
- case IToken.t_return :
- return Keywords.RETURN ;
- case IToken.t_short :
- return Keywords.SHORT ;
- case IToken.t_sizeof :
- return Keywords.SIZEOF ;
- case IToken.t_static :
- return Keywords.STATIC ;
- case IToken.t_static_cast :
- return Keywords.STATIC_CAST ;
- case IToken.t_signed :
- return Keywords.SIGNED ;
- case IToken.t_struct :
- return Keywords.STRUCT ;
- case IToken.t_switch :
- return Keywords.SWITCH ;
- case IToken.t_template :
- return Keywords.TEMPLATE ;
- case IToken.t_this :
- return Keywords.THIS ;
- case IToken.t_throw :
- return Keywords.THROW ;
- case IToken.t_true :
- return Keywords.TRUE ;
- case IToken.t_try :
- return Keywords.TRY ;
- case IToken.t_typedef :
- return Keywords.TYPEDEF ;
- case IToken.t_typeid :
- return Keywords.TYPEID ;
- case IToken.t_typename :
- return Keywords.TYPENAME ;
- case IToken.t_union :
- return Keywords.UNION ;
- case IToken.t_unsigned :
- return Keywords.UNSIGNED ;
- case IToken.t_using :
- return Keywords.USING ;
- case IToken.t_virtual :
- return Keywords.VIRTUAL ;
- case IToken.t_void :
- return Keywords.VOID ;
- case IToken.t_volatile :
- return Keywords.VOLATILE;
- case IToken.t_wchar_t :
- return Keywords.WCHAR_T ;
- case IToken.t_while :
- return Keywords.WHILE ;
- case IToken.t_xor :
- return Keywords.XOR ;
- case IToken.t_xor_eq :
- return Keywords.XOR_EQ ;
- case IToken.t__Bool :
- return Keywords._BOOL ;
- case IToken.t__Complex :
- return Keywords._COMPLEX ;
- case IToken.t__Imaginary :
- return Keywords._IMAGINARY ;
- case IToken.t_restrict :
- return Keywords.RESTRICT ;
- case IToken.tPOUND:
- return "#"; //$NON-NLS-1$
- case IToken.tPOUNDPOUND:
- return "##"; //$NON-NLS-1$
- case IToken.tEOC:
- return "EOC"; //$NON-NLS-1$
- default :
- // we should never get here!
- // assert false : getType();
- return ""; //$NON-NLS-1$
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage()
- */
- public void setImage( String i ) {
- // do nothing
- }
-
- public char[] getCharImage() {
- return DOMScanner.getCharImage( getType() );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage(char[])
- */
- public void setImage(char[] i) {
- // do nothing
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#toCharArray()
- */
- public char[] toCharArray() {
- return getCharImage();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#isConversion()
- */
- public boolean isConversion() {
- return false;
- }
-
-
- }
-
- private static class _ImagedToken extends _BasicToken {
-
- private char [] image = null;
-
- public _ImagedToken( int t, char[] i, int endOffset ) {
- super( t, 0 );
- setImage(i);
- setOffsetByLength( endOffset );
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.token.AbstractToken#getImage()
- */
- public final String getImage() {
- if( image == null ) return null;
- return new String( image );
- }
-
- public final char[] getCharImage() {
- return image;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage(java.lang.String)
- */
- public void setImage(String i) {
- image = i.toCharArray();
- }
-
- public void setImage( char [] image )
- {
- this.image = image;
- }
-
-
- public int getLength() {
- if( getCharImage() == null )
- return 0;
- int s_length = getCharImage().length;
- switch( getType() )
- {
- case IToken.tSTRING:
- return s_length + 2;
- case IToken.tLSTRING:
- return s_length + 3;
- default:
- return s_length;
- }
- }
- }
-
-
- static char[] getCharImage( int type ){
- switch ( type ) {
- case IToken.tCOLONCOLON : return Keywords.cpCOLONCOLON;
- case IToken.tCOLON : return Keywords.cpCOLON;
- case IToken.tSEMI : return Keywords.cpSEMI;
- case IToken.tCOMMA : return Keywords.cpCOMMA;
- case IToken.tQUESTION : return Keywords.cpQUESTION;
- case IToken.tLPAREN : return Keywords.cpLPAREN;
- case IToken.tRPAREN : return Keywords.cpRPAREN;
- case IToken.tLBRACKET : return Keywords.cpLBRACKET;
- case IToken.tRBRACKET : return Keywords.cpRBRACKET;
- case IToken.tLBRACE : return Keywords.cpLBRACE;
- case IToken.tRBRACE : return Keywords.cpRBRACE;
- case IToken.tPLUSASSIGN : return Keywords.cpPLUSASSIGN;
- case IToken.tINCR : return Keywords.cpINCR;
- case IToken.tPLUS : return Keywords.cpPLUS;
- case IToken.tMINUSASSIGN : return Keywords.cpMINUSASSIGN;
- case IToken.tDECR : return Keywords.cpDECR;
- case IToken.tARROWSTAR : return Keywords.cpARROWSTAR;
- case IToken.tARROW : return Keywords.cpARROW;
- case IToken.tMINUS : return Keywords.cpMINUS;
- case IToken.tSTARASSIGN : return Keywords.cpSTARASSIGN;
- case IToken.tSTAR : return Keywords.cpSTAR;
- case IToken.tMODASSIGN : return Keywords.cpMODASSIGN;
- case IToken.tMOD : return Keywords.cpMOD;
- case IToken.tXORASSIGN : return Keywords.cpXORASSIGN;
- case IToken.tXOR : return Keywords.cpXOR;
- case IToken.tAMPERASSIGN : return Keywords.cpAMPERASSIGN;
- case IToken.tAND : return Keywords.cpAND;
- case IToken.tAMPER : return Keywords.cpAMPER;
- case IToken.tBITORASSIGN : return Keywords.cpBITORASSIGN;
- case IToken.tOR : return Keywords.cpOR;
- case IToken.tBITOR : return Keywords.cpBITOR;
- case IToken.tCOMPL : return Keywords.cpCOMPL;
- case IToken.tNOTEQUAL : return Keywords.cpNOTEQUAL;
- case IToken.tNOT : return Keywords.cpNOT;
- case IToken.tEQUAL : return Keywords.cpEQUAL;
- case IToken.tASSIGN : return Keywords.cpASSIGN;
- case IToken.tSHIFTL : return Keywords.cpSHIFTL;
- case IToken.tLTEQUAL : return Keywords.cpLTEQUAL;
- case IToken.tLT : return Keywords.cpLT;
- case IToken.tSHIFTRASSIGN : return Keywords.cpSHIFTRASSIGN;
- case IToken.tSHIFTR : return Keywords.cpSHIFTR;
- case IToken.tGTEQUAL : return Keywords.cpGTEQUAL;
- case IToken.tGT : return Keywords.cpGT;
- case IToken.tSHIFTLASSIGN : return Keywords.cpSHIFTLASSIGN;
- case IToken.tELLIPSIS : return Keywords.cpELLIPSIS;
- case IToken.tDOTSTAR : return Keywords.cpDOTSTAR;
- case IToken.tDOT : return Keywords.cpDOT;
- case IToken.tDIVASSIGN : return Keywords.cpDIVASSIGN;
- case IToken.tDIV : return Keywords.cpDIV;
- case IToken.t_and : return Keywords.cAND;
- case IToken.t_and_eq : return Keywords.cAND_EQ ;
- case IToken.t_asm : return Keywords.cASM ;
- case IToken.t_auto : return Keywords.cAUTO ;
- case IToken.t_bitand : return Keywords.cBITAND ;
- case IToken.t_bitor : return Keywords.cBITOR ;
- case IToken.t_bool : return Keywords.cBOOL ;
- case IToken.t_break : return Keywords.cBREAK ;
- case IToken.t_case : return Keywords.cCASE ;
- case IToken.t_catch : return Keywords.cCATCH ;
- case IToken.t_char : return Keywords.cCHAR ;
- case IToken.t_class : return Keywords.cCLASS ;
- case IToken.t_compl : return Keywords.cCOMPL ;
- case IToken.t_const : return Keywords.cCONST ;
- case IToken.t_const_cast : return Keywords.cCONST_CAST ;
- case IToken.t_continue : return Keywords.cCONTINUE ;
- case IToken.t_default : return Keywords.cDEFAULT ;
- case IToken.t_delete : return Keywords.cDELETE ;
- case IToken.t_do : return Keywords.cDO;
- case IToken.t_double : return Keywords.cDOUBLE ;
- case IToken.t_dynamic_cast: return Keywords.cDYNAMIC_CAST ;
- case IToken.t_else : return Keywords.cELSE;
- case IToken.t_enum : return Keywords.cENUM ;
- case IToken.t_explicit : return Keywords.cEXPLICIT ;
- case IToken.t_export : return Keywords.cEXPORT ;
- case IToken.t_extern : return Keywords.cEXTERN;
- case IToken.t_false : return Keywords.cFALSE;
- case IToken.t_float : return Keywords.cFLOAT;
- case IToken.t_for : return Keywords.cFOR;
- case IToken.t_friend : return Keywords.cFRIEND;
- case IToken.t_goto : return Keywords.cGOTO;
- case IToken.t_if : return Keywords.cIF ;
- case IToken.t_inline : return Keywords.cINLINE ;
- case IToken.t_int : return Keywords.cINT ;
- case IToken.t_long : return Keywords.cLONG ;
- case IToken.t_mutable : return Keywords.cMUTABLE ;
- case IToken.t_namespace : return Keywords.cNAMESPACE ;
- case IToken.t_new : return Keywords.cNEW ;
- case IToken.t_not : return Keywords.cNOT ;
- case IToken.t_not_eq : return Keywords.cNOT_EQ;
- case IToken.t_operator : return Keywords.cOPERATOR ;
- case IToken.t_or : return Keywords.cOR ;
- case IToken.t_or_eq : return Keywords.cOR_EQ;
- case IToken.t_private : return Keywords.cPRIVATE ;
- case IToken.t_protected : return Keywords.cPROTECTED ;
- case IToken.t_public : return Keywords.cPUBLIC ;
- case IToken.t_register : return Keywords.cREGISTER ;
- case IToken.t_reinterpret_cast : return Keywords.cREINTERPRET_CAST ;
- case IToken.t_return : return Keywords.cRETURN ;
- case IToken.t_short : return Keywords.cSHORT ;
- case IToken.t_sizeof : return Keywords.cSIZEOF ;
- case IToken.t_static : return Keywords.cSTATIC ;
- case IToken.t_static_cast : return Keywords.cSTATIC_CAST ;
- case IToken.t_signed : return Keywords.cSIGNED ;
- case IToken.t_struct : return Keywords.cSTRUCT ;
- case IToken.t_switch : return Keywords.cSWITCH ;
- case IToken.t_template : return Keywords.cTEMPLATE ;
- case IToken.t_this : return Keywords.cTHIS ;
- case IToken.t_throw : return Keywords.cTHROW ;
- case IToken.t_true : return Keywords.cTRUE ;
- case IToken.t_try : return Keywords.cTRY ;
- case IToken.t_typedef : return Keywords.cTYPEDEF ;
- case IToken.t_typeid : return Keywords.cTYPEID ;
- case IToken.t_typename : return Keywords.cTYPENAME ;
- case IToken.t_union : return Keywords.cUNION ;
- case IToken.t_unsigned : return Keywords.cUNSIGNED ;
- case IToken.t_using : return Keywords.cUSING ;
- case IToken.t_virtual : return Keywords.cVIRTUAL ;
- case IToken.t_void : return Keywords.cVOID ;
- case IToken.t_volatile : return Keywords.cVOLATILE;
- case IToken.t_wchar_t : return Keywords.cWCHAR_T ;
- case IToken.t_while : return Keywords.cWHILE ;
- case IToken.t_xor : return Keywords.cXOR ;
- case IToken.t_xor_eq : return Keywords.cXOR_EQ ;
- case IToken.t__Bool : return Keywords.c_BOOL ;
- case IToken.t__Complex : return Keywords.c_COMPLEX ;
- case IToken.t__Imaginary : return Keywords.c_IMAGINARY ;
- case IToken.t_restrict : return Keywords.cRESTRICT ;
- case IToken.tPOUND: return Keywords.cpPOUND;
- case IToken.tPOUNDPOUND: return Keywords.cpPOUNDPOUND;
-
- default :
- // we should never get here!
- // assert false : getType();
- return "".toCharArray(); //$NON-NLS-1$
- }
- //return getImage().toCharArray(); //TODO - fix me!
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java
deleted file mode 100644
index 0cdaaca9312..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DependencyTree.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
-
-public class DependencyTree implements IASTTranslationUnit.IDependencyTree, IDependencyNodeHost {
-
- private final String tu_path;
-
- public DependencyTree( String path )
- {
- tu_path = path;
- }
-
- public String getTranslationUnitPath() {
- return tu_path;
- }
-
- private IASTInclusionNode [] incs = new IASTInclusionNode[2];
- private int incsPos=-1;
-
- public IASTInclusionNode[] getInclusions() {
- incs = (IASTInclusionNode[]) ArrayUtil.removeNullsAfter( IASTInclusionNode.class, incs, incsPos );
- return incs;
- }
-
- public void addInclusionNode(IASTInclusionNode node) {
- if (node != null) {
- incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, ++incsPos, node );
- }
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicFunctionStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicFunctionStyleMacro.java
deleted file mode 100644
index 35751003282..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicFunctionStyleMacro.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-/*
- * Created on Oct 5, 2004
- */
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-
-/**
- * @author aniefer
- */
-abstract public class DynamicFunctionStyleMacro extends FunctionStyleMacro {
-
- public DynamicFunctionStyleMacro( char[] name, char[][] arglist ) {
- super( name, "".toCharArray(), arglist ); //$NON-NLS-1$
- }
-
- public abstract char [] execute( CharArrayObjectMap argmap );
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java
deleted file mode 100644
index a1fe1a8b283..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/DynamicStyleMacro.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Rational Software - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog.IMacroDefinition;
-
-/**
- * @author jcamelon
- *
- */
-public abstract class DynamicStyleMacro implements IMacro{
-
- public abstract char [] execute();
-
- public DynamicStyleMacro( char [] n )
- {
- name = n;
- }
- public final char [] name;
- public IMacroDefinition attachment;
-
- public char[] getSignature()
- {
- return name;
- }
- public char[] getName()
- {
- return name;
- }
- public char[] getExpansion() {
- return execute();
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java
deleted file mode 100644
index ae9f9ffa7e2..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java
+++ /dev/null
@@ -1,1076 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial implementation
- * Markus Schorn (Wind River Systems)
- * Bryan Wilkinson (QNX) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=151207
- * Anton Leherbauer (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.parser.IProblem;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.internal.core.parser.scanner2.BaseScanner.MacroData;
-
-public class ExpressionEvaluator {
- private static char[] EMPTY_CHAR_ARRAY = new char[0];
-
- // The context stack
- private static final int initSize = 8;
-
- private int bufferStackPos = -1;
-
- private char[][] bufferStack = new char[initSize][];
-
- private Object[] bufferData = new Object[initSize];
-
- private int[] bufferPos = new int[initSize];
-
- private int[] bufferLimit = new int[initSize];
-
- private ScannerProblemFactory problemFactory = null;
-
- private int lineNumber = 1;
-
- private char[] fileName = null;
-
- private int pos = 0;
-
- // The macros
- CharArrayObjectMap definitions;
-
- public ExpressionEvaluator() {
- super();
- }
-
- public ExpressionEvaluator(ScannerProblemFactory spf) {
- this.problemFactory = spf;
- }
-
- public long evaluate(char[] buffer, int p, int length,
- CharArrayObjectMap defs) {
- return evaluate(buffer, p, length, defs, 0, "".toCharArray()); //$NON-NLS-1$
- }
-
- public long evaluate(char[] buffer, int p, int length,
- CharArrayObjectMap defs, int ln, char[] fn) {
- this.lineNumber = ln;
- this.fileName = fn;
- bufferStack[++bufferStackPos] = buffer;
- bufferPos[bufferStackPos] = p - 1;
- bufferLimit[bufferStackPos] = p + length;
- this.definitions = defs;
- tokenType = 0;
-
- long r = 0;
- try {
- r = expression();
- } catch (ExpressionEvaluator.EvalException e) {
- }
-
- while (bufferStackPos >= 0)
- popContext();
-
- return r;
- }
-
- private static class EvalException extends Exception {
- private static final long serialVersionUID = 0;
- public EvalException(String msg) {
- super(msg);
- }
- }
-
- private long expression() throws EvalException {
- return conditionalExpression();
- }
-
- private long conditionalExpression() throws EvalException {
- long r1 = logicalOrExpression();
- if (LA() == tQUESTION) {
- consume();
- long r2 = expression();
- if (LA() == tCOLON)
- consume();
- else {
- handleProblem(IProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION,
- pos);
- throw new EvalException("bad conditional expression"); //$NON-NLS-1$
- }
- long r3 = conditionalExpression();
- return r1 != 0 ? r2 : r3;
- }
- return r1;
- }
-
- private long logicalOrExpression() throws EvalException {
- long r1 = logicalAndExpression();
- while (LA() == tOR) {
- consume();
- long r2 = logicalAndExpression();
- r1 = ((r1 != 0) || (r2 != 0)) ? 1 : 0;
- }
- return r1;
- }
-
- private long logicalAndExpression() throws EvalException {
- long r1 = inclusiveOrExpression();
- while (LA() == tAND) {
- consume();
- long r2 = inclusiveOrExpression();
- r1 = ((r1 != 0) && (r2 != 0)) ? 1 : 0;
- }
- return r1;
- }
-
- private long inclusiveOrExpression() throws EvalException {
- long r1 = exclusiveOrExpression();
- while (LA() == tBITOR) {
- consume();
- long r2 = exclusiveOrExpression();
- r1 = r1 | r2;
- }
- return r1;
- }
-
- private long exclusiveOrExpression() throws EvalException {
- long r1 = andExpression();
- while (LA() == tBITXOR) {
- consume();
- long r2 = andExpression();
- r1 = r1 ^ r2;
- }
- return r1;
- }
-
- private long andExpression() throws EvalException {
- long r1 = equalityExpression();
- while (LA() == tBITAND) {
- consume();
- long r2 = equalityExpression();
- r1 = r1 & r2;
- }
- return r1;
- }
-
- private long equalityExpression() throws EvalException {
- long r1 = relationalExpression();
- for (int t = LA(); t == tEQUAL || t == tNOTEQUAL; t = LA()) {
- consume();
- long r2 = relationalExpression();
- if (t == tEQUAL)
- r1 = (r1 == r2) ? 1 : 0;
- else
- // t == tNOTEQUAL
- r1 = (r1 != r2) ? 1 : 0;
- }
- return r1;
- }
-
- private long relationalExpression() throws EvalException {
- long r1 = shiftExpression();
- for (int t = LA(); t == tLT || t == tLTEQUAL || t == tGT
- || t == tGTEQUAL; t = LA()) {
- consume();
- long r2 = shiftExpression();
- switch (t) {
- case tLT:
- r1 = (r1 < r2) ? 1 : 0;
- break;
- case tLTEQUAL:
- r1 = (r1 <= r2) ? 1 : 0;
- break;
- case tGT:
- r1 = (r1 > r2) ? 1 : 0;
- break;
- case tGTEQUAL:
- r1 = (r1 >= r2) ? 1 : 0;
- break;
- }
- }
- return r1;
- }
-
- private long shiftExpression() throws EvalException {
- long r1 = additiveExpression();
- for (int t = LA(); t == tSHIFTL || t == tSHIFTR; t = LA()) {
- consume();
- long r2 = additiveExpression();
- if (t == tSHIFTL)
- r1 = r1 << r2;
- else
- // t == tSHIFTR
- r1 = r1 >> r2;
- }
- return r1;
- }
-
- private long additiveExpression() throws EvalException {
- long r1 = multiplicativeExpression();
- for (int t = LA(); t == tPLUS || t == tMINUS; t = LA()) {
- consume();
- long r2 = multiplicativeExpression();
- if (t == tPLUS)
- r1 = r1 + r2;
- else
- // t == tMINUS
- r1 = r1 - r2;
- }
- return r1;
- }
-
- private long multiplicativeExpression() throws EvalException {
- long r1 = unaryExpression();
- for (int t = LA(); t == tMULT || t == tDIV || t == tMOD; t = LA()) {
- int position = pos; // for IProblem /0 below, need position
- // before
- // consume()
- consume();
- long r2 = unaryExpression();
- if (t == tMULT)
- r1 = r1 * r2;
- else if (r2 != 0) {
- if (t == tDIV)
- r1 = r1 / r2;
- else
- r1 = r1 % r2; //tMOD
- } else {
- handleProblem(IProblem.SCANNER_DIVIDE_BY_ZERO, position);
- throw new EvalException("Divide by 0 encountered"); //$NON-NLS-1$
- }
- }
- return r1;
- }
-
- private long unaryExpression() throws EvalException {
- switch (LA()) {
- case tPLUS:
- consume();
- return unaryExpression();
- case tMINUS:
- consume();
- return -unaryExpression();
- case tNOT:
- consume();
- return unaryExpression() == 0 ? 1 : 0;
- case tCOMPL:
- consume();
- return ~unaryExpression();
- case tNUMBER:
- return consume();
- case t_defined:
- return handleDefined();
- case tLPAREN:
- consume();
- long r1 = expression();
- if (LA() == tRPAREN) {
- consume();
- return r1;
- }
- handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos);
- throw new EvalException("missing )"); //$NON-NLS-1$
- case tCHAR:
- return getChar();
- default:
- handleProblem(IProblem.SCANNER_EXPRESSION_SYNTAX_ERROR, pos);
- throw new EvalException("expression syntax error"); //$NON-NLS-1$
- }
- }
-
- private long handleDefined() throws EvalException {
- // We need to do some special handline to get the identifier without
- // it
- // being
- // expanded by macro expansion
- skipWhiteSpace();
-
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- if (++bufferPos[bufferStackPos] >= limit)
- return 0;
-
- // check first character
- char c = buffer[bufferPos[bufferStackPos]];
- boolean inParens = false;
- if (c == '(') {
- inParens = true;
- skipWhiteSpace();
- if (++bufferPos[bufferStackPos] >= limit)
- return 0;
- c = buffer[bufferPos[bufferStackPos]];
- }
-
- if (!((c >= 'A' && c <= 'Z') || c == '_' || (c >= 'a' && c <= 'z'))) {
- handleProblem(IProblem.SCANNER_ILLEGAL_IDENTIFIER, pos);
- throw new EvalException("illegal identifier in defined()"); //$NON-NLS-1$
- }
-
- // consume rest of identifier
- int idstart = bufferPos[bufferStackPos];
- int idlen = 1;
- while (++bufferPos[bufferStackPos] < limit) {
- c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'A' && c <= 'Z') || c == '_'
- || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) {
- ++idlen;
- continue;
- }
- break;
- }
- --bufferPos[bufferStackPos];
-
- // consume to the closing paren;
- if (inParens) {
- skipWhiteSpace();
- if (++bufferPos[bufferStackPos] <= limit
- && buffer[bufferPos[bufferStackPos]] != ')') {
- handleProblem(IProblem.SCANNER_MISSING_R_PAREN, pos);
- throw new EvalException("missing ) on defined"); //$NON-NLS-1$
- }
- }
-
- // Set up the lookahead to whatever comes next
- nextToken();
-
- return definitions.get(buffer, idstart, idlen) != null ? 1 : 0;
- }
-
- // Scanner part
- int tokenType = tNULL;
-
- long tokenValue;
-
- private int LA() throws EvalException {
- if (tokenType == tNULL)
- nextToken();
- return tokenType;
- }
-
- private long consume() throws EvalException {
- long value = tokenValue;
- if (tokenType != tEOF)
- nextToken();
- return value;
- }
-
- private long getChar() throws EvalException {
- long value = 0;
-
- // if getting a character then make sure it's in '' otherwise leave
- // it
- // as 0
- if (bufferPos[bufferStackPos] - 1 >= 0
- && bufferPos[bufferStackPos] + 1 < bufferStack[bufferStackPos].length
- && bufferStack[bufferStackPos][bufferPos[bufferStackPos] - 1] == '\''
- && bufferStack[bufferStackPos][bufferPos[bufferStackPos] + 1] == '\'')
- value = bufferStack[bufferStackPos][bufferPos[bufferStackPos]];
-
- if (tokenType != tEOF)
- nextToken();
- return value;
- }
-
- private static char[] _defined = "defined".toCharArray(); //$NON-NLS-1$
-
- private void nextToken() throws EvalException {
- boolean isHex = false;
- boolean isOctal = false;
- boolean isDecimal = false;
-
- contextLoop: while (bufferStackPos >= 0) {
-
- // Find the first thing we would care about
- skipWhiteSpace();
-
- while (++bufferPos[bufferStackPos] >= bufferLimit[bufferStackPos]) {
- // We're at the end of a context, pop it off and try again
- popContext();
- continue contextLoop;
- }
-
- // Tokens don't span buffers, stick to our current one
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
- pos = bufferPos[bufferStackPos];
-
- if (buffer[pos] >= '1' && buffer[pos] <= '9')
- isDecimal = true;
- else if (buffer[pos] == '0' && pos + 1 < limit)
- if (buffer[pos + 1] == 'x' || buffer[pos + 1] == 'X') {
- isHex = true;
- ++bufferPos[bufferStackPos];
- if (pos + 2 < limit)
- if ((buffer[pos + 2] < '0' || buffer[pos + 2] > '9')
- && (buffer[pos + 2] < 'a' || buffer[pos + 2] > 'f')
- && (buffer[pos + 2] < 'A' || buffer[pos + 2] > 'F'))
- handleProblem(IProblem.SCANNER_BAD_HEX_FORMAT,
- pos);
- } else
- isOctal = true;
-
- switch (buffer[pos]) {
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':
- case 'g':
- case 'h':
- case 'i':
- case 'j':
- case 'k':
- case 'l':
- case 'm':
- case 'n':
- case 'o':
- case 'p':
- case 'q':
- case 'r':
- case 's':
- case 't':
- case 'u':
- case 'v':
- case 'w':
- case 'x':
- case 'y':
- case 'z':
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':
- case 'G':
- case 'H':
- case 'I':
- case 'J':
- case 'K':
- case 'L':
- case 'M':
- case 'N':
- case 'O':
- case 'P':
- case 'Q':
- case 'R':
- case 'S':
- case 'T':
- case 'U':
- case 'V':
- case 'W':
- case 'X':
- case 'Y':
- case 'Z':
- case '_':
- int start = bufferPos[bufferStackPos];
- int len = 1;
-
- while (++bufferPos[bufferStackPos] < limit) {
- char c = buffer[bufferPos[bufferStackPos]];
- if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
- || c == '_' || (c >= '0' && c <= '9')) {
- ++len;
- continue;
- }
- break;
- }
-
- --bufferPos[bufferStackPos];
-
- // Check for defined(
- pos = bufferPos[bufferStackPos];
- if (CharArrayUtils.equals(buffer, start, len, _defined)) {
- tokenType = t_defined;
- return;
- }
-
- // Check for macro expansion
- Object expObject = null;
- if (bufferData[bufferStackPos] instanceof FunctionStyleMacro.Expansion) {
- // first check if name is a macro arg
- expObject = ((FunctionStyleMacro.Expansion) bufferData[bufferStackPos]).definitions
- .get(buffer, start, len);
- }
-
- if (expObject == null)
- // now check regular macros
- expObject = definitions.get(buffer, start, len);
-
- if (expObject != null) {
- if (expObject instanceof FunctionStyleMacro) {
- handleFunctionStyleMacro((FunctionStyleMacro) expObject);
- } else if (expObject instanceof ObjectStyleMacro) {
- ObjectStyleMacro expMacro = (ObjectStyleMacro) expObject;
- char[] expText = expMacro.getExpansion();
- if (expText.length > 0 )
- {
- if (BaseScanner.shouldExpandMacro(expMacro, bufferStackPos, bufferData, -1, bufferPos, bufferStack ))
- pushContext(expText, new MacroData(start, start + len, expMacro));
- else
- {
- if (len == 1) { // is a character
- tokenType = tCHAR;
- return;
- }
- // undefined macro, assume 0
- tokenValue = 0;
- tokenType = tNUMBER;
- return;
-
- }
-
- }
- } else if (expObject instanceof char[]) {
- char[] expText = (char[]) expObject;
- if (expText.length > 0)
- pushContext(expText, null);
- }
- continue;
- }
-
- if (len == 1) { // is a character
- tokenType = tCHAR;
- return;
- }
-
- // undefined macro, assume 0
- tokenValue = 0;
- tokenType = tNUMBER;
- return;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- tokenValue = buffer[pos] - '0';
- tokenType = tNUMBER;
-
- while (++bufferPos[bufferStackPos] < limit) {
- char c = buffer[bufferPos[bufferStackPos]];
- if (isHex) {
- if (c >= '0' && c <= '9') {
- tokenValue *= 16;
- tokenValue += c - '0';
- continue;
- } else if (c >= 'a' && c <= 'f') {
- tokenValue = (tokenValue == 0 ? 10
- : (tokenValue * 16) + 10);
- tokenValue += c - 'a';
- continue;
- } else if (c >= 'A' && c <= 'F') {
- tokenValue = (tokenValue == 0 ? 10
- : (tokenValue * 16) + 10);
- tokenValue += c - 'A';
- continue;
- } else {
- if (bufferPos[bufferStackPos] + 1 < limit)
- if (!isValidTokenSeparator(
- c,
- buffer[bufferPos[bufferStackPos] + 1]))
- handleProblem(
- IProblem.SCANNER_BAD_HEX_FORMAT,
- pos);
- }
- } else if (isOctal) {
- if (c >= '0' && c <= '7') {
- tokenValue *= 8;
- tokenValue += c - '0';
- continue;
- }
- if (bufferPos[bufferStackPos] + 1 < limit)
- if (!isValidTokenSeparator(c,
- buffer[bufferPos[bufferStackPos] + 1]))
- handleProblem(
- IProblem.SCANNER_BAD_OCTAL_FORMAT,
- pos);
- } else if (isDecimal) {
- if (c >= '0' && c <= '9') {
- tokenValue *= 10;
- tokenValue += c - '0';
- continue;
- }
- if (bufferPos[bufferStackPos] + 1 < limit
- && !(c == 'L' || c == 'l' || c == 'U' || c == 'u'))
- if (!isValidTokenSeparator(c,
- buffer[bufferPos[bufferStackPos] + 1]))
- handleProblem(
- IProblem.SCANNER_BAD_DECIMAL_FORMAT,
- pos);
- }
-
- // end of number
- if (c == 'L' || c == 'l' || c == 'U' || c == 'u') {
- // eat the long/unsigned
- int pos= ++bufferPos[bufferStackPos];
- if (pos < limit) {
- c= buffer[pos];
- if (c == 'L' || c == 'l' || c == 'U' || c == 'u') {
- pos= ++bufferPos[bufferStackPos];
- // gcc-extension: allow ULL for unsigned long long literals
- if (pos < limit) {
- c= buffer[pos];
- if (c == 'L' || c == 'l' || c == 'U' || c == 'u') {
- pos= ++bufferPos[bufferStackPos];
- }
- }
- }
- }
- }
-
- // done
- break;
- }
- --bufferPos[bufferStackPos];
- return;
- case '(':
- tokenType = tLPAREN;
- return;
-
- case ')':
- tokenType = tRPAREN;
- return;
-
- case ':':
- tokenType = tCOLON;
- return;
-
- case '?':
- tokenType = tQUESTION;
- return;
-
- case '+':
- tokenType = tPLUS;
- return;
-
- case '-':
- tokenType = tMINUS;
- return;
-
- case '*':
- tokenType = tMULT;
- return;
-
- case '/':
- tokenType = tDIV;
- return;
-
- case '%':
- tokenType = tMOD;
- return;
-
- case '^':
- tokenType = tBITXOR;
- return;
-
- case '&':
- if (pos + 1 < limit && buffer[pos + 1] == '&') {
- ++bufferPos[bufferStackPos];
- tokenType = tAND;
- return;
- }
- tokenType = tBITAND;
- return;
-
- case '|':
- if (pos + 1 < limit && buffer[pos + 1] == '|') {
- ++bufferPos[bufferStackPos];
- tokenType = tOR;
- return;
- }
- tokenType = tBITOR;
- return;
-
- case '~':
- tokenType = tCOMPL;
- return;
-
- case '!':
- if (pos + 1 < limit && buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- tokenType = tNOTEQUAL;
- return;
- }
- tokenType = tNOT;
- return;
-
- case '=':
- if (pos + 1 < limit && buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- tokenType = tEQUAL;
- return;
- }
- handleProblem(IProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED, pos);
- throw new EvalException("assignment not allowed"); //$NON-NLS-1$
-
- case '<':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- tokenType = tLTEQUAL;
- return;
- } else if (buffer[pos + 1] == '<') {
- ++bufferPos[bufferStackPos];
- tokenType = tSHIFTL;
- return;
- }
- }
- tokenType = tLT;
- return;
-
- case '>':
- if (pos + 1 < limit) {
- if (buffer[pos + 1] == '=') {
- ++bufferPos[bufferStackPos];
- tokenType = tGTEQUAL;
- return;
- } else if (buffer[pos + 1] == '>') {
- ++bufferPos[bufferStackPos];
- tokenType = tSHIFTR;
- return;
- }
- }
- tokenType = tGT;
- return;
-
- default:
- // skip over anything we don't handle
- }
- }
-
- // We've run out of contexts, our work is done here
- tokenType = tEOF;
- return;
- }
-
- private void handleFunctionStyleMacro(FunctionStyleMacro macro) {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- skipWhiteSpace();
- if (++bufferPos[bufferStackPos] >= limit
- || buffer[bufferPos[bufferStackPos]] != '(')
- return;
-
- FunctionStyleMacro.Expansion exp = macro.new Expansion();
- char[][] arglist = macro.arglist;
- int currarg = -1;
- int parens = 0;
-
- while (bufferPos[bufferStackPos] < limit) {
- if (++currarg >= arglist.length || arglist[currarg] == null)
- // too many args
- break;
-
- skipWhiteSpace();
-
- int p = ++bufferPos[bufferStackPos];
- char c = buffer[p];
- if (c == ')') {
- if (parens == 0)
- // end of macro
- break;
- --parens;
- continue;
- } else if (c == ',') {
- // empty arg
- exp.definitions.put(arglist[currarg], EMPTY_CHAR_ARRAY);
- continue;
- } else if (c == '(') {
- ++parens;
- continue;
- }
-
- // peel off the arg
- int argstart = p;
- int argend = argstart - 1;
-
- // Loop looking for end of argument
- while (bufferPos[bufferStackPos] < limit) {
- skipOverMacroArg();
- argend = bufferPos[bufferStackPos];
- skipWhiteSpace();
-
- if (++bufferPos[bufferStackPos] >= limit)
- break;
- c = buffer[bufferPos[bufferStackPos]];
- if (c == ',' || c == ')')
- break;
- }
-
- char[] arg = EMPTY_CHAR_ARRAY;
- int arglen = argend - argstart + 1;
- if (arglen > 0) {
- arg = new char[arglen];
- System.arraycopy(buffer, argstart, arg, 0, arglen);
- }
- exp.definitions.put(arglist[currarg], arg);
-
- if (c == ')')
- break;
- }
-
- char[] expText = macro.getExpansion();
- if (expText.length > 0)
- pushContext(expText, exp);
- }
-
- private void skipOverMacroArg() {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- while (++bufferPos[bufferStackPos] < limit) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case ' ':
- case '\t':
- case '\r':
- case ',':
- case ')':
- --bufferPos[bufferStackPos];
- return;
- case '\n':
- lineNumber++;
- --bufferPos[bufferStackPos];
- return;
- case '\\':
- int p = bufferPos[bufferStackPos];
- if (p + 1 < limit && buffer[p + 1] == '\n') {
- // \n is whitespace
- lineNumber++;
- --bufferPos[bufferStackPos];
- return;
- }
- break;
- case '"':
- boolean escaped = false;
- loop: while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
- switch (buffer[bufferPos[bufferStackPos]]) {
- case '\\':
- escaped = !escaped;
- continue;
- case '"':
- if (escaped) {
- escaped = false;
- continue;
- }
- break loop;
- default:
- escaped = false;
- }
- }
- break;
- }
- }
- --bufferPos[bufferStackPos];
- }
-
- private void skipWhiteSpace() {
- char[] buffer = bufferStack[bufferStackPos];
- int limit = bufferLimit[bufferStackPos];
-
- while (++bufferPos[bufferStackPos] < limit) {
- int p = bufferPos[bufferStackPos];
- switch (buffer[p]) {
- case ' ':
- case '\t':
- case '\r':
- continue;
- case '/':
- if (p + 1 < limit) {
- if (buffer[p + 1] == '/') {
- // C++ comment, skip rest of line
- for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) {
- p = bufferPos[bufferStackPos];
- if (buffer[p] == '\\' && p + 1 < limit
- && buffer[p + 1] == '\n') {
- bufferPos[bufferStackPos] += 2;
- continue;
- }
- if (buffer[p] == '\\' && p + 1 < limit
- && buffer[p + 1] == '\r'
- && p + 2 < limit
- && buffer[p + 2] == '\n') {
- bufferPos[bufferStackPos] += 3;
- continue;
- }
-
- if (buffer[p] == '\n')
- break; // break when find non-escaped
- // newline
- }
- continue;
- } else if (buffer[p + 1] == '*') { // C comment, find
- // closing */
- for (bufferPos[bufferStackPos] += 2; bufferPos[bufferStackPos] < limit; ++bufferPos[bufferStackPos]) {
- p = bufferPos[bufferStackPos];
- if (buffer[p] == '*' && p + 1 < limit
- && buffer[p + 1] == '/') {
- ++bufferPos[bufferStackPos];
- break;
- }
- }
- continue;
- }
- }
- break;
- case '\\':
- if (p + 1 < limit && buffer[p + 1] == '\n') {
- // \n is a whitespace
- lineNumber++;
- ++bufferPos[bufferStackPos];
- continue;
- }
- }
-
- // fell out of switch without continuing, we're done
- --bufferPos[bufferStackPos];
- return;
- }
-
- // fell out of while without continuing, we're done
- --bufferPos[bufferStackPos];
- return;
- }
-
- private static final int tNULL = 0;
-
- private static final int tEOF = 1;
-
- private static final int tNUMBER = 2;
-
- private static final int tLPAREN = 3;
-
- private static final int tRPAREN = 4;
-
- private static final int tNOT = 5;
-
- private static final int tCOMPL = 6;
-
- private static final int tMULT = 7;
-
- private static final int tDIV = 8;
-
- private static final int tMOD = 9;
-
- private static final int tPLUS = 10;
-
- private static final int tMINUS = 11;
-
- private static final int tSHIFTL = 12;
-
- private static final int tSHIFTR = 13;
-
- private static final int tLT = 14;
-
- private static final int tGT = 15;
-
- private static final int tLTEQUAL = 16;
-
- private static final int tGTEQUAL = 17;
-
- private static final int tEQUAL = 18;
-
- private static final int tNOTEQUAL = 19;
-
- private static final int tBITAND = 20;
-
- private static final int tBITXOR = 21;
-
- private static final int tBITOR = 22;
-
- private static final int tAND = 23;
-
- private static final int tOR = 24;
-
- private static final int tQUESTION = 25;
-
- private static final int tCOLON = 26;
-
- private static final int t_defined = 27;
-
- private static final int tCHAR = 28;
-
- private void pushContext(char[] buffer, Object data) {
- if (++bufferStackPos == bufferStack.length) {
- int size = bufferStack.length * 2;
-
- char[][] oldBufferStack = bufferStack;
- bufferStack = new char[size][];
- System.arraycopy(oldBufferStack, 0, bufferStack, 0,
- oldBufferStack.length);
-
- Object[] oldBufferData = bufferData;
- bufferData = new Object[size];
- System.arraycopy(oldBufferData, 0, bufferData, 0,
- oldBufferData.length);
-
- int[] oldBufferPos = bufferPos;
- bufferPos = new int[size];
- System.arraycopy(oldBufferPos, 0, bufferPos, 0,
- oldBufferPos.length);
-
- int[] oldBufferLimit = bufferLimit;
- bufferLimit = new int[size];
- System.arraycopy(oldBufferLimit, 0, bufferLimit, 0,
- oldBufferLimit.length);
- }
-
- bufferStack[bufferStackPos] = buffer;
- bufferPos[bufferStackPos] = -1;
- bufferLimit[bufferStackPos] = buffer.length;
- bufferData[bufferStackPos] = data;
- }
-
- private void popContext() {
- bufferStack[bufferStackPos] = null;
- bufferData[bufferStackPos] = null;
- --bufferStackPos;
- }
-
- private void handleProblem(int id, int startOffset) {
- }
-
- private boolean isValidTokenSeparator(char c, char c2)
- throws EvalException {
- switch (c) {
- case '\t':
- case '\r':
- case '\n':
- case ' ':
- case '(':
- case ')':
- case ':':
- case '?':
- case '+':
- case '-':
- case '*':
- case '/':
- case '%':
- case '^':
- case '&':
- case '|':
- case '~':
- case '!':
- case '<':
- case '>':
- return true;
- case '=':
- if (c2 == '=')
- return true;
- return false;
- }
-
- return false;
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java
deleted file mode 100644
index fc379f87c78..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FileCodeReaderFactory.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ICodeReaderFactory;
-import org.eclipse.cdt.core.dom.IMacroCollector;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.core.parser.CodeReader;
-import org.eclipse.cdt.core.parser.ICodeReaderCache;
-import org.eclipse.cdt.internal.core.dom.parser.EmptyCodeReaderCache;
-
-/**
- * @author jcamelon
- */
-public class FileCodeReaderFactory implements ICodeReaderFactory {
-
- private static FileCodeReaderFactory instance;
- private ICodeReaderCache cache = null;
-
- private FileCodeReaderFactory(ICodeReaderCache cache)
- {
- this.cache = cache;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#getUniqueIdentifier()
- */
- public int getUniqueIdentifier() {
- return 3;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForTranslationUnit(java.lang.String)
- */
- public CodeReader createCodeReaderForTranslationUnit(String path) {
- return cache.get(path);
- }
-
- public CodeReader createCodeReaderForTranslationUnit(ITranslationUnit tu) {
- return new CodeReader(tu.getPath().toOSString(), tu.getContents());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ICodeReaderFactory#createCodeReaderForInclusion(org.eclipse.cdt.core.dom.ICodeReaderFactoryCallback, java.lang.String)
- */
- public CodeReader createCodeReaderForInclusion(IMacroCollector scanner, String path) {
- return cache.get(path);
- }
-
- /**
- * @return
- */
- public static FileCodeReaderFactory getInstance() {
- if( instance == null )
- instance = new FileCodeReaderFactory(new EmptyCodeReaderCache());
- return instance;
- }
-
- public ICodeReaderCache getCodeReaderCache() {
- return cache;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java
deleted file mode 100644
index 5939166311d..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/FunctionStyleMacro.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial implementation
- * Markus Schorn (Wind River Systems)
- * Andrew Ferguson (Symbian)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import java.util.ArrayList;
-
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-
-/**
- * @author Doug Schaefer
- */
-public class FunctionStyleMacro extends ObjectStyleMacro {
-
- private static final char[] VA_ARGS_CHARARRAY = "__VA_ARGS__".toCharArray(); //$NON-NLS-1$
- private static final char[] ELLIPSIS_CHARARRAY = "...".toString().toCharArray(); //$NON-NLS-1$
- public char[][] arglist;
- private char[] sig = null;
- private boolean hasVarArgs = false;
- private boolean hasGCCVarArgs = false;
- private int varArgsPosition = -1;
-
- public FunctionStyleMacro(char[] name, char[] expansion, char[][] arglist) {
- super(name, expansion);
- this.arglist = arglist;
-
- // determine if there's an argument with "..."
- if (arglist != null && arglist.length > 0 && arglist[0]!= null) {
- int last = -1;
-
- // if the last element in the list is null then binary search for the last non-null element
- if (arglist[arglist.length-1] == null) {
- int largest = arglist.length - 1;
- int smallest = 0;
- for (int j=arglist.length/2; last == -1; ) {
- if (arglist[j] == null) {
- largest = j;
- j=smallest + (largest-smallest)/2;
- } else {
- smallest = j;
- j=smallest + (largest - smallest)/2;
- if ((j+1 == arglist.length && arglist[j] != null) || (arglist[j] != null && arglist[j+1] == null))
- last = j;
- }
- }
- } else
- last = arglist.length-1;
-
- if (arglist[last] != null && CharArrayUtils.equals(arglist[last], ELLIPSIS_CHARARRAY)) {
- this.hasVarArgs = true;
- varArgsPosition = last;
- // change the arg to __VA_ARGS__ so this will be replaced properly later on...
- arglist[last] = VA_ARGS_CHARARRAY;
- } else if (arglist[last] != null && CharArrayUtils.equals(arglist[last], arglist[last].length - ELLIPSIS_CHARARRAY.length, ELLIPSIS_CHARARRAY.length, ELLIPSIS_CHARARRAY)) { // if the last 3 are '...'
- this.hasGCCVarArgs = true;
- varArgsPosition = last;
- // change the arg to "argname" instead of "argname..." so argname will be replaced properly later on...
- char[] swap = new char[arglist[last].length - ELLIPSIS_CHARARRAY.length];
- System.arraycopy(arglist[last], 0, swap, 0, swap.length);
- arglist[last] = swap;
- }
- }
- }
-
- public char[][] getOriginalParameters() {
- if (varArgsPosition == -1) {
- return arglist;
- }
- ArrayList result= new ArrayList(arglist.length);
- for (int i = 0; i < arglist.length; i++) {
- final char[] var= arglist[i];
- if (var != null) {
- if (i != varArgsPosition) {
- result.add(var);
- }
- else {
- if (CharArrayUtils.equals(var, VA_ARGS_CHARARRAY)) {
- result.add(ELLIPSIS_CHARARRAY);
- }
- else {
- char[] varell= new char[var.length+ELLIPSIS_CHARARRAY.length];
- System.arraycopy(var, 0, varell, 0, var.length);
- System.arraycopy(ELLIPSIS_CHARARRAY, 0, varell, var.length, ELLIPSIS_CHARARRAY.length);
- result.add(varell);
- }
- }
- }
- }
- return (char[][]) result.toArray(new char[result.size()][]);
- }
-
- public char[] getSignature(){
- if( sig != null )
- return sig;
-
- int len = name.length + 2 /*()*/;
- final char[][] params = getOriginalParameters();
- for( int i = 0; i < params.length && params[i] != null; i++ ){
- if( i + 1 < params.length && params[i+1] != null)
- len += 1; /*,*/
- len += params[i].length;
- }
- sig = new char[len];
- System.arraycopy( name, 0, sig, 0, name.length );
- sig[name.length] = '(';
- int idx = name.length + 1;
- for( int i = 0; i < params.length && params[i] != null; i++ ){
- System.arraycopy( params[i], 0, sig, idx, params[i].length );
- idx += params[i].length;
- if( i + 1 < params.length && params[i+1] != null )
- sig[idx++] = ',';
- }
- sig[idx] = ')';
- return sig;
- }
- public class Expansion {
-
- public final CharArrayObjectMap definitions
- = new CharArrayObjectMap(FunctionStyleMacro.this.arglist.length);
-
- }
-
- public boolean hasVarArgs() {
- return hasVarArgs;
- }
-
- public boolean hasGCCVarArgs() {
- return hasGCCVarArgs;
- }
-
- public int getVarArgsPosition() {
- return varArgsPosition;
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java
deleted file mode 100644
index 98588311ee2..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GCCOldScannerExtensionConfiguration.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.parser.c.GCCScannerExtensionConfiguration;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-
-/**
- * The main purpose of this class is to provide a subclass of GCCScannerExtensionConfiguration
- * for exclusive use in the old parser (ParserFactory.createScanner()) so that as old
- * hacks are removed when fixed in the new parser, they can still apply to the old parser. This
- * way the old parser will not have to be maintained as it's no longer being tested.
- *
- * @author dsteffle
- */
-public class GCCOldScannerExtensionConfiguration extends
- GCCScannerExtensionConfiguration {
-
- private static final ObjectStyleMacro __cdecl = new ObjectStyleMacro(
- "__cdecl".toCharArray(), emptyCharArray); //$NON-NLS-1$
-
- private static final FunctionStyleMacro __attribute__ = new FunctionStyleMacro(
- "__attribute__".toCharArray(), //$NON-NLS-1$
- emptyCharArray, new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
-
- private static final FunctionStyleMacro __declspec = new FunctionStyleMacro(
- "__declspec".toCharArray(), //$NON-NLS-1$
- emptyCharArray, new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
- */
- public CharArrayObjectMap getAdditionalMacros() {
- CharArrayObjectMap result = super.getAdditionalMacros();
-
- result.put(__cdecl.name, __cdecl);
- result.put(__attribute__.name, __attribute__);
- result.put(__declspec.name, __declspec);
-
- return result;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java
deleted file mode 100644
index 462a897bc1b..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/GPPOldScannerExtensionConfiguration.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2002, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.parser.cpp.GPPScannerExtensionConfiguration;
-import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
-
-/**
- * The main purpose of this class is to provide a subclass of GPPScannerExtensionConfiguration
- * for exclusive use in the old parser (ParserFactory.createScanner()) so that as old
- * hacks are removed when fixed in the new parser, they can still apply to the old parser. This
- * way the old parser will not have to be maintained as it's no longer being tested.
- *
- * @author dsteffle
- */
-public class GPPOldScannerExtensionConfiguration extends
- GPPScannerExtensionConfiguration {
-
- private static final ObjectStyleMacro __cdecl = new ObjectStyleMacro(
- "__cdecl".toCharArray(), emptyCharArray); //$NON-NLS-1$
-
- private static final FunctionStyleMacro __attribute__ = new FunctionStyleMacro(
- "__attribute__".toCharArray(), //$NON-NLS-1$
- emptyCharArray, new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
-
- private static final FunctionStyleMacro __declspec = new FunctionStyleMacro(
- "__declspec".toCharArray(), //$NON-NLS-1$
- emptyCharArray, new char[][] { "arg".toCharArray() }); //$NON-NLS-1$
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerConfiguration#getAdditionalMacros()
- */
- public CharArrayObjectMap getAdditionalMacros() {
- CharArrayObjectMap result = super.getAdditionalMacros();
-
- result.put(__cdecl.name, __cdecl);
- result.put(__attribute__.name, __attribute__);
- result.put(__declspec.name, __declspec);
-
- return result;
- }
-
-}
-
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IDependencyNodeHost.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IDependencyNodeHost.java
deleted file mode 100644
index 7f0130cd8ac..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IDependencyNodeHost.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
-
-public interface IDependencyNodeHost {
-
- public void addInclusionNode( IASTInclusionNode node );
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java
deleted file mode 100644
index c31a2ece765..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ILocationResolver.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
-import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
-import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.dom.ast.IMacroBinding;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
-import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
-
-/**
- * @author jcamelon
- */
-public interface ILocationResolver {
-
- public IASTPreprocessorMacroDefinition [] getMacroDefinitions();
- public IASTPreprocessorMacroDefinition [] getBuiltinMacroDefinitions();
- public IASTPreprocessorIncludeStatement [] getIncludeDirectives();
- public IASTPreprocessorStatement [] getAllPreprocessorStatements();
-
- public IASTNodeLocation [] getLocations( int offset, int length );
-
- public char [] getUnpreprocessedSignature( IASTNodeLocation [] locations );
-
- public IASTProblem[] getScannerProblems();
-
- public String getTranslationUnitPath();
-
- public void cleanup();
-
- public ASTPreprocessorSelectionResult getPreprocessorNode( String path, int offset, int length ) throws InvalidPreprocessorNodeException;
-
- public void setRootNode(IASTTranslationUnit root );
- public IASTFileLocation flattenLocations(IASTNodeLocation[] nodeLocations);
- public IASTName[] getReferences(IMacroBinding binding);
- public IASTName[] getDeclarations(IMacroBinding binding);
- public IASTName[] getMacroExpansions();
- public IDependencyTree getDependencyTree();
- public String getContainingFilename(int offset);
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java
deleted file mode 100644
index 4941d93aafa..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/IScannerPreprocessorLog.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Anton Leherbauer (Wind River Systems)
- * Emanuel Graf (IFS)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.core.dom.ast.IMacroBinding;
-import org.eclipse.cdt.core.parser.CodeReader;
-
-/**
- * @author jcamelon
- */
-public interface IScannerPreprocessorLog {
-
- public void startTranslationUnit(CodeReader tu_reader);
-
- public void endTranslationUnit(int offset);
-
- public void startInclusion(CodeReader reader, int offset, int endOffset, int nameOffset, int nameEndoffset, char[] name, boolean systemInclude);
-
- public void endInclusion(CodeReader reader, int offset);
-
- public void startObjectStyleMacroExpansion(IMacroDefinition macro,
- int startOffset, int endOffset);
-
- public void endObjectStyleMacroExpansion(IMacroDefinition macro, int offset);
-
-
- public void startFunctionStyleExpansion(IMacroDefinition macro,
- char[][] parameters, int startOffset, int endOffset, char[][] actualArguments);
-
- public void endFunctionStyleExpansion(IMacroDefinition macro, int offset);
-
- public interface IMacroDefinition {
- public char[] getName();
- public char[] getExpansion();
-
- public IMacroBinding getBinding();
- public void setBinding( IMacroBinding b );
- }
-
- public IMacroDefinition defineObjectStyleMacro(ObjectStyleMacro m,
- int startOffset, int nameOffset, int nameEndOffset, int endOffset);
-
- public IMacroDefinition defineFunctionStyleMacro(FunctionStyleMacro m,
- int startOffset, int nameOffset, int nameEndOffset, int endOffset);
-
- public void encounterPoundIf(int startOffset, int endOffset, boolean taken, char[] condition);
-
- public void encounterPoundIfdef(int startOffset, int endOffset,
- boolean taken, char[] condition);
-
- public void encounterPoundIfndef(int startOffset, int endOffset,
- boolean taken, char[] condition);
-
- public void encounterPoundElse(int startOffset, int endOffset, boolean taken);
-
- public void encounterPoundElif(int startOffset, int endOffset, boolean taken, char[] condition);
-
- public void encounterPoundEndIf(int startOffset, int endOffset);
-
- public void encounterPoundPragma(int startOffset, int endOffset, char[] msg);
-
- public void encounterPoundError(int startOffset, int endOffset, char[] msg);
-
- public void encounterPoundWarning(int startOffset, int endOffset, char[] msg);
-
- public void encounterPoundUndef(int startOffset, int endOffset,
- char[] symbol, int nameOffset, IMacroDefinition macroDefinition);
-
- /**
- * @deprecated use {@link #encounterPoundInclude(int, int, int, int, char[], char[], boolean, boolean)}.
- */
- public void encounterPoundInclude(int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name, boolean systemInclude, boolean active);
-
- /**
- * Report an include that is not actually processed ({@link #startInclusion(CodeReader, int, int, int, int, char[], boolean)}
- * To report hidden dependencies (bug 167100) you can use the path parameter.
- * @param startOffset
- * @param nameOffset
- * @param nameEndOffset
- * @param endOffset
- * @param name the name of the include as found in the source
- * @param hiddenDependency a file-path in case the include is a hidden dependency, or <code>null</code>.
- * @param systemInclude
- * @param active
- */
- public void encounterPoundInclude(int startOffset, int nameOffset, int nameEndOffset, int endOffset, char[] name, char[] hiddenDependency, boolean systemInclude, boolean active);
-
- public void encounterProblem(IASTProblem problem);
-
- public IMacroDefinition registerBuiltinObjectStyleMacro(ObjectStyleMacro macro);
-
- public IMacroDefinition registerBuiltinFunctionStyleMacro(FunctionStyleMacro macro);
-
- public IMacroDefinition registerBuiltinDynamicFunctionStyleMacro(DynamicFunctionStyleMacro macro);
-
- public IMacroDefinition registerBuiltinDynamicStyleMacro(DynamicStyleMacro macro);
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java
deleted file mode 100644
index 0bb0dff200b..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InclusionNode.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
-
-public class InclusionNode implements IASTInclusionNode, IDependencyNodeHost {
-
- private final IASTPreprocessorIncludeStatement stmt;
-
- public InclusionNode(IASTPreprocessorIncludeStatement stmt) {
- this.stmt = stmt;
- }
-
- public IASTPreprocessorIncludeStatement getIncludeDirective() {
- return stmt;
- }
-
- private IASTInclusionNode [] incs = new IASTInclusionNode[2];
- private int incsPos=-1;
-
- public IASTInclusionNode[] getNestedInclusions() {
- incs = (IASTInclusionNode[]) ArrayUtil.removeNullsAfter( IASTInclusionNode.class, incs, incsPos );
- return incs;
- }
-
- public void addInclusionNode(IASTInclusionNode node) {
- if (node != null) {
- incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, ++incsPos, node );
- }
- }
-
- public String toString() {
- return stmt.toString();
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InvalidPreprocessorNodeException.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InvalidPreprocessorNodeException.java
deleted file mode 100644
index 4df10d55a2c..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/InvalidPreprocessorNodeException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-/**
- * @author dsteffle
- */
-public class InvalidPreprocessorNodeException extends Exception {
-
- public InvalidPreprocessorNodeException(String message) {
- super(message);
- }
-
- public InvalidPreprocessorNodeException(String message, int offset) {
- super(message);
- globalOffset = offset;
- }
-
- private int globalOffset = -1;
-
- public int getGlobalOffset() {
- return globalOffset;
- }
-
- public void setGlobalOffset(int offset) {
- globalOffset = offset;
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java
deleted file mode 100644
index ee5467b7766..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java
+++ /dev/null
@@ -1,2937 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Anton Leherbauer (Wind River Systems)
- * Emanuel Graf (IFS)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import java.util.ArrayList;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
-import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
-import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
-import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
-import org.eclipse.cdt.core.dom.ast.IASTName;
-import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElseStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorErrorStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorPragmaStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
-import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
-import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IMacroBinding;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
-import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
-import org.eclipse.cdt.core.index.IIndexMacro;
-import org.eclipse.cdt.core.parser.CodeReader;
-import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.core.parser.util.ArrayUtil;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
-import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
-
-/**
- * @author jcamelon
- */
-public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
-
-
- public LocationMap() {
- tu = new _TranslationUnit();
- currentContext = tu;
- }
-
- public class MacroExpansionLocation implements IASTMacroExpansion {
-
- public MacroExpansionLocation(
- IASTPreprocessorMacroDefinition macroDefinition,
- IASTNodeLocation[] locations, int offset, int length) {
- this.definition = macroDefinition;
- this.locations = locations;
- this.offset = offset;
- this.length = length;
- }
-
- private final int length;
-
- private final int offset;
-
- private final IASTNodeLocation[] locations;
-
- private final IASTPreprocessorMacroDefinition definition;
-
- public IASTPreprocessorMacroDefinition getMacroDefinition() {
- return definition;
- }
-
- public IASTNodeLocation[] getExpansionLocations() {
- return locations;
- }
-
- public int getNodeOffset() {
- return offset;
- }
-
- public int getNodeLength() {
- return length;
- }
-
- public IASTFileLocation asFileLocation() {
- return rootNode.flattenLocationsToFile(locations);
- }
-
- public String toString() {
-
- return "Macro Expansion " + definition.getName().toString() + " flattened to " + asFileLocation().toString(); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- }
-
- public class FunctionMacroExpansionLocation extends MacroExpansionLocation{
-
- private char[][] actParams;
-
- /**
- * @param macroDefinition
- * @param locations
- * @param offset
- * @param length
- */
- public FunctionMacroExpansionLocation(IASTPreprocessorMacroDefinition macroDefinition, IASTNodeLocation[] locations, int offset, int length, char[][] actParameters) {
- super(macroDefinition, locations, offset, length);
- this.actParams = actParameters;
- }
-
- public char[][] getActualParameters() {
- return actParams;
- }
-
- }
-
- private static final String NOT_VALID_MACRO = "Not a valid macro selection"; //$NON-NLS-1$
-
- private static final String TU_INCLUDE_NOT_FOUND = "File searching does not match TU or #includes."; //$NON-NLS-1$
-
- /**
- * @author jcamelon
- */
- public static class ASTEndif extends ASTNode implements
- IASTPreprocessorEndifStatement {
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTElif extends ASTNode implements
- IASTPreprocessorElifStatement {
-
- private final boolean taken;
- private char[] condition;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
- */
- public boolean taken() {
- return taken;
- }
-
- /**
- * @param taken
- */
- public ASTElif(boolean taken, char[] condition) {
- this.taken = taken;
- this.condition = condition;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#getCondition()
- */
- public char[] getCondition() {
- return condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTElse extends ASTNode implements
- IASTPreprocessorElseStatement {
- private final boolean taken;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
- */
- public boolean taken() {
- return taken;
- }
-
- /**
- * @param taken
- */
- public ASTElse(boolean taken) {
- this.taken = taken;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTIfndef extends ASTNode implements
- IASTPreprocessorIfndefStatement {
-
- private final boolean taken;
- private char[] condition;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
- */
- public boolean taken() {
- return taken;
- }
-
- /**
- * @param taken
- */
- public ASTIfndef(boolean taken, char[] condition) {
- this.taken = taken;
- this.condition = condition;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement#getCondition()
- */
- public char[] getCondition() {
- return condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTIfdef extends ASTNode implements
- IASTPreprocessorIfdefStatement {
-
- private final boolean taken;
-
- private char[] condition;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
- */
- public boolean taken() {
- return taken;
- }
-
- /**
- * @param taken
- */
- public ASTIfdef(boolean taken, char[] condition) {
- this.taken = taken;
- this.condition = condition;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement#getCondition()
- */
- public char[] getCondition() {
- return condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTIf extends ASTNode implements
- IASTPreprocessorIfStatement {
-
- private final boolean taken;
- private char[] condition;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorElifStatement#taken()
- */
- public boolean taken() {
- return taken;
- }
-
- /**
- * @param taken
- */
- public ASTIf(boolean taken, char[] condition) {
- this.taken = taken;
- this.condition = condition;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfStatement#getCondition()
- */
- public char[] getCondition() {
- return condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTError extends ASTNode implements
- IASTPreprocessorErrorStatement {
-
- private char[] msg;
-
-
-
- public ASTError(char[] msg) {
- super();
- this.msg = msg;
- }
-
- public char[] getMessage() {
- return msg;
- }
-
- }
-
- public static class ASTWarning extends ASTNode implements
- IASTPreprocessorErrorStatement {
-
- private char[] msg;
-
- public ASTWarning(char[] msg) {
- super();
- this.msg = msg;
- }
-
- public char[] getMessage() {
- return msg;
- }
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTPragma extends ASTNode implements
- IASTPreprocessorPragmaStatement {
-
- private char[] msg;
-
-
-
- public ASTPragma(char[] msg) {
- super();
- this.msg = msg;
- }
-
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.dom.ast.IASTPreprocessorPragmaStatement#getMessage()
- */
- public char[] getMessage() {
- return msg;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTUndef extends ASTNode implements
- IASTPreprocessorUndefStatement {
-
- public ASTUndef( IASTName n )
- {
- this.n = n;
- n.setPropertyInParent( IASTPreprocessorUndefStatement.MACRO_NAME );
- n.setParent(this);
- }
-
- private final IASTName n;
-
- public IASTName getMacroName() {
- return n;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Endif extends _Context implements
- _IPreprocessorDirective {
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Endif(_CompositeContext parent, int startOffset, int endOffset) {
- super(parent, startOffset, endOffset);
- // TODO Auto-generated constructor stub
- }
-
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Elif extends _Context implements
- _IPreprocessorDirective {
-
- public final boolean taken;
- public char[] condition;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Elif(_CompositeContext parent, int startOffset, int endOffset,
- boolean taken, char[] condition) {
- super(parent, startOffset, endOffset);
- this.taken = taken;
- this.condition = condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Ifdef extends _Context implements
- _IPreprocessorDirective {
-
- public final boolean taken;
- public char[] condition;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Ifdef(_CompositeContext parent, int startOffset, int endOffset,
- boolean taken, char[] condition) {
- super(parent, startOffset, endOffset);
- this.taken = taken;
- this.condition = condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Ifndef extends _Context implements
- _IPreprocessorDirective {
-
- public final boolean taken;
- public char[] condition;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Ifndef(_CompositeContext parent, int startOffset,
- int endOffset, boolean taken, char[] condition) {
- super(parent, startOffset, endOffset);
- this.taken = taken;
- this.condition = condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Error extends _Context implements
- _IPreprocessorDirective {
-
- char[] msg;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- * @param msg
- */
- public _Error(_CompositeContext parent, int startOffset, int endOffset, char[] msg) {
- super(parent, startOffset, endOffset);
- this.msg = msg;
- }
-
- }
-
- protected static class _Warning extends _Context implements _IPreprocessorDirective {
- char[] msg;
- public _Warning(_CompositeContext parent, int startOffset, int endOffset, char[] msg) {
- super(parent, startOffset, endOffset);
- this.msg = msg;
- }
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Pragma extends _Context implements
- _IPreprocessorDirective {
-
- char[] msg;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Pragma(_CompositeContext parent, int startOffset, int endOffset, char[] msg) {
- super(parent, startOffset, endOffset);
- this.msg = msg;
- }
-
-
- }
-
- /**
- * @author jcamelon
- */
- protected class _If extends _Context implements _IPreprocessorDirective {
-
- public final boolean taken;
- public char[] condition;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _If(_CompositeContext parent, int startOffset, int endOffset,
- boolean taken, char[] condition) {
- super(parent, startOffset, endOffset);
- this.taken = taken;
- this.condition = condition;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- protected static class _Else extends _Context implements
- _IPreprocessorDirective {
-
- public final boolean taken;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Else(_CompositeContext parent, int startOffset, int endOffset,
- boolean taken) {
- super(parent, startOffset, endOffset);
- this.taken = taken;
- }
-
- }
-
- /**
- * Represents an include directive without sub-contexts.
- * This allows to model inactive includes and unresolved includes.
- */
- protected static class _Include extends _Context implements
- _IPreprocessorIncludeDirective {
-
- public final int fNameOffset;
- public final int fNameEndOffset;
- public final char[] fName;
- public final char[] fPath;
- public final boolean fSystemInclude;
- public final boolean fIsActive;
- public final boolean fIsResolved;
-
- public _Include(_CompositeContext parent, int startOffset, int endOffset, int nameOffset, int nameEndoffset,
- char[] name, char[] path, boolean systemInclude, boolean active, boolean resolved) {
- super(parent, startOffset, endOffset);
- fNameOffset= nameOffset;
- fNameEndOffset= nameEndoffset;
- fName= name;
- fPath= path == null ? name : path;
- fSystemInclude= systemInclude;
- fIsActive= active;
- fIsResolved= resolved;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTInclusionStatement extends ASTNode implements
- IASTPreprocessorIncludeStatement {
-
- private final char[] path;
- private IASTName fName;
-
- public int startOffset;
- public int endOffset;
- private boolean fSystemInclude;
- private boolean fIsActive= true;
- private boolean fIsResolved= true;
-
- /**
- * @param cs
- */
- public ASTInclusionStatement(char[] cs) {
- this.path = cs;
- }
-
- public String getPath() {
- return new String(path);
- }
-
- public String toString() {
- return getPath();
- }
-
- public IASTName getName() {
- return fName;
- }
-
- public void setName(IASTName name) {
- fName= name;
- }
-
- public boolean isSystemInclude() {
- return fSystemInclude;
- }
-
- public void setSystemInclude(boolean val) {
- fSystemInclude= val;
- }
-
- public boolean isActive() {
- return fIsActive;
- }
-
- public void setActive(boolean val) {
- fIsActive= val;
- }
-
- public boolean isResolved() {
- return fIsResolved;
- }
-
- public void setResolved(boolean val) {
- fIsResolved= val;
- }
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTFunctionMacro extends ASTNode implements
- IASTPreprocessorFunctionStyleMacroDefinition {
-
- private IASTName name;
- private String expansion;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#getParameters()
- */
- public IASTFunctionStyleMacroParameter[] getParameters() {
- if (parameters == null)
- return IASTFunctionStyleMacroParameter.EMPTY_PARAMETER_ARRAY;
- removeNullParameters();
- return parameters;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroDefinition#addParameter(org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter)
- */
- public void addParameter(IASTFunctionStyleMacroParameter parm) {
- if (parameters == null) {
- parameters = new IASTFunctionStyleMacroParameter[DEFAULT_PARMS_LIST_SIZE];
- currentIndex = 0;
- }
- if (parameters.length == currentIndex) {
- IASTFunctionStyleMacroParameter[] old = parameters;
- parameters = new IASTFunctionStyleMacroParameter[old.length * 2];
- for (int i = 0; i < old.length; ++i)
- parameters[i] = old[i];
- }
- parameters[currentIndex++] = parm;
- }
-
- private void removeNullParameters() {
- int nullCount = 0;
- for (int i = 0; i < parameters.length; ++i)
- if (parameters[i] == null)
- ++nullCount;
- if (nullCount == 0)
- return;
- IASTFunctionStyleMacroParameter[] old = parameters;
- int newSize = old.length - nullCount;
- parameters = new IASTFunctionStyleMacroParameter[newSize];
- for (int i = 0; i < newSize; ++i)
- parameters[i] = old[i];
- currentIndex = newSize;
- }
-
- private int currentIndex = 0;
-
- private IASTFunctionStyleMacroParameter[] parameters = null;
-
- private static final int DEFAULT_PARMS_LIST_SIZE = 2;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
- */
- public IASTName getName() {
- return name;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
- */
- public void setName(IASTName name) {
- this.name = name;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
- */
- public String getExpansion() {
- return expansion;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
- */
- public void setExpansion(String exp) {
- this.expansion = exp;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName)
- */
- public int getRoleForName(IASTName n) {
- if (name == n)
- return r_definition;
- return r_unclear;
- }
-
- public IASTFileLocation getExpansionLocation() {
- return null;
- }
-
- }
-
- public static interface _IPreprocessorDirective {
- }
- public static interface _IPreprocessorIncludeDirective extends _IPreprocessorDirective {
- }
-
- protected class _Undef extends _Context implements
- _IPreprocessorDirective {
- public final char[] name;
- public final int nameOffset;
- private IASTName expansionName;
- public final IMacroDefinition macroDefn;
-
- public IASTName getName()
- {
- if( expansionName == null )
- {
- expansionName = new ASTMacroName( name );
- expansionName.setParent( rootNode );
- expansionName.setPropertyInParent( IASTPreprocessorUndefStatement.MACRO_NAME );
- ((ASTNode)expansionName).setOffsetAndLength( context_directive_start, name.length );
- }
- return expansionName;
- }
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Undef(_CompositeContext parent, int startOffset, int endOffset,
- char[] name, int nameOffset, IMacroDefinition macro ) {
- super(parent, startOffset, endOffset);
- this.name = name;
- this.nameOffset = nameOffset;
- this.macroDefn = macro;
- }
-
- }
-
- /**
- * @author jcamelon
- */
- public class ASTMacroName extends ASTNode implements IASTName {
- private final char[] name;
- private final IASTFileLocation fileLocation;
- private IMacroBinding binding = null;
-
- public ASTMacroName(char[] n) {
- this(n, null);
- }
-
- public ASTMacroName(char [] n, IASTFileLocation fileLocation) {
- this.name = n;
- this.fileLocation = fileLocation;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTName#resolveBinding()
- */
- public IBinding resolveBinding() {
- if( binding == null )
- {
- binding = resolveBindingForMacro( name, getOffset() );
- }
- return binding;
- }
-
-
- public IASTCompletionContext getCompletionContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTName#toCharArray()
- */
- public char[] toCharArray() {
- return name;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return new String(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTName#isDeclaration()
- */
- public boolean isDeclaration() {
- if (getParent() instanceof IASTPreprocessorMacroDefinition
- && getPropertyInParent() == IASTPreprocessorMacroDefinition.MACRO_NAME)
- return true;
- return false;
- }
-
- public boolean isDefinition() {
- return isDeclaration();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTName#isReference()
- */
- public boolean isReference() {
- return !isDeclaration();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTName#getBinding()
- */
- public IBinding getBinding() {
- return binding;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTName#setBinding(org.eclipse.cdt.core.dom.ast.IBinding)
- */
- public void setBinding(IBinding binding) {
- //do nothing
- }
-
- public IASTFileLocation getFileLocation() {
- return fileLocation != null ? fileLocation : super.getFileLocation();
- }
-
- public ILinkage getLinkage() {
- return Linkage.NO_LINKAGE;
- }
- }
-
- public class ASTIncludeName extends ASTNode implements IASTName {
- private final char[] name;
-
- public ASTIncludeName(char[] n) {
- this.name = n;
- }
-
- public IBinding resolveBinding() {
- return null;
- }
- public IASTCompletionContext getCompletionContext() {
- return null;
- }
-
- public char[] toCharArray() {
- return name;
- }
-
- public String toString() {
- return new String(name);
- }
-
- public boolean isDeclaration() {
- return false;
- }
-
- public boolean isDefinition() {
- return false;
- }
-
- public boolean isReference() {
- return false;
- }
-
- public IBinding getBinding() {
- return null;
- }
-
- public void setBinding(IBinding binding) {
- }
-
- public ILinkage getLinkage() {
- return Linkage.NO_LINKAGE;
- }
- }
-
- /**
- * @author jcamelon
- */
- public static class ASTObjectMacro extends ASTNode implements
- IASTPreprocessorObjectStyleMacroDefinition {
-
- private IASTName name;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTNameOwner#getRoleForName(org.eclipse.cdt.core.dom.ast.IASTName)
- */
- public int getRoleForName(IASTName n) {
- if (name == n)
- return r_definition;
- return r_unclear;
- }
-
- private String expansion;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getName()
- */
- public IASTName getName() {
- return name;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setName(org.eclipse.cdt.core.dom.ast.IASTName)
- */
- public void setName(IASTName name) {
- this.name = name;
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#getExpansion()
- */
- public String getExpansion() {
- return expansion;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTMacroDefinition#setExpansion(java.lang.String)
- */
- public void setExpansion(String exp) {
- this.expansion = exp;
- }
-
- public IASTFileLocation getExpansionLocation() {
- return null;
- }
-
- }
-
- public abstract static class Location implements IASTNodeLocation {
- private final int nodeOffset;
-
- private final int nodeLength;
-
- /**
- * @param offset
- * @param length
- */
- public Location(int offset, int length) {
- nodeOffset = offset;
- nodeLength = length;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeOffset()
- */
- public int getNodeOffset() {
- return nodeOffset;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTNodeLocation#getNodeLength()
- */
- public int getNodeLength() {
- return nodeLength;
- }
-
- }
-
- public static class ASTFunctionMacroParameter extends ASTNode
- implements IASTFunctionStyleMacroParameter {
- private String value;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter#getParameter()
- */
- public String getParameter() {
- return value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter#setParameter(java.lang.String)
- */
- public void setParameter(String value) {
- this.value = value;
- }
-
- }
-
- public class FileLocation extends Location implements
- IASTFileLocation {
-
- private String fileName;
- private _CompositeFileContext _fileContext;
-
- /**
- * @param length
- * @param offset
- * @param tu_filename
- *
- */
- public FileLocation(char[] tu_filename, int offset, int length) {
- super(offset, length);
- fileName = new String(tu_filename);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.dom.ast.IASTFileLocation#getFileName()
- */
- public String getFileName() {
- return fileName;
- }
-
- public IASTFileLocation asFileLocation() {
- return this;
- }
-
- public int getStartingLineNumber() {
- _CompositeFileContext i = getFileContext();
- if( i != null )
- return i.getLineNumber( getNodeOffset() );
- return 0;
- }
-
- private _CompositeFileContext getFileContext() {
- if( _fileContext == null )
- {
- if( fileName.equals( getTranslationUnitPath() ))
- _fileContext = tu;
- else
- _fileContext = findInclusion( tu, fileName );
- }
- return _fileContext;
- }
-
- public int getEndingLineNumber() {
- _CompositeFileContext i = getFileContext();
- if( i != null )
- return i.getLineNumber( getNodeOffset() + getNodeLength());
- return 0;
- }
-
- public String toString() {
- StringBuffer buffer = new StringBuffer( fileName );
- buffer.append(" line " ); //$NON-NLS-1$
- buffer.append( getStartingLineNumber() );
- buffer.append( " to " ); //$NON-NLS-1$
- buffer.append( getEndingLineNumber() );
- return buffer.toString();
- }
-
- }
-
- protected static class _Context {
- /**
- * @param startOffset
- * @param endOffset
- */
- public _Context(_CompositeContext parent, int startOffset, int endOffset) {
- this.context_directive_start = startOffset;
- this.context_directive_end = endOffset;
- this.context_ends = endOffset;
- this.parent = parent;
- }
-
- /**
- * Global offset of start of directive (inclusive).
- */
- public int context_directive_start;
- /**
- * Global offset of end of directive (exclusive).
- */
- public int context_directive_end;
- /**
- * Global offset of end of context introduced by directive (exclusive).
- */
- public int context_ends;
- public _CompositeContext parent;
-
- public _CompositeContext getParent() {
- return parent;
- }
-
- public int getDirectiveStart() {
- return context_directive_start;
- }
-
- public int getDirectiveLength() {
- return context_directive_end - context_directive_start;
- }
-
- public int getContextStart() {
- return context_directive_end;
- }
-
- public int getContextLength() {
- return context_ends- context_directive_end;
- }
-
- public final boolean contains(int offset) {
- return (offset >= context_directive_start && offset < context_ends);
- }
-
- public final boolean containsInContext(int offset) {
- return (offset >= context_directive_end && offset < context_ends);
- }
-
- public boolean containsInDirective(int offset, int length) {
- return context_directive_start <= offset && offset + length <= context_directive_end;
- }
-
- public boolean hasAncestor(_Context cc) {
- _Context p = parent;
- while (p != null) {
- if (p == cc)
- return true;
- p = p.parent;
- }
- return false;
- }
-
- public _CompositeFileContext getContainingFileContext() {
- if( this instanceof _CompositeFileContext )
- return (_CompositeFileContext) this;
- _CompositeContext result = getParent();
- while( !( result instanceof _CompositeFileContext ) )
- result = result.getParent();
- return (_CompositeFileContext) result;
- }
- }
-
- protected static class _CompositeContext extends _Context {
-
- public _CompositeContext(_CompositeContext parent, int startOffset,
- int endOffset) {
- super(parent, startOffset, endOffset);
- }
-
- private static final int DEFAULT_SUBCONTEXT_ARRAY_SIZE = 8;
-
- private _Context[] subContexts = null;
-
- private static final _Context[] EMPTY_CONTEXT_ARRAY = new _Context[0];
-
- public _Context[] getSubContexts() {
- if (subContexts == null)
- return EMPTY_CONTEXT_ARRAY;
- final int length= subContexts.length;
- if (length > 0 && subContexts[length-1] == null) {
- subContexts = (_Context[]) ArrayUtil.trim(_Context.class, subContexts);
- }
- return subContexts;
- }
-
- public void addSubContext(_Context c) {
- if (subContexts == null)
- subContexts = new _Context[DEFAULT_SUBCONTEXT_ARRAY_SIZE];
- subContexts = (_Context[]) ArrayUtil.append(_Context.class, subContexts, c);
- }
-
- public boolean hasSubContexts() {
- if (subContexts == null)
- return false;
- for (int i = 0; i < subContexts.length; ++i)
- if (subContexts[i] != null)
- return true;
- return false;
- }
-
- public _Context findContextContainingOffset(int offset) {
- if (subContexts != null)
- {
- int left = 0;
- int right = subContexts.length - 1;
- int middle = 0;
- while (left <= right) {
- middle = (left+right) / 2;
- _Context c = subContexts[middle];
- if (c== null || offset < c.context_directive_start) {
- right= middle-1;
- }
- else if (offset >= c.context_ends) {
- left= middle+1;
- }
- else {
- if (c instanceof _CompositeContext) {
- final _CompositeContext compositeContext = (_CompositeContext) c;
- _Context nested= compositeContext.findContextContainingOffset(offset);
- if (nested != null) {
- return nested;
- }
- }
- return c;
- }
- }
- }
- // if no sub context contains this, do it this way
- if ((offset >= context_directive_start && offset < context_ends))
- return this;
- return null;
- }
-
-
- public int getNumberOfContexts() {
- final _Context[] contextz = getSubContexts();
- int result = contextz.length;
- for (int i = 0; i < contextz.length; ++i)
- if (contextz[i] instanceof _CompositeContext)
- result += ((_CompositeContext) contextz[i])
- .getNumberOfContexts();
- return result;
- }
-
- public int getOffsetInContext(int globalOffset) {
- int externalCount= 0;
- if (subContexts != null) {
- for (int i = 0; i < subContexts.length; ++i) {
- _Context subC = subContexts[i];
- if (subC == null || globalOffset < subC.getContextStart()) {
- break;
- }
- if (subC instanceof _CompositeContext) {
- externalCount+= subC.getContextLength();
- }
- }
- }
- final int result = globalOffset - externalCount - getContextStart();
- return ((result < 0) ? 0 : result);
- }
- }
-
- protected static class _CompositeFileContext extends _CompositeContext {
- public CodeReader reader;
- private int[] lineOffsetCache;
- private int numberOfLines;
-
- public _CompositeFileContext(_CompositeContext parent, int startOffset,
- int endOffset, CodeReader reader) {
- super(parent, startOffset, endOffset);
- this.reader = reader;
- }
-
- public _CompositeFileContext(_CompositeContext parent, int startOffset,
- int endOffset ) {
- super(parent, startOffset, endOffset);
- }
-
- public int getLineNumber(int nodeOffset) {
- if( nodeOffset >= reader.buffer.length )
- return 1;
- if (lineOffsetCache == null) {
- createLineOffsetCache();
- }
- int left= 0;
- int right= numberOfLines - 1;
- int mid= 0;
-
- while (left < right) {
- mid= (left + right) / 2;
- int lineOffset= lineOffsetCache[mid];
- if (nodeOffset < lineOffset) {
- if (left == mid)
- right= mid;
- else
- right= mid - 1;
- } else if (nodeOffset > lineOffset) {
- if (right == mid)
- left= mid;
- else
- left= mid + 1;
- } else if (nodeOffset == lineOffset) {
- left= right= mid;
- }
- }
- if (nodeOffset < lineOffsetCache[left])
- --left;
- return left + 1;
- }
-
- private void createLineOffsetCache() {
- final char[] buffer= reader.buffer;
- int[] lineOffsets= new int[buffer.length / 30 + 1];
- int lines= 1;
- lineOffsets[0]= 0;
- for (int i = 0; i < buffer.length; ++i) {
- // TODO consider '\r' line endings?
- if (buffer[i] == '\n') {
- if (lineOffsets.length == lines) {
- final int ratio= Math.min(Math.max(i / lines, 1), 20);
- int[] tmp= new int[lines + (buffer.length - i) / ratio + 1];
- System.arraycopy(lineOffsets, 0, tmp, 0, lines);
- lineOffsets= tmp;
- }
- lineOffsets[lines++]= i + 1;
- }
- }
- lineOffsetCache= lineOffsets;
- numberOfLines= lines;
- }
- }
-
- protected static class _Inclusion extends _CompositeFileContext implements
- _IPreprocessorIncludeDirective {
-
- public final int fNameOffset;
- public final int fNameEndOffset;
- public final char[] fName;
- public boolean fSystemInclude;
-
- public _Inclusion(_CompositeContext parent, CodeReader reader,
- int startOffset, int endOffset, int nameOffset, int nameEndoffset, char[] name, boolean systemInclude) {
- super(parent, startOffset, endOffset, reader);
- fNameOffset= nameOffset;
- fNameEndOffset= nameEndoffset;
- fName= name;
- fSystemInclude= systemInclude;
- }
- }
-
- protected static class _TranslationUnit extends _CompositeFileContext {
-
- public _TranslationUnit() {
- super(null, 0, 0 );
- }
-
- IMacroDefinition [] builtins = new IMacroDefinition[2];
- private int builtinsPos=-1;
-
- public void addBuiltinMacro(IMacroDefinition def) {
- if (def != null) {
- builtins = (IMacroDefinition[]) ArrayUtil.append( IMacroDefinition.class, builtins, ++builtinsPos, def );
- }
- }
-
- public IMacroDefinition [] getBuiltinMacroDefinitions()
- {
- builtins = (IMacroDefinition[]) ArrayUtil.removeNullsAfter( IMacroDefinition.class, builtins, builtinsPos );
- return builtins;
- }
-
- }
-
- protected static class _MacroDefinition extends _Context implements
- IMacroDefinition {
-
- public _MacroDefinition(_CompositeContext parent, int startOffset,
- int endOffset, char[] name, int nameOffset, char[] expansion) {
- super(parent, startOffset, endOffset);
- this.name = name;
- this.expansion = expansion;
- this.nameOffset = nameOffset;
- }
-
- public _MacroDefinition(_CompositeContext parent, int startOffset,
- int endOffset, char[] name, int nameOffset, IMacro macro) {
- super(parent, startOffset, endOffset);
- this.name = name;
- this.macro = macro;
- this.nameOffset = nameOffset;
- }
-
- public final char[] name;
- public final int nameOffset;
- public IASTPreprocessorMacroDefinition astNode;
-
- // expansions can be in the IMacro if there is one
- private char[] expansion;
- private IMacro macro;
-
- private IMacroBinding bind;
-
- public char[] getName() {
- return name;
- }
-
- public char[] getExpansion() {
- if (expansion == null && macro != null)
- expansion = macro.getExpansion();
- return expansion;
- }
-
- public IASTFileLocation getFileLocation() {
- return macro != null && macro instanceof IIndexMacro
- ? ((IIndexMacro)macro).getFileLocation()
- : null;
- }
-
- public IMacroBinding getBinding() {
- return bind;
- }
-
- public void setBinding(IMacroBinding b) {
- this.bind = b;
- }
-
- }
-
- protected static class _ObjectMacroDefinition extends _MacroDefinition
- implements _IPreprocessorDirective {
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- * @param name
- * TODO
- * @param expansion
- * TODO
- */
- public _ObjectMacroDefinition(_CompositeContext parent,
- int startOffset, int endOffset, char[] name, int nameOffset,
- char[] expansion) {
- super(parent, startOffset, endOffset, name, nameOffset, expansion);
- }
-
- public _ObjectMacroDefinition(_CompositeContext parent,
- int startOffset, int endOffset, char[] name, int nameOffset,
- IMacro macro) {
- super(parent, startOffset, endOffset, name, nameOffset, macro);
- }
-
- }
-
- protected static class _FunctionMacroDefinition extends _MacroDefinition
- implements _IPreprocessorDirective {
-
- private final char[][] parms;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- * @param parameters
- */
- public _FunctionMacroDefinition(_CompositeContext parent,
- int startOffset, int endOffset, char[] name, int nameOffset,
- char[] expansion, char[][] parameters) {
- super(parent, startOffset, endOffset, name, nameOffset, expansion);
- this.parms = parameters;
- }
-
- public _FunctionMacroDefinition(_CompositeContext parent,
- int startOffset, int endOffset, char[] name, int nameOffset,
- IMacro macro, char[][] parameters) {
- super(parent, startOffset, endOffset, name, nameOffset, macro);
- this.parms = parameters;
- }
-
- public char[][] getParms() {
- return parms;
- }
- }
-
- protected static class _Problem extends _Context {
- public final IASTProblem problem;
-
- /**
- * @param parent
- * @param startOffset
- * @param endOffset
- */
- public _Problem(_CompositeContext parent, int startOffset,
- int endOffset, IASTProblem problem) {
- super(parent, startOffset, endOffset);
- this.problem = problem;
- }
-
- }
-
- protected class _MacroExpansion extends _CompositeContext {
- public final IMacroDefinition definition;
- private IASTName expansionName;
-
- public _MacroExpansion(_CompositeContext parent, int startOffset,
- int endOffset, IMacroDefinition definition) {
- super(parent, startOffset, endOffset);
- this.definition = definition;
- }
-
- public IASTName getName()
- {
- if( expansionName == null )
- {
- expansionName = new ASTMacroName( definition.getName() );
- expansionName.setParent( rootNode );
- expansionName.setPropertyInParent( IASTTranslationUnit.EXPANSION_NAME );
- ((ASTNode)expansionName).setOffsetAndLength(context_directive_start, getDirectiveLength());
- }
- return expansionName;
- }
- }
-
- protected class _ObjectMacroExpansion extends _MacroExpansion {
-
- public _ObjectMacroExpansion(_CompositeContext parent, int startOffset,
- int endOffset, IMacroDefinition definition) {
- super(parent, startOffset, endOffset, definition);
- }
-
- }
-
- protected class _FunctionMacroExpansion extends _MacroExpansion {
- public final char[][] args;
- public final char[][] actArgs;
-
-
- public _FunctionMacroExpansion(_CompositeContext parent,
- int startOffset, int endOffset, IMacroDefinition definition,
- char[][] args, char[][] actParameters) {
- super(parent, startOffset, endOffset, definition);
- this.args = args;
- this.actArgs = actParameters;
- }
-
- }
-
- protected _TranslationUnit tu;
-
- protected _CompositeContext currentContext;
-
- private static final IASTProblem[] EMPTY_PROBLEMS_ARRAY = new IASTProblem[0];
-
- private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
-
- private static final IASTPreprocessorMacroDefinition[] EMPTY_MACRO_DEFINITIONS_ARRAY = new IASTPreprocessorMacroDefinition[0];
-
- private static final IASTPreprocessorIncludeStatement[] EMPTY_INCLUDES_ARRAY = new IASTPreprocessorIncludeStatement[0];
-
- private static final IASTPreprocessorStatement[] EMPTY_PREPROCESSOR_ARRAY = new IASTPreprocessorStatement[0];
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getMacroDefinitions()
- */
- public IASTPreprocessorMacroDefinition[] getMacroDefinitions() {
- int size = collectContexts(V_MACRODEFS, tu, null, 0);
- if (size == 0)
- return EMPTY_MACRO_DEFINITIONS_ARRAY;
- _Context[] contexts = new _Context[size];
- collectContexts(V_MACRODEFS, tu, contexts, 0);
-
- IASTPreprocessorMacroDefinition[] result = new IASTPreprocessorMacroDefinition[contexts.length];
- for (int i = 0; i < contexts.length; ++i)
- result[i] = createASTMacroDefinition((_MacroDefinition) contexts[i]);
-
-
- return result;
- }
-
- public IASTPreprocessorMacroDefinition[] getBuiltinMacroDefinitions() {
- IMacroDefinition[] mdefs= tu.getBuiltinMacroDefinitions();
- if (mdefs.length == 0)
- return EMPTY_MACRO_DEFINITIONS_ARRAY;
- ArrayList result= new ArrayList(mdefs.length);
- for (int i = 0; i < mdefs.length; i++) {
- IMacroDefinition mdef = mdefs[i];
- if (mdef instanceof _MacroDefinition) {
- result.add(createASTMacroDefinition((_MacroDefinition) mdef));
- }
- }
- return (IASTPreprocessorMacroDefinition[]) result.toArray(new IASTPreprocessorMacroDefinition[result.size()]);
- }
-
- public IMacroBinding resolveBindingForMacro(char[] name, int offset ) {
- _Context search = findContextForOffset( offset );
- IMacroDefinition macroDefinition = null;
- if (search instanceof _MacroDefinition) {
- _MacroDefinition macroDef = (_MacroDefinition) search;
- if( CharArrayUtils.equals( name, macroDef.name) && offset == macroDef.nameOffset )
- macroDefinition = macroDef;
- }
- else if (search instanceof _MacroExpansion ) {
- _MacroExpansion expansion = (_MacroExpansion) search;
- macroDefinition = expansion.definition;
- }
- if( macroDefinition == null )
- return null;
- if( macroDefinition.getBinding() == null )
- macroDefinition.setBinding( new MacroBinding( name, rootNode.getScope(), macroDefinition ) );
- return macroDefinition.getBinding();
- }
-
- /**
- * @param d
- * @return
- */
- private IASTPreprocessorMacroDefinition createASTMacroDefinition(
- _MacroDefinition d) {
- IASTPreprocessorMacroDefinition r = null;
- if (d instanceof _FunctionMacroDefinition) {
- IASTPreprocessorFunctionStyleMacroDefinition f = new ASTFunctionMacro();
- char[][] parms = ((_FunctionMacroDefinition) d).getParms();
- for (int j = 0; j < parms.length; ++j) {
- IASTFunctionStyleMacroParameter parm = new ASTFunctionMacroParameter();
- parm.setParameter(new String(parms[j]));
- f.addParameter(parm);
- parm.setParent(f);
- parm
- .setPropertyInParent(IASTPreprocessorFunctionStyleMacroDefinition.PARAMETER);
- }
- r = f;
- }
- else {
- r = new ASTObjectMacro();
- }
-
- IASTName name = new ASTMacroName(d.name, d.getFileLocation());
- name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME);
- name.setParent(r);
- ((ASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length);
- r.setName(name);
- r.setExpansion(new String(d.getExpansion()));
- ((ASTNode) r).setOffsetAndLength(d.context_directive_start, d.getDirectiveLength());
- d.astNode = r;
- r.setParent(rootNode);
- r.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
-
- return r;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getIncludeDirectives()
- */
- public IASTPreprocessorIncludeStatement[] getIncludeDirectives() {
- int size = collectContexts(V_INCLUDE_DIRECTIVES, tu, null, 0);
- if (size == 0)
- return EMPTY_INCLUDES_ARRAY;
- _Context[] contexts = new _Context[size];
- collectContexts(V_INCLUDE_DIRECTIVES, tu, contexts, 0);
- IASTPreprocessorIncludeStatement[] result = new IASTPreprocessorIncludeStatement[size];
- for (int i = 0; i < size; ++i)
- result[i] = (IASTPreprocessorIncludeStatement)createPreprocessorStatement(contexts[i]);
-
- return result;
- }
-
- /**
- * @param inc
- * @return
- */
- private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) {
- ASTInclusionStatement result = new ASTInclusionStatement(inc.reader.filename);
- result.setOffsetAndLength(inc.context_directive_start, inc.getDirectiveLength());
- result.startOffset = inc.getContextStart();
- result.endOffset = inc.context_directive_end;
- ASTIncludeName name= new ASTIncludeName(inc.fName);
- name.setPropertyInParent(IASTPreprocessorIncludeStatement.INCLUDE_NAME);
- name.setParent(result);
- name.setOffsetAndLength(inc.fNameOffset, inc.fNameEndOffset-inc.fNameOffset);
- result.setName(name);
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- result.setSystemInclude(inc.fSystemInclude);
- result.setActive(true);
- result.setResolved(true);
- return result;
- }
-
- private IASTPreprocessorIncludeStatement createASTInclusion(_Include inc) {
- ASTInclusionStatement result = new ASTInclusionStatement(inc.fPath);
- result.setOffsetAndLength(inc.context_directive_start, inc.getDirectiveLength());
- result.startOffset = inc.getContextStart();
- result.endOffset = inc.context_directive_end;
- ASTIncludeName name= new ASTIncludeName(inc.fName);
- name.setPropertyInParent(IASTPreprocessorIncludeStatement.INCLUDE_NAME);
- name.setParent(result);
- name.setOffsetAndLength(inc.fNameOffset, inc.fNameEndOffset-inc.fNameOffset);
- result.setName(name);
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- result.setSystemInclude(inc.fSystemInclude);
- result.setActive(inc.fIsActive);
- result.setResolved(inc.fIsResolved);
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getAllPreprocessorStatements()
- */
- public IASTPreprocessorStatement[] getAllPreprocessorStatements() {
- int size = collectContexts(V_PREPROCESSOR, tu, null, 0);
- if (size == 0)
- return EMPTY_PREPROCESSOR_ARRAY;
- _Context[] contexts = new _Context[size];
- collectContexts(V_PREPROCESSOR, tu, contexts, 0);
- IASTPreprocessorStatement[] result = new IASTPreprocessorStatement[size];
- for (int i = 0; i < size; ++i)
- result[i] = createPreprocessorStatement(contexts[i]);
-
- return result;
- }
-
- private IASTPreprocessorStatement createPreprocessorStatement(
- _Context context) {
- IASTPreprocessorStatement result = null;
- if (context instanceof _Inclusion)
- result = createASTInclusion(((_Inclusion) context));
- else if (context instanceof _Include)
- result = createASTInclusion(((_Include) context));
- else if (context instanceof _MacroDefinition)
- result = createASTMacroDefinition((_MacroDefinition) context);
- else if (context instanceof _Undef)
- result = createASTUndef((_Undef) context);
- else if (context instanceof _Pragma)
- result = createASTPragma((_Pragma) context);
- else if (context instanceof _Error)
- result = createASTError((_Error) context);
- else if (context instanceof _Warning)
- result = createASTWarning((_Warning) context);
- else if (context instanceof _If)
- result = createASTIf((_If) context);
- else if (context instanceof _Ifdef)
- result = createASTIfdef((_Ifdef) context);
- else if (context instanceof _Ifndef)
- result = createASTIfndef((_Ifndef) context);
- else if (context instanceof _Else)
- result = createASTElse((_Else) context);
- else if (context instanceof _Elif)
- result = createASTElif((_Elif) context);
- else if (context instanceof _Endif)
- result = createASTEndif((_Endif) context);
-
- return result;
- }
-
- /**
- * @param endif
- * @return
- */
- private IASTPreprocessorStatement createASTEndif(_Endif endif) {
- IASTPreprocessorEndifStatement result = new ASTEndif();
- ((ASTNode) result).setOffsetAndLength(endif.context_directive_start, endif.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param elif
- * @return
- */
- private IASTPreprocessorStatement createASTElif(_Elif elif) {
- IASTPreprocessorElifStatement result = new ASTElif(elif.taken, elif.condition);
- ((ASTNode) result).setOffsetAndLength(elif.context_directive_start, elif.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param else1
- * @return
- */
- private IASTPreprocessorStatement createASTElse(_Else e) {
- IASTPreprocessorElseStatement result = new ASTElse(e.taken);
- ((ASTNode) result).setOffsetAndLength(e.context_directive_start, e.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param ifndef
- * @return
- */
- private IASTPreprocessorStatement createASTIfndef(_Ifndef ifndef) {
- IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken, ifndef.condition);
- ((ASTNode) result).setOffsetAndLength(ifndef.context_directive_start, ifndef.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param ifdef
- * @return
- */
- private IASTPreprocessorStatement createASTIfdef(_Ifdef ifdef) {
- IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken, ifdef.condition);
- ((ASTNode) result).setOffsetAndLength(ifdef.context_directive_start, ifdef.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param if1
- * @return
- */
- private IASTPreprocessorStatement createASTIf(_If i) {
- IASTPreprocessorIfStatement result = new ASTIf(i.taken, i.condition);
- ((ASTNode) result).setOffsetAndLength(i.context_directive_start, i.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param error
- * @return
- */
- private IASTPreprocessorStatement createASTError(_Error error) {
- IASTPreprocessorErrorStatement result = new ASTError(error.msg);
- ((ASTNode) result).setOffsetAndLength(error.context_directive_start, error.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param warning
- * @return
- */
- private IASTPreprocessorStatement createASTWarning(_Warning warning) {
- IASTPreprocessorErrorStatement result = new ASTWarning(warning.msg);
- ((ASTNode) result).setOffsetAndLength(warning.context_directive_start, warning.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param pragma
- * @return
- */
- private IASTPreprocessorStatement createASTPragma(_Pragma pragma) {
- IASTPreprocessorPragmaStatement result = new ASTPragma(pragma.msg);
- ((ASTNode) result).setOffsetAndLength(pragma.getDirectiveStart(), pragma.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /**
- * @param undef
- * @return
- */
- private IASTPreprocessorStatement createASTUndef(_Undef undef) {
- IASTPreprocessorUndefStatement result = new ASTUndef(undef.getName());
- ((ASTNode) result).setOffsetAndLength(undef.getDirectiveStart(), undef.getDirectiveLength());
- result.setParent(rootNode);
- result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getLocations(int,
- * int)
- */
- public IASTNodeLocation[] getLocations(int offset, int length) {
- if (tu == null)
- return EMPTY_LOCATION_ARRAY;
- _Context c = findContextForOffset(offset);
- if( c == null )
- return EMPTY_LOCATION_ARRAY;
- if (offset + length <= c.context_ends) {
- if (c instanceof _CompositeContext) {
- _Context[] subz = ((_CompositeContext) c).getSubContexts();
- boolean foundNested = findNested( subz, offset, length);
- if (!foundNested)
- return createSoleLocationArray(c, offset, length);
- } else
- return createSoleLocationArray(c, offset, length);
- }
- // check to see if we spill over into other
- _WeightedContext[] extraContexts = findAllContextsForLength(offset,
- length);
- if (extraContexts.length == 0)
- return EMPTY_LOCATION_ARRAY;
- if (extraContexts.length == 1)
- return createSoleLocationArray(extraContexts[0].context, offset,
- length);
-
- return createMegaLocationArray(offset, length, extraContexts);
- }
-
- private boolean findNested(_Context[] subz, int offset, int length){
- final int offset2= offset+length-1;
- int left = 0;
- int right = subz.length-1;
- int middle = 0;
- _Context sub = null;
-
- while( left <= right ){
- middle = (left+right)/2;
- sub = subz[middle];
- if (offset2 < sub.context_directive_start) {
- right= middle-1;
- }
- else if (offset >= sub.context_ends) {
- left= middle+1;
- }
- else {
- return true;
- }
- }
-
- return false;
- }
-
- private IASTNodeLocation[] createMegaLocationArray(int offset, int length,
- _WeightedContext[] contexts) {
- IASTNodeLocation[] result = new IASTNodeLocation[contexts.length];
- int currentOffset = offset;
- for (int i = 0; i < contexts.length; ++i) {
- final IASTNodeLocation location = createSoleLocation(
- contexts[i].context, currentOffset, contexts[i].count);
- result[i] = location;
- currentOffset += contexts[i].count;
- }
- return (IASTNodeLocation[]) ArrayUtil.removeNulls( IASTNodeLocation.class, result );
- }
-
- protected static final class _WeightedContext {
- public final _Context context;
-
- public final int count;
-
- public _WeightedContext(_Context c, int currentCount) {
- context = c;
- count = currentCount;
- }
-
- }
-
- protected _WeightedContext[] findAllContextsForLength(int offset, int length) {
- _WeightedContext[] result = new _WeightedContext[2];
- _Context cc = null;
- int currentCount = 0;
- length= Math.min(tu.context_ends, length);
- for (int i = offset; i < offset + length; ++i) {
- _Context r = tu.findContextContainingOffset(i);
- if (cc == null) {
- cc = r;
- currentCount = 1;
- } else if (cc == r)
- ++currentCount;
- else if (cc instanceof _MacroExpansion && r.hasAncestor(cc))
- ++currentCount;
- else {
- result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result,
- new _WeightedContext(cc, currentCount));
- cc = r;
- currentCount = 1;
- }
- }
- result = (_WeightedContext[]) ArrayUtil.append(_WeightedContext.class, result,
- new _WeightedContext(cc, currentCount));
- return (_WeightedContext[]) ArrayUtil.trim(_WeightedContext.class, result);
- }
-
- protected IASTNodeLocation createSoleLocation(_Context c, int offset,
- int length) {
-
- if (c instanceof _IPreprocessorDirective || c instanceof _Problem ) {
- if (c.containsInDirective(offset, length)) {
- _CompositeContext parent = c.parent;
- if (parent instanceof _CompositeFileContext) {
- _CompositeFileContext fc = (_CompositeFileContext) parent;
- return new FileLocation(fc.reader.filename, fc.getOffsetInContext(offset), length);
- }
- }
- }
- if (c instanceof _CompositeFileContext) {
- _CompositeFileContext cfc = (_CompositeFileContext) c;
- return new FileLocation(cfc.reader.filename, cfc.getOffsetInContext(offset), length);
- }
- if (c instanceof _MacroExpansion) {
- _MacroExpansion expansion = (_MacroExpansion) c;
- if (c.containsInDirective(offset, length)) {
- _CompositeContext parent = c.parent;
- if (parent instanceof _CompositeFileContext) {
- _CompositeFileContext fc = (_CompositeFileContext) parent;
- return new FileLocation(fc.reader.filename, fc.getOffsetInContext(offset), length);
- }
- }
-
-
- IASTNodeLocation[] locations = createSoleLocationArray(c.parent, c.getDirectiveStart(), c.getDirectiveLength());
- IASTPreprocessorMacroDefinition definition = null;
- _MacroDefinition d = (_MacroDefinition) expansion.definition;
- if (d.astNode != null)
- definition = d.astNode;
- else {
- IASTPreprocessorMacroDefinition astNode = createASTMacroDefinition(d);
- d.astNode = astNode;
- definition = astNode;
- }
-
- if (c instanceof _FunctionMacroExpansion) {
- _FunctionMacroExpansion fe = (_FunctionMacroExpansion) c;
- return new FunctionMacroExpansionLocation(definition, locations, fe.getOffsetInContext(offset), length, fe.actArgs);
- }else {
- _MacroExpansion me = (_MacroExpansion) c;
- return new MacroExpansionLocation(definition, locations,
- me.getOffsetInContext(offset), length);
- }
- }
- return null;
- }
-
-
- /**
- * @param c
- * @param offset
- * @param length
- * @return
- */
- protected IASTNodeLocation[] createSoleLocationArray(_Context c,
- int offset, int length) {
- IASTNodeLocation value = createSoleLocation(c, offset, length);
- if (value == null)
- return EMPTY_LOCATION_ARRAY;
- IASTNodeLocation[] result = new IASTNodeLocation[1];
- result[0] = value;
- return result;
- }
-
- protected _Context findContextForOffset(int offset) {
- return tu.findContextContainingOffset(offset);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startTranslationUnit()
- */
- public void startTranslationUnit(CodeReader tu_reader) {
- tu.reader = tu_reader;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endTranslationUnit(int)
- */
- public void endTranslationUnit(int offset) {
- tu.context_ends = offset;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#startInclusion(char[],
- * int)
- */
- public void startInclusion(CodeReader reader, int offset, int endOffset, int nameOffset, int nameEndoffset, char[] name, boolean systemInclude) {
- _Inclusion i = new _Inclusion(currentContext, reader, offset, endOffset, nameOffset, nameEndoffset, name, systemInclude);
- currentContext.addSubContext(i);
- currentContext = i;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#endInclusion(char[],
- * int)
- */
- public void endInclusion(CodeReader reader, int offset) {
- if( currentContext instanceof _Inclusion &&
- ((_Inclusion)currentContext).reader == reader )
- {
- ((_Inclusion) currentContext).context_ends = offset;
- currentContext = currentContext.getParent();
- return;
- }
-
- _CompositeContext test = currentContext;
- while( ( test = test.getParent() ) != tu )
- {
- if( test instanceof _Inclusion &&
- ((_Inclusion)test).reader == reader )
- {
- currentContext = test;
- ((_Inclusion) currentContext).context_ends = offset;
- currentContext = currentContext.getParent();
- return;
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterObjectStyleMacroExpansion(char[],
- * char[], int)
- */
- public void startObjectStyleMacroExpansion(IMacroDefinition macro,
- int startOffset, int endOffset) {
- _ObjectMacroExpansion context = new _ObjectMacroExpansion(
- currentContext, startOffset, endOffset, macro);
- currentContext.addSubContext(context);
- currentContext = context;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitObjectStyleMacroExpansion(char[],
- * int)
- */
- public void endObjectStyleMacroExpansion(IMacroDefinition macro, int offset) {
- if( currentContext instanceof _MacroExpansion && ((_MacroExpansion)currentContext).definition == macro )
- {
- ((_ObjectMacroExpansion) currentContext).context_ends = offset;
- currentContext = currentContext.getParent();
- return;
- }
-
- _CompositeContext test = currentContext;
- while( ( test = test.getParent() ) != tu )
- {
- if( test instanceof _MacroExpansion && ((_MacroExpansion)test).definition == macro )
- {
- currentContext = test;
- ((_ObjectMacroExpansion) currentContext).context_ends = offset;
- currentContext = currentContext.getParent();
- return;
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#enterFunctionStyleExpansion(char[],
- * char[][], char[], int)
- */
- public void startFunctionStyleExpansion(IMacroDefinition macro,
- char[][] parameters, int startOffset, int endOffset, char[][] actParameters) {
- _FunctionMacroExpansion context = new _FunctionMacroExpansion(
- currentContext, startOffset, endOffset, macro, parameters, actParameters);
- currentContext.addSubContext(context);
- currentContext = context;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#exitFunctionStyleExpansion(char[],
- * int)
- */
- public void endFunctionStyleExpansion(IMacroDefinition macro, int offset) {
- if( currentContext instanceof _MacroExpansion && ((_MacroExpansion)currentContext).definition == macro )
- {
- ((_FunctionMacroExpansion) currentContext).context_ends = offset;
- currentContext = currentContext.getParent();
- return;
- }
-
- _CompositeContext test = currentContext;
- while( ( test = test.getParent() ) != tu )
- {
- if( test instanceof _MacroExpansion && ((_MacroExpansion)test).definition == macro )
- {
- currentContext = test;
- ((_FunctionMacroExpansion) currentContext).context_ends = offset;
- currentContext = currentContext.getParent();
- return;
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineObjectStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro,
- * int, int, int, int)
- */
- public IMacroDefinition defineObjectStyleMacro(ObjectStyleMacro m,
- int startOffset, int nameOffset, int nameEndOffset, int endOffset) {
- _ObjectMacroDefinition objectMacroDefinition = new _ObjectMacroDefinition(
- currentContext, startOffset, endOffset, m.name, nameOffset,
- m.getExpansion());
- currentContext.addSubContext(objectMacroDefinition);
- return objectMacroDefinition;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#defineFunctionStyleMacro(org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro,
- * int, int, int, int)
- */
- public IMacroDefinition defineFunctionStyleMacro(FunctionStyleMacro m,
- int startOffset, int nameOffset, int nameEndOffset, int endOffset) {
- final _FunctionMacroDefinition functionMacroDefinition = new _FunctionMacroDefinition(
- currentContext, startOffset, endOffset, m.name, nameOffset,
- m.getExpansion(), removeNullArguments(m.getOriginalParameters()));
- currentContext.addSubContext(functionMacroDefinition);
- return functionMacroDefinition;
- }
-
- /**
- * @param arglist
- * @return
- */
- private char[][] removeNullArguments(char[][] arglist) {
- int nullCount = 0;
- for (int i = 0; i < arglist.length; ++i)
- if (arglist[i] == null)
- ++nullCount;
- if (nullCount == 0)
- return arglist;
- char[][] old = arglist;
- int newSize = old.length - nullCount;
- arglist = new char[newSize][];
- for (int i = 0; i < newSize; ++i)
- arglist[i] = old[i];
- return arglist;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIf(int,
- * int)
- */
- public void encounterPoundIf(int startOffset, int endOffset, boolean taken, char[] condtion) {
- currentContext.addSubContext(new _If(currentContext, startOffset,
- endOffset, taken, condtion));
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundPragma(int,
- * int)
- */
- public void encounterPoundPragma(int startOffset, int endOffset, char[] msg) {
- currentContext.addSubContext(new _Pragma(currentContext, startOffset,
- endOffset, msg));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundError(int,
- * int)
- */
- public void encounterPoundError(int startOffset, int endOffset, char[] msg) {
- currentContext.addSubContext(new _Error(currentContext, startOffset,
- endOffset, msg));
- }
-
- /*
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundWarning(int, int)
- */
- public void encounterPoundWarning(int startOffset, int endOffset, char[] msg) {
- currentContext.addSubContext(new _Warning(currentContext, startOffset,
- endOffset, msg));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfdef(int,
- * int)
- */
- public void encounterPoundIfdef(int startOffset, int endOffset,
- boolean taken, char[] condition) {
- currentContext.addSubContext(new _Ifdef(currentContext, startOffset,
- endOffset, taken, condition));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundUndef(int,
- * int)
- */
- public void encounterPoundUndef(int startOffset, int endOffset,
- char[] symbol, int nameOffset, IMacroDefinition macroDefinition) {
- currentContext.addSubContext(new _Undef(currentContext, startOffset,
- endOffset, symbol, nameOffset, macroDefinition));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElse(int,
- * int)
- */
- public void encounterPoundElse(int startOffset, int endOffset, boolean taken) {
- currentContext.addSubContext(new _Else(currentContext, startOffset,
- endOffset, taken));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundElif(int,
- * int)
- */
- public void encounterPoundElif(int startOffset, int endOffset, boolean taken, char[] condition) {
- currentContext.addSubContext(new _Elif(currentContext, startOffset,
- endOffset, taken, condition));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundEndIf(int,
- * int)
- */
- public void encounterPoundEndIf(int startOffset, int endOffset) {
- currentContext.addSubContext(new _Endif(currentContext, startOffset,
- endOffset));
- }
-
- /*
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundInclude(int, int, int, int, char[], boolean, boolean)
- */
- public void encounterPoundInclude(int startOffset, int nameOffset, int nameEndOffset, int endOffset,
- char[] name, boolean systemInclude, boolean active) {
- encounterPoundInclude(startOffset, nameOffset, nameEndOffset, endOffset, name, null, systemInclude, active);
- }
-
- public void encounterPoundInclude(int startOffset, int nameOffset, int nameEndOffset, int endOffset,
- char[] name, char[] path, boolean systemInclude, boolean active) {
- currentContext.addSubContext(new _Include(currentContext, startOffset, endOffset, nameOffset, nameEndOffset, name, path, systemInclude, active, path != null));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getTranslationUnitPath()
- */
- public String getTranslationUnitPath() {
- return new String(tu.reader.filename);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#cleanup()
- */
- public void cleanup() {
- tu = null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getScannerProblems()
- */
- public IASTProblem[] getScannerProblems() {
- int size = LocationMap.collectContexts(V_PROBLEMS, tu, null, 0);
- if (size == 0)
- return EMPTY_PROBLEMS_ARRAY;
- _Context[] contexts = new _Context[size];
- LocationMap.collectContexts(V_PROBLEMS, tu, contexts, 0);
- IASTProblem[] result = new IASTProblem[size];
- for (int i = 0; i < size; ++i) {
- result[i] = ((_Problem) contexts[i]).problem;
- result[i].setParent(rootNode);
- result[i].setPropertyInParent(IASTTranslationUnit.SCANNER_PROBLEM);
- }
-
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterIProblem(org.eclipse.cdt.core.parser.IProblem)
- */
- public void encounterProblem(IASTProblem problem) {
- ScannerASTProblem p = (ScannerASTProblem) problem;
- int offset= p.getOffset();
- int endoffset= offset + p.getLength();
- _Problem pr = new _Problem(currentContext, offset, endoffset, problem);
- currentContext.addSubContext(pr);
- }
-
- protected static final int V_ALL = 1;
-
- protected static final int V_INCLUSIONS = 2;
-
- protected static final int V_PROBLEMS = 3;
-
- protected static final int V_MACRODEFS = 4;
-
- protected static final int V_PREPROCESSOR = 5;
-
- protected static final int V_MACRODEFSUNDEFS = 6;
-
- protected static final int V_INCLUDE_DIRECTIVES = 7;
-
- private static final char[] EMPTY_CHAR_ARRAY = "".toCharArray(); //$NON-NLS-1$
- private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
-
-
- protected IASTTranslationUnit rootNode;
-
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
-
-
- protected static int collectContexts(int key, _Context source,
- _Context[] result, int s) {
- int startAt = s;
- int count = 0;
- switch (key) {
- case V_ALL:
- if (result != null)
- result[startAt++] = source;
- ++count;
- break;
- case V_INCLUSIONS:
- if (source instanceof _Inclusion) {
- if (result != null)
- result[startAt++] = source;
- ++count;
- }
- break;
- case V_INCLUDE_DIRECTIVES:
- if (source instanceof _IPreprocessorIncludeDirective) {
- if (result != null)
- result[startAt++] = source;
- ++count;
- }
- break;
- case V_PROBLEMS:
- if (source instanceof _Problem) {
- if (result != null)
- result[startAt++] = source;
- ++count;
- }
- break;
- case V_MACRODEFS:
- if (source instanceof _MacroDefinition) {
- if (result != null)
- result[startAt++] = source;
- ++count;
- }
- break;
- case V_PREPROCESSOR:
- if (source instanceof _IPreprocessorDirective) {
- if (result != null)
- result[startAt++] = source;
- ++count;
- }
- break;
- case V_MACRODEFSUNDEFS:
- if (source instanceof _MacroDefinition || source instanceof _Undef) {
- if (result != null)
- result[startAt++] = source;
- ++count;
- }
- break;
- }
- if (source instanceof _CompositeContext) {
- _Context[] l = ((_CompositeContext) source).getSubContexts();
- for (int i = 0; i < l.length; ++i) {
- int value = collectContexts(key, l[i], result, startAt);
- count += value;
- startAt += value;
- }
- }
- return count;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getSignature(org.eclipse.cdt.core.dom.ast.IASTNodeLocation[])
- */
- public char[] getUnpreprocessedSignature(IASTNodeLocation[] locations) {
-
- switch (locations.length) {
- case 1:
- if (locations[0] instanceof IASTFileLocation) {
- IASTNodeLocation nodeLocation = locations[0];
- char[] name = ((IASTFileLocation) nodeLocation).getFileName()
- .toCharArray();
- if (readerCompatable(nodeLocation, tu.reader, name))
- return CharArrayUtils.extract(tu.reader.buffer,
- nodeLocation.getNodeOffset(), nodeLocation
- .getNodeLength());
-
- int size = collectContexts(V_INCLUSIONS, tu, null, 0);
- if (size == 0)
- return EMPTY_CHAR_ARRAY;
- _Context[] inclusions = new _Context[size];
- collectContexts(V_INCLUSIONS, tu, inclusions, 0);
- for (int i = 0; i < size; ++i) {
- _Inclusion inc = (_Inclusion) inclusions[i];
- if (readerCompatable(nodeLocation, inc.reader, name))
- return CharArrayUtils.extract(inc.reader.buffer,
- nodeLocation.getNodeOffset(), nodeLocation
- .getNodeLength());
- }
- }
- return EMPTY_CHAR_ARRAY;
- case 0:
- return EMPTY_CHAR_ARRAY;
- default:
- // TODO
- return EMPTY_CHAR_ARRAY;
- }
- }
-
- /**
- * @param nodeLocation
- * @param reader
- * @param name
- * @return
- */
- private boolean readerCompatable(IASTNodeLocation nodeLocation,
- CodeReader reader, char[] name) {
- if (!CharArrayUtils.equals(reader.filename, name))
- return false;
- if (nodeLocation.getNodeOffset() > reader.buffer.length)
- return false;
- if (nodeLocation.getNodeOffset() + nodeLocation.getNodeLength() > reader.buffer.length)
- return false;
- return true;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog#encounterPoundIfndef(int,
- * int, boolean)
- */
- public void encounterPoundIfndef(int startOffset, int endOffset,
- boolean taken, char[] condition) {
- currentContext.addSubContext(new _Ifndef(currentContext, startOffset,
- endOffset, taken, condition));
- }
-
- _Inclusion findInclusion(_CompositeContext context, String path) {
- _Inclusion foundContext = null;
- _Context[] contexts = context.getSubContexts();
- _Inclusion tempContext= null;
- for (int i = 0; foundContext == null && i < contexts.length; i++) {
- if (contexts[i] instanceof _Inclusion) {
- tempContext = (_Inclusion) contexts[i];
-
- // check if the file matches the #include
- if (CharArrayUtils.equals(
- tempContext.reader.filename, path
- .toCharArray())) {
- foundContext = tempContext;
- break;
- }
- foundContext = findInclusion(tempContext, path);
- }
- }
-
- return foundContext;
- }
-
- private ASTPreprocessorSelectionResult getPreprocessorNode(
- int globalOffset, int length, _Context startContext)
- throws InvalidPreprocessorNodeException {
- IASTNode result = null;
- if (!(startContext instanceof _CompositeContext))
- throw new InvalidPreprocessorNodeException(NOT_VALID_MACRO,
- globalOffset);
- _Context[] contexts = ((_CompositeContext) startContext).getSubContexts();
-
- // check if a macro in the location map is the selection
- for (int i = 0; result == null && i < contexts.length; i++) {
- _Context context = contexts[i];
-
- if (globalOffset < context.getDirectiveStart()) {
- break;
- }
-
- // check if the _Context is the selection
- if (globalOffset == context.getDirectiveStart()) {
- if( context instanceof _MacroExpansion) {
- _MacroExpansion expansion = (_MacroExpansion)context;
- if( expansion.definition.getName().length == length )
- result = expansion.getName();
- }
- else if (length == context.getDirectiveLength()) {
- result = createPreprocessorStatement(context);
- }
- }
-
- // check if a sub node of the macro is the selection // TODO
- // determine how this can be kept in sync with logic in
- // getAllPreprocessorStatements (i.e. 1:1 mapping)
- if (context.containsInDirective(globalOffset, length)) {
- if (context instanceof _MacroDefinition) {
- _MacroDefinition macroDefinition = (_MacroDefinition) context;
- if (globalOffset == macroDefinition.nameOffset
- && length == macroDefinition.name.length) {
- result = createASTMacroDefinition(macroDefinition).getName();
- }
- }
- }
-
- // if offset is past the _Context then increment globalOffset
- if (globalOffset >= context.getContextStart()) {
- globalOffset += context.getContextLength();
- }
- }
-
- return new ASTPreprocessorSelectionResult(result, globalOffset);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver#getPreprocessorNode(int,
- * int)
- */
- public ASTPreprocessorSelectionResult getPreprocessorNode(String path,
- int offset, int length) throws InvalidPreprocessorNodeException {
- ASTPreprocessorSelectionResult result = null;
-
- int globalOffset = 0;
- _Context foundContext = tu;
-
- // is the selection in TU or an #include else it's an exception
- if (CharArrayUtils.equals(tu.reader.filename, path.toCharArray())) {
- globalOffset = offset; // in TU so start at the real offset
- } else {
- foundContext = findInclusion(tu, path);
-
- if (foundContext == null) {
- throw new InvalidPreprocessorNodeException(TU_INCLUDE_NOT_FOUND, globalOffset);
- } else if (foundContext instanceof _Inclusion) {
- globalOffset = foundContext.getContextStart() + offset;
- }
- }
-
- result = getPreprocessorNode(globalOffset, length, foundContext);
-
- return result;
- }
-
- public void setRootNode(IASTTranslationUnit root) {
- this.rootNode = root;
- }
-
- public IASTFileLocation flattenLocations(IASTNodeLocation[] nodeLocations) {
- if (nodeLocations == null)
- return null;
- if (nodeLocations.length == 0)
- return null;
- if (nodeLocations.length == 1
- && nodeLocations[0] instanceof IASTFileLocation)
- return (IASTFileLocation) nodeLocations[0];
- IASTFileLocation[] result = new IASTFileLocation[nodeLocations.length];
- for (int i = 0; i < nodeLocations.length; ++i) {
- if (nodeLocations[i] != null)
- result[i] = nodeLocations[i].asFileLocation();
- }
- return flatten(result);
- }
-
- private IASTFileLocation flatten(IASTFileLocation[] result) {
- String filename = null;
- int offset = 0, length = 0;
- for (int i = 0; i < result.length; ++i) {
- if (i == 0) {
- offset = result[0].getNodeOffset();
- filename = result[0].getFileName();
- length = result[0].getNodeLength();
- } else {
- if( result[i] != null && !result[i].getFileName().equals( filename ) )
- return null;
- if( result[i].getNodeOffset() == result[i-1].getNodeOffset() )
- continue;
- if (result[i] != null
- && result[i].getNodeOffset() != (offset + length) )
- return null;
- if (result[i] != null)
- length += result[i].getNodeLength();
- }
- }
- return new FileLocation(filename.toCharArray(), offset, length);
- }
-
- public IASTName[] getReferences(IMacroBinding binding) {
- if( binding instanceof MacroBinding )
- {
- IMacroDefinition d = ((MacroBinding)binding).getDefinition();
- _Context [] r = findReferences( tu, d );
- return createNameArray( r );
- }
- return EMPTY_NAME_ARRAY;
- }
-
- private IASTName[] createNameArray(_Context[] r) {
- IASTName [] result = new IASTName[ r.length ];
- for( int i = 0; i < r.length; ++i )
- {
- IASTName n = null;
- if( r[i] instanceof _MacroExpansion )
- {
- n = ((_MacroExpansion)r[i]).getName();
- }
- else if( r[i] instanceof _Undef )
- {
- n = ((_Undef)r[i]).getName();
- createASTUndef( (_Undef) r[i] );
- }
- result[i] = n;
- }
- return result;
- }
-
- protected _Context [] findReferences(_CompositeContext c, IMacroDefinition d) {
- _Context [] results = new _Context[2];
- _Context [] subs = c.getSubContexts();
- for( int i = 0; i < subs.length; ++i )
- {
- if( subs[i] instanceof _MacroExpansion )
- {
- if( ((_MacroExpansion)subs[i]).definition == d )
- results = (_Context[]) ArrayUtil.append( _Context.class, results, subs[i] );
- }
- else if( subs[i] instanceof _Undef )
- {
- if( ((_Undef)subs[i]).macroDefn == d )
- results = (_Context[]) ArrayUtil.append( _Context.class, results, subs[i] );
- }
-
- if( subs[i] instanceof _CompositeContext )
- {
- _Context [] s = findReferences( (_CompositeContext) subs[i], d );
- if( s.length > 0 )
- results = (_Context[]) ArrayUtil.addAll( _Context.class, results, s );
- }
- }
- return (_Context[]) ArrayUtil.trim( _Context.class, results );
- }
-
- public IASTName[] getDeclarations(IMacroBinding binding) {
- if( binding instanceof MacroBinding )
- {
- IMacroDefinition d = ((MacroBinding)binding).getDefinition();
- if( d instanceof _MacroDefinition )
- return createNameArray( ((_MacroDefinition)d) );
- }
- return EMPTY_NAME_ARRAY;
- }
-
- private IASTName[] createNameArray(_MacroDefinition definition) {
- if( definition == null ) return EMPTY_NAME_ARRAY;
- IASTName [] result = new IASTName[1];
- if( definition.astNode == null )
- {
- IASTPreprocessorMacroDefinition astNode = createASTMacroDefinition(definition);
- definition.astNode = astNode;
- result[0] = definition.astNode.getName();
- }
- else
- {
- result[0] = definition.astNode.getName();
- }
- return result;
- }
-
- public IASTName[] getMacroExpansions() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public IDependencyTree getDependencyTree() {
- DependencyTree result = new DependencyTree(getTranslationUnitPath());
- buildDependencyTree( result, tu );
- return result;
- }
-
- protected void buildDependencyTree(IDependencyNodeHost result, _CompositeFileContext context) {
- _Context [] subs = context.getSubContexts();
- for( int i = 0; i < subs.length; ++i )
- {
- if( subs[i] instanceof _Inclusion )
- {
- IASTTranslationUnit.IDependencyTree.IASTInclusionNode node = createDepTreeNode( (_Inclusion)subs[i] );
- result.addInclusionNode( node );
- }
- }
- }
-
- private IASTInclusionNode createDepTreeNode(_Inclusion inclusion) {
- IASTPreprocessorIncludeStatement stmt = createASTInclusion( inclusion );
- InclusionNode node = new InclusionNode( stmt );
- buildDependencyTree(node, inclusion);
- return node;
- }
-
- public IMacroDefinition registerBuiltinObjectStyleMacro(ObjectStyleMacro macro) {
- IMacroDefinition result = new _ObjectMacroDefinition( tu, -1, -1, macro.name, -1, macro );
- tu.addBuiltinMacro( result );
- return result;
- }
-
- public IMacroDefinition registerBuiltinFunctionStyleMacro(FunctionStyleMacro macro) {
- IMacroDefinition result = new _FunctionMacroDefinition( tu, -1, -1, macro.name, -1, macro, removeNullArguments( macro.arglist ) );
- tu.addBuiltinMacro( result );
- return result;
- }
-
- public IMacroDefinition registerBuiltinDynamicFunctionStyleMacro(DynamicFunctionStyleMacro macro) {
- IMacroDefinition result = new _MacroDefinition( tu, -1, -1, macro.name, -1, macro.getExpansion() );
- tu.addBuiltinMacro( result );
- return result;
- }
-
- public IMacroDefinition registerBuiltinDynamicStyleMacro(DynamicStyleMacro macro) {
- IMacroDefinition result = new _MacroDefinition( tu, -1, -1, macro.name, -1, macro.execute() );
- tu.addBuiltinMacro( result );
- return result;
- }
-
- public String getContainingFilename(int offset) {
- _Context c = findContextForOffset(offset);
- if( c == null ) return EMPTY_STRING;
- if (c instanceof _Inclusion && c.containsInDirective(offset, 1)) {
- c = c.getParent();
- }
- _CompositeFileContext file = c.getContainingFileContext();
- if( file == null ) return EMPTY_STRING;
- return file.reader.getPath();
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroBinding.java
deleted file mode 100644
index 17a0f40f1c9..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroBinding.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.dom.ILinkage;
-import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.IMacroBinding;
-import org.eclipse.cdt.core.dom.ast.IScope;
-import org.eclipse.cdt.internal.core.dom.Linkage;
-import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap._FunctionMacroDefinition;
-import org.eclipse.core.runtime.PlatformObject;
-
-public class MacroBinding extends PlatformObject implements IMacroBinding {
-
- private final char[] name;
- private final IScope scope;
- private final IScannerPreprocessorLog.IMacroDefinition definition;
-
- public MacroBinding( char [] name, IScope scope, IScannerPreprocessorLog.IMacroDefinition definition )
- {
- this.name = name;
- this.scope = scope;
- this.definition = definition;
- }
-
- public String getName() {
- return new String( name );
- }
-
- public char[] getNameCharArray() {
- return name;
- }
-
- public IScope getScope() throws DOMException {
- return scope;
- }
-
- /**
- * @return Returns the definition.
- */
- public IScannerPreprocessorLog.IMacroDefinition getDefinition() {
- return definition;
- }
-
- public ILinkage getLinkage() {
- return Linkage.NO_LINKAGE;
- }
-
- public char[] getExpansion() {
- return definition.getExpansion();
- }
-
- public boolean isFunctionStyle() {
- return definition instanceof _FunctionMacroDefinition;
- }
-
- public char[][] getParameterList() {
- if (isFunctionStyle()) {
- return ((_FunctionMacroDefinition) definition).getParms();
- }
- return null;
- }
-
- public char[] getExpansionImage() {
- throw new UnsupportedOperationException();
- }
-
- public char[][] getParameterPlaceholderList() {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroExpansionToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroExpansionToken.java
deleted file mode 100644
index f101e655abf..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/MacroExpansionToken.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.parser.IToken;
-
-/**
- * @author Doug Schaefer
- */
-public class MacroExpansionToken implements IToken {
-
- public MacroExpansionToken() {
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getType()
- */
- public int getType() {
- return IToken.tMACROEXP;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getImage()
- */
- public String getImage() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getOffset()
- */
- public int getOffset() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getLength()
- */
- public int getLength() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getEndOffset()
- */
- public int getEndOffset() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getLineNumber()
- */
- public int getLineNumber() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getNext()
- */
- public IToken getNext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage(java.lang.String)
- */
- public void setImage(String i) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setNext(org.eclipse.cdt.core.parser.IToken)
- */
- public void setNext(IToken t) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setType(int)
- */
- public void setType(int i) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#looksLikeExpression()
- */
- public boolean looksLikeExpression() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#isPointer()
- */
- public boolean isPointer() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#isOperator()
- */
- public boolean isOperator() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#canBeAPrefix()
- */
- public boolean canBeAPrefix() {
- // TODO Auto-generated method stub
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getCharImage()
- */
- public char[] getCharImage() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage(char[])
- */
- public void setImage(char[] i) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getFilename()
- */
- public char[] getFilename() {
- return null;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java
deleted file mode 100644
index 986d9d42d81..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ObjectStyleMacro.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.internal.core.parser.scanner2.IScannerPreprocessorLog.IMacroDefinition;
-
-/**
- * @author Doug Schaefer
- */
-public class ObjectStyleMacro implements IMacro {
-
- public char[] name;
- protected char[] expansion;
- public IMacroDefinition attachment;
-
- public ObjectStyleMacro(char[] name, char[] expansion) {
- this.name = name;
- this.expansion = expansion;
- }
-
- public char[] getSignature() {
- return name;
- }
-
- public char[] getName(){
- return name;
- }
-
- public String toString() {
- return new String( name );
- }
-
- public char[] getExpansion() {
- return expansion;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java
deleted file mode 100644
index 346ce87b6bf..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerASTProblem.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Anton Leherbauer (Wind River Systems)
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.scanner2;
-
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
-import org.eclipse.cdt.core.dom.ast.IASTProblem;
-import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
-import org.eclipse.cdt.internal.core.parser.ParserMessages;
-
-/**
- * @author jcamelon
- */
-public class ScannerASTProblem extends ASTNode implements IASTProblem {
-
- private final char[] arg;
-
- private final int id;
-
- private final boolean isError;
-
- private final boolean isWarning;
-
- private String message = null;
-
- public ScannerASTProblem(int id, char[] arg, boolean warn, boolean error) {
- this.id = id;
- this.arg = arg;
- this.isWarning = warn;
- this.isError = error;
- }
-
- public int getID() {
- return id;
- }
-
- public boolean isError() {
- return isError;
- }
-
- public boolean isWarning() {
- return isWarning;
- }
-
- protected static final Map errorMessages;
- static {
- errorMessages = new HashMap();
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_POUND_ERROR),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.error")); //$NON-NLS-1$
- errorMessages.put(new Integer(IASTProblem.PREPROCESSOR_POUND_WARNING), ParserMessages
- .getString("ScannerProblemFactory.error.preproc.warning")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_INCLUSION_NOT_FOUND),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.inclusionNotFound")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_DEFINITION_NOT_FOUND),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.definitionNotFound")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_DEFN),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.invalidMacroDefn")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_INVALID_MACRO_REDEFN),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.invalidMacroRedefn")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_UNBALANCE_CONDITION),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.unbalancedConditional")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(
- IASTProblem.PREPROCESSOR_CONDITIONAL_EVAL_ERROR),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.conditionalEval")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_MACRO_USAGE_ERROR),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.macroUsage")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_CIRCULAR_INCLUSION),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.circularInclusion")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_INVALID_DIRECTIVE),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.invalidDirective")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_MACRO_PASTING_ERROR),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.macroPasting")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(
- IASTProblem.PREPROCESSOR_MISSING_RPAREN_PARMLIST),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.missingRParen")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.PREPROCESSOR_INVALID_VA_ARGS),
- ParserMessages
- .getString("ScannerProblemFactory.error.preproc.invalidVaArgs")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_INVALID_ESCAPECHAR),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.invalidEscapeChar")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_UNBOUNDED_STRING),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.unboundedString")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_BAD_FLOATING_POINT),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.badFloatingPoint")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_BAD_HEX_FORMAT),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.badHexFormat")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_BAD_OCTAL_FORMAT),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.badOctalFormat")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_BAD_DECIMAL_FORMAT),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.badDecimalFormat")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_ASSIGNMENT_NOT_ALLOWED),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.assignmentNotAllowed")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_DIVIDE_BY_ZERO),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.divideByZero")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_MISSING_R_PAREN),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.missingRParen")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_EXPRESSION_SYNTAX_ERROR),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.expressionSyntaxError")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_ILLEGAL_IDENTIFIER),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.illegalIdentifier")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_BAD_CONDITIONAL_EXPRESSION),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.badConditionalExpression")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_UNEXPECTED_EOF),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.unexpectedEOF")); //$NON-NLS-1$
- errorMessages
- .put(
- new Integer(IASTProblem.SCANNER_BAD_CHARACTER),
- ParserMessages
- .getString("ScannerProblemFactory.error.scanner.badCharacter")); //$NON-NLS-1$
- errorMessages.put(new Integer(IASTProblem.SYNTAX_ERROR), ParserMessages
- .getString("ParserProblemFactory.error.syntax.syntaxError")); //$NON-NLS-1$
- }
-
- protected final static String PROBLEM_PATTERN = "BaseProblemFactory.problemPattern"; //$NON-NLS-1$
-
- public String getMessage() {
- if (message != null)
- return message;
-
- String msg = (String) errorMessages.get(new Integer(id));
- if (msg == null)
- msg = ""; //$NON-NLS-1$
-
- if (arg != null) {
- msg = MessageFormat.format(msg, new Object[] { new String(arg) });
- }
-
- IASTFileLocation f = getFileLocation();
- String file = null;
- int line = 0;
- if( f == null )
- {
- file = ""; //$NON-NLS-1$
- } else {
- file = f.getFileName();
- line = f.getStartingLineNumber();
- }
- Object[] args = new Object[] { msg, file, new Integer(line) };
- message = ParserMessages.getFormattedString(PROBLEM_PATTERN, args);
- return message;
- }
-
- public boolean checkCategory(int bitmask) {
- return ((id & bitmask) != 0);
- }
-
- public String getArguments() {
- return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java
deleted file mode 100644
index e7b69971433..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/AbstractToken.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Rational Software - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.token;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.cdt.core.parser.IToken;
-import org.eclipse.cdt.core.parser.ITokenDuple;
-import org.eclipse.cdt.core.parser.util.CharArrayUtils;
-
-
-/**
- * @author johnc
- */
-public abstract class AbstractToken implements IToken, ITokenDuple {
-
- private final char[] filename;
-
- public AbstractToken( int type, int lineNumber, char [] filename )
- {
- setType( type );
- this.lineNumber = lineNumber;
- this.filename = filename;
- }
-
- public AbstractToken( int type, char [] filename, int lineNumber )
- {
- setType( type );
- this.filename = filename;
- this.lineNumber = lineNumber;
- }
-
- public String toString() {
- return getImage();
- }
-
- public abstract String getImage();
- public abstract int getOffset();
- public abstract int getLength();
-
- public int getType() { return type; }
-
- public void setType(int i) {
- type = i;
- }
-
- public int getLineNumber() {
- return lineNumber;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getFilename()
- */
- public char[] getFilename() {
- return filename;
- }
-
- public int getEndOffset() { return getOffset() + getLength(); }
-
- protected int type;
- protected int lineNumber = 1;
- protected IToken next = null;
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object other) {
- if( other == null ) return false;
- if( !( other instanceof IToken ) )
- return false;
- if( ((IToken)other).getType() != getType() )
- return false;
- if( !CharArrayUtils.equals( ((IToken)other).getCharImage(), getCharImage() ) )
- return false;
- if( getOffset() != ((IToken)other).getOffset() )
- return false;
- if( getEndOffset() != ((IToken)other).getEndOffset() )
- return false;
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#isKeyword()
- */
- public boolean canBeAPrefix() {
- switch( getType() )
- {
- case tIDENTIFIER:
- case tCOMPL:
- return true;
- default:
- if( getType() >= t_and && getType() <= t_xor_eq ) return true;
- if( getType() >= t__Bool && getType() <= t_restrict ) return true;
- }
- return false;
- }
-
- public boolean looksLikeExpression()
- {
- switch( getType() )
- {
- case IToken.tINTEGER:
- case IToken.t_false:
- case IToken.t_true:
- case IToken.tSTRING:
- case IToken.tLSTRING:
- case IToken.tFLOATINGPT:
- case IToken.tCHAR:
- case IToken.tAMPER:
- case IToken.tDOT:
- case IToken.tLPAREN:
- case IToken.tMINUS:
- case IToken.tSTAR:
- case IToken.tPLUS:
- case IToken.tNOT:
- case IToken.tCOMPL:
- return true;
- default:
- break;
- }
- return false;
- }
-
- public boolean isOperator()
- {
- switch( getType() )
- {
- case IToken.t_new:
- case IToken.t_delete:
- case IToken.tPLUS:
- case IToken.tMINUS:
- case IToken.tSTAR:
- case IToken.tDIV:
- case IToken.tXOR:
- case IToken.tMOD:
- case IToken.tAMPER:
- case IToken.tBITOR:
- case IToken.tCOMPL:
- case IToken.tNOT:
- case IToken.tASSIGN:
- case IToken.tLT:
- case IToken.tGT:
- case IToken.tPLUSASSIGN:
- case IToken.tMINUSASSIGN:
- case IToken.tSTARASSIGN:
- case IToken.tDIVASSIGN:
- case IToken.tMODASSIGN:
- case IToken.tBITORASSIGN:
- case IToken.tAMPERASSIGN:
- case IToken.tXORASSIGN:
- case IToken.tSHIFTL:
- case IToken.tSHIFTR:
- case IToken.tSHIFTLASSIGN:
- case IToken.tSHIFTRASSIGN:
- case IToken.tEQUAL:
- case IToken.tNOTEQUAL:
- case IToken.tLTEQUAL:
- case IToken.tGTEQUAL:
- case IToken.tAND:
- case IToken.tOR:
- case IToken.tINCR:
- case IToken.tDECR:
- case IToken.tCOMMA:
- case IToken.tARROW:
- case IToken.tARROWSTAR:
- return true;
- default:
- return false;
- }
- }
-
- public boolean isPointer()
- {
- return (getType() == IToken.tAMPER || getType() == IToken.tSTAR);
- }
-
-
-
- public final IToken getNext() { return next; }
- public void setNext(IToken t) { next = t; }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#contains(org.eclipse.cdt.core.parser.ITokenDuple)
- */
- public boolean contains(ITokenDuple duple) {
- return ( duple.getFirstToken() == duple.getLastToken() ) && ( duple.getFirstToken() == this );
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#extractNameFromTemplateId()
- */
- public char[] extractNameFromTemplateId(){
- return getCharImage();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#findLastTokenType(int)
- */
- public int findLastTokenType(int t) {
- if( getType() == t ) return 0;
- return -1;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getFirstToken()
- */
- public IToken getFirstToken() {
- return this;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getLastSegment()
- */
- public ITokenDuple getLastSegment() {
- return this;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getLastToken()
- */
- public IToken getLastToken() {
- return this;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getLeadingSegments()
- */
- public ITokenDuple getLeadingSegments() {
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentCount()
- */
- public int getSegmentCount() {
- return 1;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
- */
- public int getStartOffset() {
- return getOffset();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getSubrange(int, int)
- */
- public ITokenDuple getSubrange(int startIndex, int endIndex) {
- if( startIndex == 0 && endIndex == 0 ) return this;
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getTemplateIdArgLists()
- */
- public List[] getTemplateIdArgLists() {
- // TODO Auto-generated method stub
- return null;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getToken(int)
- */
- public IToken getToken(int index) {
- if( index == 0 ) return this;
- return null;
- }
-
-
- private class SingleIterator implements Iterator
- {
- boolean hasNext = true;
- /* (non-Javadoc)
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return hasNext;
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#next()
- */
- public Object next() {
- hasNext = false;
- return AbstractToken.this;
- }
-
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#iterator()
- */
- public Iterator iterator() {
- return new SingleIterator();
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#length()
- */
- public int length() {
- return 1;
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#syntaxOfName()
- */
- public boolean syntaxOfName() {
- return ( getType() == IToken.tIDENTIFIER );
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#toQualifiedName()
- */
- public String[] toQualifiedName() {
- String [] qualifiedName = new String[1];
- qualifiedName[0] = getImage();
- return qualifiedName;
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#getSegmentIterator()
- */
- public ITokenDuple[] getSegments() {
- ITokenDuple [] r = new ITokenDuple[0];
- r[0] = this;
- return r;
- }
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java
deleted file mode 100644
index 02764f59776..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/token/SimpleToken.java
+++ /dev/null
@@ -1,485 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Rational Software - initial implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.core.parser.token;
-
-import org.eclipse.cdt.core.parser.IToken;
-import org.eclipse.cdt.core.parser.Keywords;
-
-public class SimpleToken extends AbstractToken implements IToken {
-
- public SimpleToken( int t, int endOffset, char [] filename, int line )
- {
- super( t, filename, line );
- setOffsetAndLength( endOffset );
- }
-
- protected int offset;
-
- // All the tokens generated by the macro expansion
- // will have dimensions (offset and length) equal to the expanding symbol.
- public int getOffset() {
- return offset;
- }
-
- public int getLength() {
- return getCharImage().length;
- }
-
- protected void setOffsetAndLength( int endOffset )
- {
- this.offset = endOffset - getLength();
- }
-
- public String getImage() {
- switch ( getType() ) {
- case IToken.tCOLONCOLON :
- return "::" ; //$NON-NLS-1$
- case IToken.tCOLON :
- return ":" ; //$NON-NLS-1$
- case IToken.tSEMI :
- return ";" ; //$NON-NLS-1$
- case IToken.tCOMMA :
- return "," ; //$NON-NLS-1$
- case IToken.tQUESTION :
- return "?" ; //$NON-NLS-1$
- case IToken.tLPAREN :
- return "(" ; //$NON-NLS-1$
- case IToken.tRPAREN :
- return ")" ; //$NON-NLS-1$
- case IToken.tLBRACKET :
- return "[" ; //$NON-NLS-1$
- case IToken.tRBRACKET :
- return "]" ; //$NON-NLS-1$
- case IToken.tLBRACE :
- return "{" ; //$NON-NLS-1$
- case IToken.tRBRACE :
- return "}"; //$NON-NLS-1$
- case IToken.tPLUSASSIGN :
- return "+="; //$NON-NLS-1$
- case IToken.tINCR :
- return "++" ; //$NON-NLS-1$
- case IToken.tPLUS :
- return "+"; //$NON-NLS-1$
- case IToken.tMINUSASSIGN :
- return "-=" ; //$NON-NLS-1$
- case IToken.tDECR :
- return "--" ; //$NON-NLS-1$
- case IToken.tARROWSTAR :
- return "->*" ; //$NON-NLS-1$
- case IToken.tARROW :
- return "->" ; //$NON-NLS-1$
- case IToken.tMINUS :
- return "-" ; //$NON-NLS-1$
- case IToken.tSTARASSIGN :
- return "*=" ; //$NON-NLS-1$
- case IToken.tSTAR :
- return "*" ; //$NON-NLS-1$
- case IToken.tMODASSIGN :
- return "%=" ; //$NON-NLS-1$
- case IToken.tMOD :
- return "%" ; //$NON-NLS-1$
- case IToken.tXORASSIGN :
- return "^=" ; //$NON-NLS-1$
- case IToken.tXOR :
- return "^" ; //$NON-NLS-1$
- case IToken.tAMPERASSIGN :
- return "&=" ; //$NON-NLS-1$
- case IToken.tAND :
- return "&&" ; //$NON-NLS-1$
- case IToken.tAMPER :
- return "&" ; //$NON-NLS-1$
- case IToken.tBITORASSIGN :
- return "|=" ; //$NON-NLS-1$
- case IToken.tOR :
- return "||" ; //$NON-NLS-1$
- case IToken.tBITOR :
- return "|" ; //$NON-NLS-1$
- case IToken.tCOMPL :
- return "~" ; //$NON-NLS-1$
- case IToken.tNOTEQUAL :
- return "!=" ; //$NON-NLS-1$
- case IToken.tNOT :
- return "!" ; //$NON-NLS-1$
- case IToken.tEQUAL :
- return "==" ; //$NON-NLS-1$
- case IToken.tASSIGN :
- return "=" ; //$NON-NLS-1$
- case IToken.tSHIFTL :
- return "<<" ; //$NON-NLS-1$
- case IToken.tLTEQUAL :
- return "<=" ; //$NON-NLS-1$
- case IToken.tLT :
- return "<"; //$NON-NLS-1$
- case IToken.tSHIFTRASSIGN :
- return ">>=" ; //$NON-NLS-1$
- case IToken.tSHIFTR :
- return ">>" ; //$NON-NLS-1$
- case IToken.tGTEQUAL :
- return ">=" ; //$NON-NLS-1$
- case IToken.tGT :
- return ">" ; //$NON-NLS-1$
- case IToken.tSHIFTLASSIGN :
- return "<<=" ; //$NON-NLS-1$
- case IToken.tELLIPSIS :
- return "..." ; //$NON-NLS-1$
- case IToken.tDOTSTAR :
- return ".*" ; //$NON-NLS-1$
- case IToken.tDOT :
- return "." ; //$NON-NLS-1$
- case IToken.tDIVASSIGN :
- return "/=" ; //$NON-NLS-1$
- case IToken.tDIV :
- return "/" ; //$NON-NLS-1$
- case IToken.t_and :
- return Keywords.AND;
- case IToken.t_and_eq :
- return Keywords.AND_EQ ;
- case IToken.t_asm :
- return Keywords.ASM ;
- case IToken.t_auto :
- return Keywords.AUTO ;
- case IToken.t_bitand :
- return Keywords.BITAND ;
- case IToken.t_bitor :
- return Keywords.BITOR ;
- case IToken.t_bool :
- return Keywords.BOOL ;
- case IToken.t_break :
- return Keywords.BREAK ;
- case IToken.t_case :
- return Keywords.CASE ;
- case IToken.t_catch :
- return Keywords.CATCH ;
- case IToken.t_char :
- return Keywords.CHAR ;
- case IToken.t_class :
- return Keywords.CLASS ;
- case IToken.t_compl :
- return Keywords.COMPL ;
- case IToken.t_const :
- return Keywords.CONST ;
- case IToken.t_const_cast :
- return Keywords.CONST_CAST ;
- case IToken.t_continue :
- return Keywords.CONTINUE ;
- case IToken.t_default :
- return Keywords.DEFAULT ;
- case IToken.t_delete :
- return Keywords.DELETE ;
- case IToken.t_do :
- return Keywords.DO;
- case IToken.t_double :
- return Keywords.DOUBLE ;
- case IToken.t_dynamic_cast :
- return Keywords.DYNAMIC_CAST ;
- case IToken.t_else :
- return Keywords.ELSE;
- case IToken.t_enum :
- return Keywords.ENUM ;
- case IToken.t_explicit :
- return Keywords.EXPLICIT ;
- case IToken.t_export :
- return Keywords.EXPORT ;
- case IToken.t_extern :
- return Keywords.EXTERN;
- case IToken.t_false :
- return Keywords.FALSE;
- case IToken.t_float :
- return Keywords.FLOAT;
- case IToken.t_for :
- return Keywords.FOR;
- case IToken.t_friend :
- return Keywords.FRIEND;
- case IToken.t_goto :
- return Keywords.GOTO;
- case IToken.t_if :
- return Keywords.IF ;
- case IToken.t_inline :
- return Keywords.INLINE ;
- case IToken.t_int :
- return Keywords.INT ;
- case IToken.t_long :
- return Keywords.LONG ;
- case IToken.t_mutable :
- return Keywords.MUTABLE ;
- case IToken.t_namespace :
- return Keywords.NAMESPACE ;
- case IToken.t_new :
- return Keywords.NEW ;
- case IToken.t_not :
- return Keywords.NOT ;
- case IToken.t_not_eq :
- return Keywords.NOT_EQ;
- case IToken.t_operator :
- return Keywords.OPERATOR ;
- case IToken.t_or :
- return Keywords.OR ;
- case IToken.t_or_eq :
- return Keywords.OR_EQ;
- case IToken.t_private :
- return Keywords.PRIVATE ;
- case IToken.t_protected :
- return Keywords.PROTECTED ;
- case IToken.t_public :
- return Keywords.PUBLIC ;
- case IToken.t_register :
- return Keywords.REGISTER ;
- case IToken.t_reinterpret_cast :
- return Keywords.REINTERPRET_CAST ;
- case IToken.t_return :
- return Keywords.RETURN ;
- case IToken.t_short :
- return Keywords.SHORT ;
- case IToken.t_sizeof :
- return Keywords.SIZEOF ;
- case IToken.t_static :
- return Keywords.STATIC ;
- case IToken.t_static_cast :
- return Keywords.STATIC_CAST ;
- case IToken.t_signed :
- return Keywords.SIGNED ;
- case IToken.t_struct :
- return Keywords.STRUCT ;
- case IToken.t_switch :
- return Keywords.SWITCH ;
- case IToken.t_template :
- return Keywords.TEMPLATE ;
- case IToken.t_this :
- return Keywords.THIS ;
- case IToken.t_throw :
- return Keywords.THROW ;
- case IToken.t_true :
- return Keywords.TRUE ;
- case IToken.t_try :
- return Keywords.TRY ;
- case IToken.t_typedef :
- return Keywords.TYPEDEF ;
- case IToken.t_typeid :
- return Keywords.TYPEID ;
- case IToken.t_typename :
- return Keywords.TYPENAME ;
- case IToken.t_union :
- return Keywords.UNION ;
- case IToken.t_unsigned :
- return Keywords.UNSIGNED ;
- case IToken.t_using :
- return Keywords.USING ;
- case IToken.t_virtual :
- return Keywords.VIRTUAL ;
- case IToken.t_void :
- return Keywords.VOID ;
- case IToken.t_volatile :
- return Keywords.VOLATILE;
- case IToken.t_wchar_t :
- return Keywords.WCHAR_T ;
- case IToken.t_while :
- return Keywords.WHILE ;
- case IToken.t_xor :
- return Keywords.XOR ;
- case IToken.t_xor_eq :
- return Keywords.XOR_EQ ;
- case IToken.t__Bool :
- return Keywords._BOOL ;
- case IToken.t__Complex :
- return Keywords._COMPLEX ;
- case IToken.t__Imaginary :
- return Keywords._IMAGINARY ;
- case IToken.t_restrict :
- return Keywords.RESTRICT ;
- case IToken.tPOUND:
- return "#"; //$NON-NLS-1$
- case IToken.tPOUNDPOUND:
- return "##"; //$NON-NLS-1$
- case IToken.tEOC:
- return "EOC"; //$NON-NLS-1$
- default :
- // we should never get here!
- // assert false : getType();
- return ""; //$NON-NLS-1$
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage()
- */
- public void setImage( String i ) {
- // do nothing
- }
-
- public char[] getCharImage() {
- return getCharImage( getType() );
- }
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#getCharImage()
- */
- static public char[] getCharImage( int type ){
- switch ( type ) {
- case IToken.tCOLONCOLON : return Keywords.cpCOLONCOLON;
- case IToken.tCOLON : return Keywords.cpCOLON;
- case IToken.tSEMI : return Keywords.cpSEMI;
- case IToken.tCOMMA : return Keywords.cpCOMMA;
- case IToken.tQUESTION : return Keywords.cpQUESTION;
- case IToken.tLPAREN : return Keywords.cpLPAREN;
- case IToken.tRPAREN : return Keywords.cpRPAREN;
- case IToken.tLBRACKET : return Keywords.cpLBRACKET;
- case IToken.tRBRACKET : return Keywords.cpRBRACKET;
- case IToken.tLBRACE : return Keywords.cpLBRACE;
- case IToken.tRBRACE : return Keywords.cpRBRACE;
- case IToken.tPLUSASSIGN : return Keywords.cpPLUSASSIGN;
- case IToken.tINCR : return Keywords.cpINCR;
- case IToken.tPLUS : return Keywords.cpPLUS;
- case IToken.tMINUSASSIGN : return Keywords.cpMINUSASSIGN;
- case IToken.tDECR : return Keywords.cpDECR;
- case IToken.tARROWSTAR : return Keywords.cpARROWSTAR;
- case IToken.tARROW : return Keywords.cpARROW;
- case IToken.tMINUS : return Keywords.cpMINUS;
- case IToken.tSTARASSIGN : return Keywords.cpSTARASSIGN;
- case IToken.tSTAR : return Keywords.cpSTAR;
- case IToken.tMODASSIGN : return Keywords.cpMODASSIGN;
- case IToken.tMOD : return Keywords.cpMOD;
- case IToken.tXORASSIGN : return Keywords.cpXORASSIGN;
- case IToken.tXOR : return Keywords.cpXOR;
- case IToken.tAMPERASSIGN : return Keywords.cpAMPERASSIGN;
- case IToken.tAND : return Keywords.cpAND;
- case IToken.tAMPER : return Keywords.cpAMPER;
- case IToken.tBITORASSIGN : return Keywords.cpBITORASSIGN;
- case IToken.tOR : return Keywords.cpOR;
- case IToken.tBITOR : return Keywords.cpBITOR;
- case IToken.tCOMPL : return Keywords.cpCOMPL;
- case IToken.tNOTEQUAL : return Keywords.cpNOTEQUAL;
- case IToken.tNOT : return Keywords.cpNOT;
- case IToken.tEQUAL : return Keywords.cpEQUAL;
- case IToken.tASSIGN : return Keywords.cpASSIGN;
- case IToken.tSHIFTL : return Keywords.cpSHIFTL;
- case IToken.tLTEQUAL : return Keywords.cpLTEQUAL;
- case IToken.tLT : return Keywords.cpLT;
- case IToken.tSHIFTRASSIGN : return Keywords.cpSHIFTRASSIGN;
- case IToken.tSHIFTR : return Keywords.cpSHIFTR;
- case IToken.tGTEQUAL : return Keywords.cpGTEQUAL;
- case IToken.tGT : return Keywords.cpGT;
- case IToken.tSHIFTLASSIGN : return Keywords.cpSHIFTLASSIGN;
- case IToken.tELLIPSIS : return Keywords.cpELLIPSIS;
- case IToken.tDOTSTAR : return Keywords.cpDOTSTAR;
- case IToken.tDOT : return Keywords.cpDOT;
- case IToken.tDIVASSIGN : return Keywords.cpDIVASSIGN;
- case IToken.tDIV : return Keywords.cpDIV;
- case IToken.t_and : return Keywords.cAND;
- case IToken.t_and_eq : return Keywords.cAND_EQ ;
- case IToken.t_asm : return Keywords.cASM ;
- case IToken.t_auto : return Keywords.cAUTO ;
- case IToken.t_bitand : return Keywords.cBITAND ;
- case IToken.t_bitor : return Keywords.cBITOR ;
- case IToken.t_bool : return Keywords.cBOOL ;
- case IToken.t_break : return Keywords.cBREAK ;
- case IToken.t_case : return Keywords.cCASE ;
- case IToken.t_catch : return Keywords.cCATCH ;
- case IToken.t_char : return Keywords.cCHAR ;
- case IToken.t_class : return Keywords.cCLASS ;
- case IToken.t_compl : return Keywords.cCOMPL ;
- case IToken.t_const : return Keywords.cCONST ;
- case IToken.t_const_cast : return Keywords.cCONST_CAST ;
- case IToken.t_continue : return Keywords.cCONTINUE ;
- case IToken.t_default : return Keywords.cDEFAULT ;
- case IToken.t_delete : return Keywords.cDELETE ;
- case IToken.t_do : return Keywords.cDO;
- case IToken.t_double : return Keywords.cDOUBLE ;
- case IToken.t_dynamic_cast: return Keywords.cDYNAMIC_CAST ;
- case IToken.t_else : return Keywords.cELSE;
- case IToken.t_enum : return Keywords.cENUM ;
- case IToken.t_explicit : return Keywords.cEXPLICIT ;
- case IToken.t_export : return Keywords.cEXPORT ;
- case IToken.t_extern : return Keywords.cEXTERN;
- case IToken.t_false : return Keywords.cFALSE;
- case IToken.t_float : return Keywords.cFLOAT;
- case IToken.t_for : return Keywords.cFOR;
- case IToken.t_friend : return Keywords.cFRIEND;
- case IToken.t_goto : return Keywords.cGOTO;
- case IToken.t_if : return Keywords.cIF ;
- case IToken.t_inline : return Keywords.cINLINE ;
- case IToken.t_int : return Keywords.cINT ;
- case IToken.t_long : return Keywords.cLONG ;
- case IToken.t_mutable : return Keywords.cMUTABLE ;
- case IToken.t_namespace : return Keywords.cNAMESPACE ;
- case IToken.t_new : return Keywords.cNEW ;
- case IToken.t_not : return Keywords.cNOT ;
- case IToken.t_not_eq : return Keywords.cNOT_EQ;
- case IToken.t_operator : return Keywords.cOPERATOR ;
- case IToken.t_or : return Keywords.cOR ;
- case IToken.t_or_eq : return Keywords.cOR_EQ;
- case IToken.t_private : return Keywords.cPRIVATE ;
- case IToken.t_protected : return Keywords.cPROTECTED ;
- case IToken.t_public : return Keywords.cPUBLIC ;
- case IToken.t_register : return Keywords.cREGISTER ;
- case IToken.t_reinterpret_cast : return Keywords.cREINTERPRET_CAST ;
- case IToken.t_return : return Keywords.cRETURN ;
- case IToken.t_short : return Keywords.cSHORT ;
- case IToken.t_sizeof : return Keywords.cSIZEOF ;
- case IToken.t_static : return Keywords.cSTATIC ;
- case IToken.t_static_cast : return Keywords.cSTATIC_CAST ;
- case IToken.t_signed : return Keywords.cSIGNED ;
- case IToken.t_struct : return Keywords.cSTRUCT ;
- case IToken.t_switch : return Keywords.cSWITCH ;
- case IToken.t_template : return Keywords.cTEMPLATE ;
- case IToken.t_this : return Keywords.cTHIS ;
- case IToken.t_throw : return Keywords.cTHROW ;
- case IToken.t_true : return Keywords.cTRUE ;
- case IToken.t_try : return Keywords.cTRY ;
- case IToken.t_typedef : return Keywords.cTYPEDEF ;
- case IToken.t_typeid : return Keywords.cTYPEID ;
- case IToken.t_typename : return Keywords.cTYPENAME ;
- case IToken.t_union : return Keywords.cUNION ;
- case IToken.t_unsigned : return Keywords.cUNSIGNED ;
- case IToken.t_using : return Keywords.cUSING ;
- case IToken.t_virtual : return Keywords.cVIRTUAL ;
- case IToken.t_void : return Keywords.cVOID ;
- case IToken.t_volatile : return Keywords.cVOLATILE;
- case IToken.t_wchar_t : return Keywords.cWCHAR_T ;
- case IToken.t_while : return Keywords.cWHILE ;
- case IToken.t_xor : return Keywords.cXOR ;
- case IToken.t_xor_eq : return Keywords.cXOR_EQ ;
- case IToken.t__Bool : return Keywords.c_BOOL ;
- case IToken.t__Complex : return Keywords.c_COMPLEX ;
- case IToken.t__Imaginary : return Keywords.c_IMAGINARY ;
- case IToken.t_restrict : return Keywords.cRESTRICT ;
- case IToken.tPOUND: return Keywords.cpPOUND;
- case IToken.tPOUNDPOUND: return Keywords.cpPOUNDPOUND;
-
- default :
- // we should never get here!
- // assert false : getType();
- return "".toCharArray(); //$NON-NLS-1$
- }
- //return getImage().toCharArray(); //TODO - fix me!
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.IToken#setImage(char[])
- */
- public void setImage(char[] i) {
- // do nothing
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#toCharArray()
- */
- public char[] toCharArray() {
- return getCharImage();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.parser.ITokenDuple#isConversion()
- */
- public boolean isConversion() {
- return false;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java
index ad18cfbea11..0dcd99419ff 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java
@@ -38,14 +38,12 @@ import org.eclipse.cdt.core.index.IndexLocationFactory;
import org.eclipse.cdt.core.model.AbstractLanguage;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
-import org.eclipse.cdt.core.parser.IMacro;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndex;
import org.eclipse.cdt.internal.core.index.IndexBasedCodeReaderFactory;
-import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacro;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -82,7 +80,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
boolean fRequestUpdate= false;
boolean fRequestIsCounted= true;
boolean fIsUpdated= false;
- public IMacro[] fMacros;
+ public IIndexMacro[] fMacros;
}
private int fUpdateFlags= IIndexManager.UPDATE_ALL;
@@ -456,10 +454,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
}
}
}
- catch (OutOfMemoryError e) {
- throw e;
- }
- catch (Throwable e) {
+ catch (Exception e) {
swallowError(path, e);
}
}
@@ -760,7 +755,7 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return result*31 + key.hashCode();
}
- public final IMacro[] getConvertedMacros(int linkageID, IIndexFileLocation ifl) throws CoreException {
+ public final IIndexMacro[] getConvertedMacros(int linkageID, IIndexFileLocation ifl) throws CoreException {
if (!needToUpdateHeader(linkageID, ifl)) {
FileInfo info= getFileInfo(linkageID, ifl);
assert info != null;
@@ -771,14 +766,9 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
return null;
}
}
- IMacro[] result= info.fMacros;
+ IIndexMacro[] result= info.fMacros;
if (result == null) {
- IIndexMacro[] macros= info.fIndexFile.getMacros();
- result= new IMacro[macros.length];
- for (int i = 0; i < macros.length; i++) {
- IIndexMacro macro = macros[i];
- result[i]= ((PDOMMacro)macro).getMacro();
- }
+ result= info.fIndexFile.getMacros();
info.fMacros= result;
}
return result;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java
index 33af9916ce5..5df83345fb8 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java
@@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * QNX - Initial API and implementation
- * Markus Schorn (Wind River Systems)
- * Andrew Ferguson (Symbian)
+ * QNX - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ * Andrew Ferguson (Symbian)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
@@ -18,16 +18,20 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ILinkage;
+import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
+import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexMacro;
-import org.eclipse.cdt.core.parser.IMacro;
-import org.eclipse.cdt.internal.core.parser.scanner2.FunctionStyleMacro;
-import org.eclipse.cdt.internal.core.parser.scanner2.ObjectStyleMacro;
+import org.eclipse.cdt.core.parser.Keywords;
+import org.eclipse.cdt.core.parser.util.CharArrayUtils;
+import org.eclipse.cdt.internal.core.dom.Linkage;
+import org.eclipse.cdt.internal.core.parser.scanner.MacroDefinitionParser;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.db.Database;
import org.eclipse.cdt.internal.core.pdom.db.IString;
@@ -40,11 +44,6 @@ import org.eclipse.core.runtime.CoreException;
*/
public class PDOMMacro implements IIndexMacro, IASTFileLocation {
- private final PDOM pdom;
- private final int record;
- private IIndexMacro macro;
-
- private static final byte MACROSTYLE_UNKNOWN = 0; // for reading versions of PDOM <39
private static final byte MACROSTYLE_OBJECT = 1;
private static final byte MACROSTYLE_FUNCTION= 2;
@@ -58,7 +57,15 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
private static final int MACRO_STYLE = 26; // byte
private static final int RECORD_SIZE = 27;
+ private static final char[][] UNINITIALIZED= {};
+
+ private final PDOM pdom;
+ private final int record;
+ private char[][] fParameterList= UNINITIALIZED;
+ private char[] fName;
+ private char[] fExpansion;
+
public PDOMMacro(PDOM pdom, int record) {
this.pdom = pdom;
this.record = record;
@@ -138,142 +145,54 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
int rec = pdom.getDB().getInt(record + FIRST_PARAMETER);
return rec != 0 ? new PDOMMacroParameter(pdom, rec) : null;
}
-
- private class ObjectStylePDOMMacro extends ObjectStyleMacro implements IIndexMacro {
- public ObjectStylePDOMMacro(char[] name) {
- super(name, null);
- }
- public char[] getExpansion() {
- if (expansion == null) {
- expansion= getMacroExpansion();
- }
- return expansion;
- }
- public IASTFileLocation getFileLocation() {
- return PDOMMacro.this;
- }
- public IIndexFile getFile() throws CoreException {
- return PDOMMacro.this.getFile();
- }
- public int getNodeOffset() {
- return PDOMMacro.this.getNodeOffset();
- }
- public int getNodeLength() {
- return PDOMMacro.this.getNodeLength();
- }
- public char[][] getParameterList() {
- return null;
- }
- }
-
- private class FunctionStylePDOMMacro extends FunctionStyleMacro implements IIndexMacro {
- public FunctionStylePDOMMacro(char[] name, char[][] arglist) {
- super(name, null, arglist);
- }
- public char[] getExpansion() {
- if (expansion == null) {
- expansion= getMacroExpansion();
- }
- return expansion;
- }
- public IASTFileLocation getFileLocation() {
- return PDOMMacro.this;
- }
- public IIndexFile getFile() throws CoreException {
- return PDOMMacro.this.getFile();
- }
- public int getNodeOffset() {
- return PDOMMacro.this.getNodeOffset();
- }
- public int getNodeLength() {
- return PDOMMacro.this.getNodeLength();
- }
- public char[][] getParameterList() {
- return getOriginalParameters();
- }
- }
-
- private char[] getMacroExpansion() {
- try {
- return PDOMMacro.this.getExpansionInDB().getChars();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- return new char[] { ' ' };
- }
- }
-
- public IMacro getMacro() throws CoreException {
- rebuildMacro();
- return macro;
- }
-
- private void rebuildMacro() throws CoreException {
- if (macro == null) {
- char[] name = getNameInDB(pdom, record).getChars();
- PDOMMacroParameter param= getFirstParameter();
-
- byte style= pdom.getDB().getByte(record + MACRO_STYLE);
- if(style == MACROSTYLE_UNKNOWN) {
- /* PDOM formats < 39 do not store MACRO_STYLE (208558) */
- style= param != null ? MACROSTYLE_FUNCTION : MACROSTYLE_OBJECT;
- }
-
- switch(style) {
- case MACROSTYLE_OBJECT:
- macro= new ObjectStylePDOMMacro(name);
- break;
- case MACROSTYLE_FUNCTION:
- List paramList = new ArrayList();
- while (param != null) {
- paramList.add(param.getName().getChars());
- param = param.getNextParameter();
+
+ public char[][] getParameterList() {
+ if (fParameterList == UNINITIALIZED) {
+ fParameterList= null;
+ try {
+ byte style= pdom.getDB().getByte(record + MACRO_STYLE);
+ if (style == MACROSTYLE_FUNCTION) {
+ List paramList = new ArrayList();
+ PDOMMacroParameter param= getFirstParameter();
+ while (param != null) {
+ paramList.add(param.getName().getChars());
+ param = param.getNextParameter();
+ }
+ fParameterList= (char[][])paramList.toArray(new char[paramList.size()][]);
}
- char[][] params = (char[][])paramList.toArray(new char[paramList.size()][]);
- macro= new FunctionStylePDOMMacro(name, params);
- break;
- default:
- throw new PDOMNotImplementedError();
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
}
}
+ return fParameterList;
}
- public char[][] getParameterList() {
- try {
- rebuildMacro();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- return new char[][]{};
- }
- return macro.getParameterList();
- }
-
- public char[] getSignature() {
- try {
- rebuildMacro();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- return new char[] { ' ' };
+ public char[] getExpansionImage() {
+ if (fExpansion == null) {
+ try {
+ fExpansion= getExpansionInDB().getChars();
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ fExpansion= new char[] { ' ' };
+ }
}
- return macro.getSignature();
+ return fExpansion;
}
- public char[] getExpansion() {
- try {
- rebuildMacro();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- return new char[] { ' ' };
+ public char[] getNameCharArray() {
+ if (fName == null) {
+ try {
+ fName= getNameInDB(pdom, record).getChars();
+ } catch (CoreException e) {
+ CCorePlugin.log(e);
+ fName= new char[] { ' ' };
+ }
}
- return macro.getExpansion();
+ return fName;
}
-
- public char[] getName() {
- try {
- return getNameInDB(pdom, record).getChars();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- return new char[] { ' ' };
- }
+
+ public String getName() {
+ return new String(getNameCharArray());
}
public IIndexFile getFile() throws CoreException {
@@ -334,4 +253,39 @@ public class PDOMMacro implements IIndexMacro, IASTFileLocation {
}
}
+ public char[] getExpansion() {
+ char[] expansionImage= getExpansionImage();
+ return MacroDefinitionParser.getExpansion(expansionImage, 0, expansionImage.length);
+ }
+
+ public char[][] getParameterPlaceholderList() {
+ char[][] params= getParameterList();
+ if (params != null && params.length > 0) {
+ char[] lastParam= params[params.length-1];
+ if (CharArrayUtils.equals(lastParam, 0, Keywords.cpELLIPSIS.length, Keywords.cpELLIPSIS)) {
+ char[][] result= new char[params.length][];
+ System.arraycopy(params, 0, result, 0, params.length-1);
+ result[params.length-1]= lastParam.length == Keywords.cpELLIPSIS.length ? Keywords.cVA_ARGS :
+ CharArrayUtils.extract(lastParam, Keywords.cpELLIPSIS.length, lastParam.length-Keywords.cpELLIPSIS.length);
+ return result;
+ }
+ }
+ return params;
+ }
+
+ public boolean isFunctionStyle() {
+ return getParameterList() != null;
+ }
+
+ public ILinkage getLinkage() throws CoreException {
+ return Linkage.NO_LINKAGE;
+ }
+
+ public IScope getScope() throws DOMException {
+ return null;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TodoTaskParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TodoTaskParser.java
index bb24f667119..5fe0e8ba319 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TodoTaskParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/TodoTaskParser.java
@@ -57,8 +57,10 @@ public class TodoTaskParser {
for (int i = 0; i < comments.length; i++) {
IASTComment comment = comments[i];
IASTFileLocation location = comment.getFileLocation();
- parse(comment.getComment(), location.getFileName(), location.getNodeOffset(),
- location.getStartingLineNumber(), tasks);
+ if (location != null) { // be defensive, bug 213307
+ parse(comment.getComment(), location.getFileName(), location.getNodeOffset(),
+ location.getStartingLineNumber(), tasks);
+ }
}
if (tasks.isEmpty()) {
return EMPTY_TASK_ARRAY;

Back to the top