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

fix problem reporting from the ExpressionEvaluator

This commit is contained in:
Andrew Niefer 2004-10-18 21:11:57 +00:00
parent 801c17db2e
commit 121fe1e577
3 changed files with 87 additions and 45 deletions

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.parser.IProblem; 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.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.core.parser.util.CharArrayUtils;
@ -30,7 +29,7 @@ public class ExpressionEvaluator {
private int[] bufferPos = new int[bufferInitialSize]; private int[] bufferPos = new int[bufferInitialSize];
private int[] bufferLimit = new int[bufferInitialSize]; private int[] bufferLimit = new int[bufferInitialSize];
private ISourceElementRequestor requestor = null; private ScannerCallbackManager callbackManager = null;
private ScannerProblemFactory spf = null; private ScannerProblemFactory spf = null;
private int lineNumber = 1; private int lineNumber = 1;
@ -45,8 +44,8 @@ public class ExpressionEvaluator {
super(); super();
} }
public ExpressionEvaluator(ISourceElementRequestor requestor, ScannerProblemFactory spf) { public ExpressionEvaluator( ScannerCallbackManager manager, ScannerProblemFactory spf) {
this.requestor = requestor; this.callbackManager = manager;
this.spf = spf; this.spf = spf;
} }
@ -526,7 +525,7 @@ public class ExpressionEvaluator {
tokenValue += c - '0'; tokenValue += c - '0';
continue; 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])) if (!isValidTokenSeparator(c, buffer[bufferPos[bufferStackPos] + 1]))
handleProblem(IProblem.SCANNER_BAD_DECIMAL_FORMAT, pos); handleProblem(IProblem.SCANNER_BAD_DECIMAL_FORMAT, pos);
} }
@ -666,6 +665,7 @@ public class ExpressionEvaluator {
char[] buffer = bufferStack[bufferStackPos]; char[] buffer = bufferStack[bufferStackPos];
int limit = bufferLimit[bufferStackPos]; int limit = bufferLimit[bufferStackPos];
skipWhiteSpace();
if (++bufferPos[bufferStackPos] >= limit if (++bufferPos[bufferStackPos] >= limit
|| buffer[bufferPos[bufferStackPos]] != '(') || buffer[bufferPos[bufferStackPos]] != '(')
return; return;
@ -898,8 +898,8 @@ public class ExpressionEvaluator {
} }
private void handleProblem(int id, int startOffset) { private void handleProblem(int id, int startOffset) {
if (requestor != null && spf != null) if (callbackManager != 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$ 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 { private boolean isValidTokenSeparator(char c, char c2) throws EvalException {

View file

@ -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.IASTCompletionNode;
import org.eclipse.cdt.core.parser.ast.IASTFactory; import org.eclipse.cdt.core.parser.ast.IASTFactory;
import org.eclipse.cdt.core.parser.ast.IASTInclusion; 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.extension.IScannerExtension;
import org.eclipse.cdt.core.parser.util.CharArrayIntMap; import org.eclipse.cdt.core.parser.util.CharArrayIntMap;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap; import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
@ -62,7 +61,7 @@ public class Scanner2 implements IScanner, IScannerData {
* @author jcamelon * @author jcamelon
* *
*/ */
private static class InclusionData { protected static class InclusionData {
public final IASTInclusion inclusion; public final IASTInclusion inclusion;
public final CodeReader reader; public final CodeReader reader;
@ -112,9 +111,8 @@ public class Scanner2 implements IScanner, IScannerData {
int[] lineNumbers = new int[bufferInitialSize]; int[] lineNumbers = new int[bufferInitialSize];
private int[] lineOffsets = new int[bufferInitialSize]; private int[] lineOffsets = new int[bufferInitialSize];
//inclusion stack //callbacks
private Object[] callbackStack = new Object[bufferInitialSize]; private ScannerCallbackManager callbackManager;
private int callbackPos = -1;
//branch tracking //branch tracking
private int branchStackPos = -1; private int branchStackPos = -1;
@ -159,7 +157,8 @@ public class Scanner2 implements IScanner, IScannerData {
this.language = language; this.language = language;
this.log = log; this.log = log;
this.workingCopies = workingCopies; this.workingCopies = workingCopies;
this.expressionEvaluator = new ExpressionEvaluator(requestor, spf); this.callbackManager = new ScannerCallbackManager( requestor );
this.expressionEvaluator = new ExpressionEvaluator(callbackManager, spf);
if( language == ParserLanguage.C ) if( language == ParserLanguage.C )
keywords = ckeywords; keywords = ckeywords;
@ -258,7 +257,7 @@ public class Scanner2 implements IScanner, IScannerData {
bufferData[bufferStackPos] = data; bufferData[bufferStackPos] = data;
if( data instanceof InclusionData ) if( data instanceof InclusionData )
{ {
pushCallback( data ); callbackManager.pushCallback( data );
if( log.isTracing() ) if( log.isTracing() )
{ {
StringBuffer b = new StringBuffer( "Entering inclusion "); //$NON-NLS-1$ 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 ); buffer.append( ((InclusionData)bufferData[bufferStackPos]).reader.filename );
log.traceLog( buffer.toString() ); log.traceLog( buffer.toString() );
} }
pushCallback( ((InclusionData) bufferData[bufferStackPos]).inclusion );
callbackManager.pushCallback( ((InclusionData) bufferData[bufferStackPos]).inclusion );
} }
bufferData[bufferStackPos] = null; bufferData[bufferStackPos] = null;
--bufferStackPos; --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) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScanner#addDefinition(java.lang.String, java.lang.String) * @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 ){ if( callbackManager.hasCallbacks() ){
popCallbacks(); callbackManager.popCallbacks();
} }
if (finished) if (finished)
@ -1140,7 +1116,7 @@ public class Scanner2 implements IScanner, IScannerData {
private void handleProblem(int id, int startOffset, char [] arg ) { private void handleProblem(int id, int startOffset, char [] arg ) {
if( parserMode == ParserMode.COMPLETION_PARSE ) return; if( parserMode == ParserMode.COMPLETION_PARSE ) return;
IProblem p = spf.createProblem( id, startOffset, bufferPos[bufferStackPos], getLineNumber( bufferPos[bufferStackPos] ), getCurrentFilename(), arg != null ? arg : emptyCharArray, false, true ); 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 ) if( parserMode == ParserMode.QUICK_PARSE )
{ {
IASTInclusion inclusion = getASTFactory().createInclusion( fileNameArray, EMPTY_STRING_CHAR_ARRAY, local, startOffset, startingLineNumber, nameOffset, nameEndOffset, nameLine, endOffset, endLine, getCurrentFilename() ); IASTInclusion inclusion = getASTFactory().createInclusion( fileNameArray, EMPTY_STRING_CHAR_ARRAY, local, startOffset, startingLineNumber, nameOffset, nameEndOffset, nameLine, endOffset, endLine, getCurrentFilename() );
pushCallback( new InclusionData( null, inclusion ) ); callbackManager.pushCallback( new InclusionData( null, inclusion ) );
pushCallback( inclusion ); callbackManager.pushCallback( inclusion );
} }
else else
{ {
@ -1815,7 +1791,7 @@ public class Scanner2 implements IScanner, IScannerData {
? new ObjectStyleMacro(name, text) ? new ObjectStyleMacro(name, text)
: new FunctionStyleMacro(name, text, arglist) ); : 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 ){ private char[][] extractMacroParameters( int idstart, char[] name, boolean reportProblems ){

View file

@ -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;
}
}