Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2004-10-18 17:11:57 -0400
committerAndrew Niefer2004-10-18 17:11:57 -0400
commit121fe1e5770282acb8eae9c067ce99086a46fbe2 (patch)
tree2ccc2afdbc070897ddf6ecf4ee4c76d7cb1977d7
parent801c17db2eaa784898549ba6c8641b825b279750 (diff)
downloadorg.eclipse.cdt-121fe1e5770282acb8eae9c067ce99086a46fbe2.tar.gz
org.eclipse.cdt-121fe1e5770282acb8eae9c067ce99086a46fbe2.tar.xz
org.eclipse.cdt-121fe1e5770282acb8eae9c067ce99086a46fbe2.zip
fix problem reporting from the ExpressionEvaluator
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ExpressionEvaluator.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java52
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java66
3 files changed, 87 insertions, 45 deletions
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
index 435b464d04a..b4efd0f4970 100644
--- 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
@@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.parser.IProblem;
-import org.eclipse.cdt.core.parser.ISourceElementRequestor;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@@ -30,7 +29,7 @@ public class ExpressionEvaluator {
private int[] bufferPos = new int[bufferInitialSize];
private int[] bufferLimit = new int[bufferInitialSize];
- private ISourceElementRequestor requestor = null;
+ private ScannerCallbackManager callbackManager = null;
private ScannerProblemFactory spf = null;
private int lineNumber = 1;
@@ -45,8 +44,8 @@ public class ExpressionEvaluator {
super();
}
- public ExpressionEvaluator(ISourceElementRequestor requestor, ScannerProblemFactory spf) {
- this.requestor = requestor;
+ public ExpressionEvaluator( ScannerCallbackManager manager, ScannerProblemFactory spf) {
+ this.callbackManager = manager;
this.spf = spf;
}
@@ -526,7 +525,7 @@ public class ExpressionEvaluator {
tokenValue += c - '0';
continue;
}
- if (bufferPos[bufferStackPos] + 1 < limit)
+ 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);
}
@@ -666,6 +665,7 @@ public class ExpressionEvaluator {
char[] buffer = bufferStack[bufferStackPos];
int limit = bufferLimit[bufferStackPos];
+ skipWhiteSpace();
if (++bufferPos[bufferStackPos] >= limit
|| buffer[bufferPos[bufferStackPos]] != '(')
return;
@@ -898,8 +898,8 @@ public class ExpressionEvaluator {
}
private void handleProblem(int id, int startOffset) {
- if (requestor != null && spf != null)
- requestor.acceptProblem(spf.createProblem( id, startOffset, bufferPos[(bufferStackPos == -1 ? 0 : bufferStackPos)], lineNumber, (fileName == null ? "".toCharArray() : fileName), emptyCharArray, false, true )); //$NON-NLS-1$
+ if (callbackManager != null && spf != null)
+ callbackManager.pushCallback( spf.createProblem( id, startOffset, bufferPos[(bufferStackPos == -1 ? 0 : bufferStackPos)], lineNumber, (fileName == null ? "".toCharArray() : fileName), emptyCharArray, false, true )); //$NON-NLS-1$
}
private boolean isValidTokenSeparator(char c, char c2) throws EvalException {
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
index bee4b4da043..47dadcc1782 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/Scanner2.java
@@ -38,7 +38,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.core.parser.ast.IASTInclusion;
-import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.extension.IScannerExtension;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
@@ -62,7 +61,7 @@ public class Scanner2 implements IScanner, IScannerData {
* @author jcamelon
*
*/
- private static class InclusionData {
+ protected static class InclusionData {
public final IASTInclusion inclusion;
public final CodeReader reader;
@@ -112,9 +111,8 @@ public class Scanner2 implements IScanner, IScannerData {
int[] lineNumbers = new int[bufferInitialSize];
private int[] lineOffsets = new int[bufferInitialSize];
- //inclusion stack
- private Object[] callbackStack = new Object[bufferInitialSize];
- private int callbackPos = -1;
+ //callbacks
+ private ScannerCallbackManager callbackManager;
//branch tracking
private int branchStackPos = -1;
@@ -159,7 +157,8 @@ public class Scanner2 implements IScanner, IScannerData {
this.language = language;
this.log = log;
this.workingCopies = workingCopies;
- this.expressionEvaluator = new ExpressionEvaluator(requestor, spf);
+ this.callbackManager = new ScannerCallbackManager( requestor );
+ this.expressionEvaluator = new ExpressionEvaluator(callbackManager, spf);
if( language == ParserLanguage.C )
keywords = ckeywords;
@@ -258,7 +257,7 @@ public class Scanner2 implements IScanner, IScannerData {
bufferData[bufferStackPos] = data;
if( data instanceof InclusionData )
{
- pushCallback( data );
+ callbackManager.pushCallback( data );
if( log.isTracing() )
{
StringBuffer b = new StringBuffer( "Entering inclusion "); //$NON-NLS-1$
@@ -279,37 +278,14 @@ public class Scanner2 implements IScanner, IScannerData {
buffer.append( ((InclusionData)bufferData[bufferStackPos]).reader.filename );
log.traceLog( buffer.toString() );
}
- pushCallback( ((InclusionData) bufferData[bufferStackPos]).inclusion );
+
+ callbackManager.pushCallback( ((InclusionData) bufferData[bufferStackPos]).inclusion );
}
bufferData[bufferStackPos] = null;
--bufferStackPos;
}
- private void pushCallback( Object obj ){
- if( ++callbackPos == callbackStack.length ){
- Object[] temp = new Object[ callbackStack.length << 1 ];
- System.arraycopy( callbackStack, 0, temp, 0, callbackStack.length );
- callbackStack = temp;
- }
- callbackStack[ callbackPos ] = obj;
- }
- private void popCallbacks(){
- Object obj = null;
- for( int i = 0; i <= callbackPos; i++ ){
- obj = callbackStack[i];
- //on the stack, InclusionData means enter, IASTInclusion means exit
- if( obj instanceof InclusionData )
- requestor.enterInclusion( ((InclusionData)obj).inclusion );
- else if( obj instanceof IASTInclusion )
- requestor.exitInclusion( (IASTInclusion) obj );
- else if( obj instanceof IASTMacro )
- requestor.acceptMacro( (IASTMacro) obj );
- else if( obj instanceof IProblem )
- requestor.acceptProblem( (IProblem) obj );
- }
- callbackPos = -1;
- }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScanner#addDefinition(java.lang.String, java.lang.String)
@@ -416,8 +392,8 @@ public class Scanner2 implements IScanner, IScannerData {
}
}
- if( callbackPos != -1 ){
- popCallbacks();
+ if( callbackManager.hasCallbacks() ){
+ callbackManager.popCallbacks();
}
if (finished)
@@ -1140,7 +1116,7 @@ public class Scanner2 implements IScanner, IScannerData {
private void handleProblem(int id, int startOffset, char [] arg ) {
if( parserMode == ParserMode.COMPLETION_PARSE ) return;
IProblem p = spf.createProblem( id, startOffset, bufferPos[bufferStackPos], getLineNumber( bufferPos[bufferStackPos] ), getCurrentFilename(), arg != null ? arg : emptyCharArray, false, true );
- pushCallback( p );
+ callbackManager.pushCallback( p );
}
@@ -1644,8 +1620,8 @@ public class Scanner2 implements IScanner, IScannerData {
if( parserMode == ParserMode.QUICK_PARSE )
{
IASTInclusion inclusion = getASTFactory().createInclusion( fileNameArray, EMPTY_STRING_CHAR_ARRAY, local, startOffset, startingLineNumber, nameOffset, nameEndOffset, nameLine, endOffset, endLine, getCurrentFilename() );
- pushCallback( new InclusionData( null, inclusion ) );
- pushCallback( inclusion );
+ callbackManager.pushCallback( new InclusionData( null, inclusion ) );
+ callbackManager.pushCallback( inclusion );
}
else
{
@@ -1815,7 +1791,7 @@ public class Scanner2 implements IScanner, IScannerData {
? new ObjectStyleMacro(name, text)
: new FunctionStyleMacro(name, text, arglist) );
- pushCallback( getASTFactory().createMacro( name, startingOffset, startingLineNumber, idstart, idstart + idlen, nameLine, textstart + textlen, endingLine, getCurrentFilename() ) );
+ callbackManager.pushCallback( getASTFactory().createMacro( name, startingOffset, startingLineNumber, idstart, idstart + idlen, nameLine, textstart + textlen, endingLine, getCurrentFilename() ) );
}
private char[][] extractMacroParameters( int idstart, char[] name, boolean reportProblems ){
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java
new file mode 100644
index 00000000000..77f02008d6b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/ScannerCallbackManager.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+/*
+ * Created on Oct 18, 2004
+ */
+package org.eclipse.cdt.internal.core.parser.scanner2;
+
+import org.eclipse.cdt.core.parser.IProblem;
+import org.eclipse.cdt.core.parser.ISourceElementRequestor;
+import org.eclipse.cdt.core.parser.ast.IASTInclusion;
+import org.eclipse.cdt.core.parser.ast.IASTMacro;
+import org.eclipse.cdt.internal.core.parser.scanner2.Scanner2.InclusionData;
+
+/**
+ * @author aniefer
+ */
+public class ScannerCallbackManager {
+ private static final int bufferInitialSize = 8;
+
+ private Object[] callbackStack = new Object[bufferInitialSize];
+ private int callbackPos = -1;
+ private ISourceElementRequestor requestor;
+
+ public ScannerCallbackManager( ISourceElementRequestor requestor ){
+ this.requestor = requestor;
+ }
+
+ public void pushCallback( Object obj ){
+ if( ++callbackPos == callbackStack.length ){
+ Object[] temp = new Object[ callbackStack.length << 1 ];
+ System.arraycopy( callbackStack, 0, temp, 0, callbackStack.length );
+ callbackStack = temp;
+ }
+ callbackStack[ callbackPos ] = obj;
+ }
+
+ public void popCallbacks(){
+ Object obj = null;
+ for( int i = 0; i <= callbackPos; i++ ){
+ obj = callbackStack[i];
+ //on the stack, InclusionData means enter, IASTInclusion means exit
+ if( obj instanceof InclusionData )
+ requestor.enterInclusion( ((InclusionData)obj).inclusion );
+ else if( obj instanceof IASTInclusion )
+ requestor.exitInclusion( (IASTInclusion) obj );
+ else if( obj instanceof IASTMacro )
+ requestor.acceptMacro( (IASTMacro) obj );
+ else if( obj instanceof IProblem )
+ requestor.acceptProblem( (IProblem) obj );
+ }
+ callbackPos = -1;
+ }
+
+ public boolean hasCallbacks(){
+ return callbackPos != -1;
+ }
+}

Back to the top