mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
bug 69296 - remove ILineOffsetReconciler
This commit is contained in:
parent
1dfc3821c4
commit
226defa14a
8 changed files with 41 additions and 184 deletions
|
@ -14,14 +14,12 @@ package org.eclipse.cdt.core.parser.tests;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ILineOffsetReconciler;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
@ -50,18 +48,14 @@ public class AutomatedTest extends AutomatedFramework {
|
|||
|
||||
File file = null;
|
||||
IParser parser = null;
|
||||
ILineOffsetReconciler mapping = null;
|
||||
|
||||
try{
|
||||
file = (File)fileList.removeFirst();
|
||||
FileInputStream stream = new FileInputStream( file );
|
||||
|
||||
String filePath = file.getCanonicalPath();
|
||||
ParserLanguage language = ((String)natures.get( filePath )).equalsIgnoreCase("cpp") ? ParserLanguage.CPP : ParserLanguage.C; //$NON-NLS-1$
|
||||
parser = ParserFactory.createParser( ParserFactory.createScanner(filePath, new ScannerInfo(), ParserMode.QUICK_PARSE, language, nullCallback, null, null ), nullCallback, ParserMode.QUICK_PARSE, language, null);
|
||||
|
||||
mapping = ParserFactory.createLineOffsetReconciler( new InputStreamReader( stream ) );
|
||||
|
||||
assertTrue( parser.parse() );
|
||||
}
|
||||
catch( Throwable e )
|
||||
|
@ -69,10 +63,10 @@ public class AutomatedTest extends AutomatedFramework {
|
|||
String output = null;
|
||||
if( e instanceof AssertionFailedError ){
|
||||
output = file.getCanonicalPath() + ": Parse failed on line "; //$NON-NLS-1$
|
||||
output += mapping.getLineNumberForOffset(parser.getLastErrorOffset()) + "\n"; //$NON-NLS-1$
|
||||
output += parser.getLastErrorLine() + "\n"; //$NON-NLS-1$
|
||||
} else {
|
||||
output = file.getCanonicalPath() + ": " + e.getClass().toString(); //$NON-NLS-1$
|
||||
output += " on line " + mapping.getLineNumberForOffset(parser.getLastErrorOffset()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
output += " on line " + parser.getLastErrorLine() + "\n"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
if( report != null ){
|
||||
report.write( output.getBytes() );
|
||||
|
@ -112,22 +106,21 @@ public class AutomatedTest extends AutomatedFramework {
|
|||
String sourceInfo = properties.getProperty( "source", "" ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if( sourceInfo.equals("") ) //$NON-NLS-1$
|
||||
throw new FileNotFoundException();
|
||||
else{
|
||||
StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," ); //$NON-NLS-1$
|
||||
String str = null, val = null;
|
||||
try{
|
||||
while( tokenizer.hasMoreTokens() ){
|
||||
str = tokenizer.nextToken().trim();
|
||||
val = tokenizer.nextToken().trim();
|
||||
|
||||
testSources.put( str, val );
|
||||
}
|
||||
} catch ( NoSuchElementException e ){
|
||||
//only way to get here is to have a missing val, assume cpp for that str
|
||||
testSources.put( str, "cpp" ); //$NON-NLS-1$
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer( sourceInfo, "," ); //$NON-NLS-1$
|
||||
String str = null, val = null;
|
||||
try{
|
||||
while( tokenizer.hasMoreTokens() ){
|
||||
str = tokenizer.nextToken().trim();
|
||||
val = tokenizer.nextToken().trim();
|
||||
|
||||
testSources.put( str, val );
|
||||
}
|
||||
|
||||
} catch ( NoSuchElementException e ){
|
||||
//only way to get here is to have a missing val, assume cpp for that str
|
||||
testSources.put( str, "cpp" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
} catch ( FileNotFoundException e ){
|
||||
testSources.put( resourcePath + "/defaultCpp", "cpp" ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
testSources.put( resourcePath + "/defaultC", "c" ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
@ -23,7 +22,6 @@ import junit.framework.AssertionFailedError;
|
|||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ILineOffsetReconciler;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
|
@ -75,21 +73,19 @@ public class TortureTest extends FractionalAutomatedTest {
|
|||
|
||||
if (sourceInfo.equals("")) //$NON-NLS-1$
|
||||
throw new FileNotFoundException();
|
||||
else {
|
||||
StringTokenizer tokenizer = new StringTokenizer(sourceInfo, ","); //$NON-NLS-1$
|
||||
String str = null, val = null;
|
||||
try {
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
str = tokenizer.nextToken().trim();
|
||||
val = tokenizer.nextToken().trim();
|
||||
|
||||
testSources.put(str, val);
|
||||
}
|
||||
} catch (NoSuchElementException e){
|
||||
//only way to get here is to have a missing val, assume cpp for that str
|
||||
testSources.put(str, "cpp"); //$NON-NLS-1$
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer(sourceInfo, ","); //$NON-NLS-1$
|
||||
String str = null, val = null;
|
||||
try {
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
str = tokenizer.nextToken().trim();
|
||||
val = tokenizer.nextToken().trim();
|
||||
|
||||
testSources.put(str, val);
|
||||
}
|
||||
|
||||
} catch (NoSuchElementException e){
|
||||
//only way to get here is to have a missing val, assume cpp for that str
|
||||
testSources.put(str, "cpp"); //$NON-NLS-1$
|
||||
}
|
||||
} catch (FileNotFoundException e){
|
||||
testSources.put(resourcePath, "cpp"); //$NON-NLS-1$
|
||||
|
@ -106,14 +102,12 @@ public class TortureTest extends FractionalAutomatedTest {
|
|||
}
|
||||
|
||||
|
||||
static protected void reportException (Throwable e, String file, IParser parser, ILineOffsetReconciler mapping){
|
||||
static protected void reportException (Throwable e, String file, IParser parser){
|
||||
String output = null;
|
||||
int lineNumber = -1;
|
||||
|
||||
try {
|
||||
lineNumber = mapping.getLineNumberForOffset(parser.getLastErrorOffset());
|
||||
} catch (Exception ex) {}
|
||||
|
||||
lineNumber = parser.getLastErrorLine();
|
||||
|
||||
if (e instanceof AssertionFailedError) {
|
||||
output = file + ": Parse failed on line "; //$NON-NLS-1$
|
||||
output += lineNumber + "\n"; //$NON-NLS-1$
|
||||
|
@ -255,7 +249,7 @@ public class TortureTest extends FractionalAutomatedTest {
|
|||
thread.stop();
|
||||
reportHang(testCode, filePath);
|
||||
} else if (thread.result != null) {
|
||||
reportException(thread.result, filePath, thread.parser, thread.mapping);
|
||||
reportException(thread.result, filePath, thread.parser);
|
||||
}
|
||||
} else {
|
||||
// gcc probably didn't expect this test to pass.
|
||||
|
@ -269,7 +263,6 @@ public class TortureTest extends FractionalAutomatedTest {
|
|||
|
||||
|
||||
static class ParseThread extends Thread {
|
||||
public ILineOffsetReconciler mapping = null;
|
||||
public String code;
|
||||
public boolean cppNature;
|
||||
public String file;
|
||||
|
@ -284,8 +277,6 @@ public class TortureTest extends FractionalAutomatedTest {
|
|||
parser = ParserFactory.createParser(
|
||||
ParserFactory.createScanner( new CodeReader( code.toCharArray() ), new ScannerInfo(), parserMode, language, nullCallback, new NullLogService(), null ), nullCallback, parserMode, language, null);
|
||||
|
||||
mapping = ParserFactory.createLineOffsetReconciler( new StringReader( code ) );
|
||||
|
||||
assertTrue(parser.parse());
|
||||
}
|
||||
catch( Throwable e )
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public interface ILineOffsetReconciler
|
||||
{
|
||||
public int getLineNumberForOffset( int offset );
|
||||
public IOffsetDuple getOffsetRangeForLineNumber( int LineNumber );
|
||||
}
|
|
@ -58,5 +58,6 @@ public interface IParser {
|
|||
*/
|
||||
public int getLastErrorOffset();
|
||||
|
||||
public int getLastErrorLine();
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@
|
|||
package org.eclipse.cdt.core.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -30,7 +29,6 @@ import org.eclipse.cdt.internal.core.parser.StructuralParser;
|
|||
import org.eclipse.cdt.internal.core.parser.ast.complete.CompleteParseASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.expression.ExpressionParseASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.ast.quick.QuickParseASTFactory;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.LineOffsetReconciler;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.Scanner;
|
||||
import org.eclipse.cdt.internal.core.parser.token.KeywordSets;
|
||||
|
||||
|
@ -111,11 +109,6 @@ public class ParserFactory {
|
|||
{
|
||||
return createScanner(new CodeReader(fileName), config, mode, language, requestor, log, workingCopies);
|
||||
}
|
||||
|
||||
public static ILineOffsetReconciler createLineOffsetReconciler( Reader input )
|
||||
{
|
||||
return new LineOffsetReconciler( input );
|
||||
}
|
||||
|
||||
public static IQuickParseCallback createQuickParseCallback()
|
||||
{
|
||||
|
|
|
@ -51,9 +51,10 @@ import org.eclipse.cdt.internal.core.parser.util.TraceUtil;
|
|||
public class ExpressionParser implements IExpressionParser, IParserData {
|
||||
|
||||
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
private static int FIRST_ERROR_OFFSET_UNSET = -1;
|
||||
private static int FIRST_ERROR_UNSET = -1;
|
||||
protected boolean parsePassed = true;
|
||||
protected int firstErrorOffset = FIRST_ERROR_OFFSET_UNSET;
|
||||
protected int firstErrorOffset = FIRST_ERROR_UNSET;
|
||||
protected int firstErrorLine = FIRST_ERROR_UNSET;
|
||||
private BacktrackException backtrack = new BacktrackException();
|
||||
private int backtrackCount = 0;
|
||||
|
||||
|
@ -223,8 +224,10 @@ public class ExpressionParser implements IExpressionParser, IParserData {
|
|||
*/
|
||||
protected void failParse() {
|
||||
try {
|
||||
if (firstErrorOffset == FIRST_ERROR_OFFSET_UNSET)
|
||||
if (firstErrorOffset == FIRST_ERROR_UNSET){
|
||||
firstErrorOffset = LA(1).getOffset();
|
||||
firstErrorLine = LA(1).getLineNumber();
|
||||
}
|
||||
} catch (EndOfFileException eof) {
|
||||
// do nothing
|
||||
} finally {
|
||||
|
|
|
@ -3291,6 +3291,9 @@ public abstract class Parser extends ExpressionParser implements IParser
|
|||
public int getLastErrorOffset() {
|
||||
return firstErrorOffset;
|
||||
}
|
||||
public int getLastErrorLine() {
|
||||
return firstErrorLine;
|
||||
}
|
||||
|
||||
protected void setCompletionToken(IToken token) {
|
||||
// do nothing!
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.internal.core.parser.scanner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.eclipse.cdt.core.parser.ILineOffsetReconciler;
|
||||
import org.eclipse.cdt.core.parser.IOffsetDuple;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserMessages;
|
||||
import org.eclipse.cdt.internal.core.parser.token.OffsetDuple;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class LineOffsetReconciler implements ILineOffsetReconciler
|
||||
{
|
||||
private Reader ourReader;
|
||||
int currentOffset = 0;
|
||||
/**
|
||||
* @param input
|
||||
*/
|
||||
public LineOffsetReconciler(Reader input)
|
||||
{
|
||||
ourReader = input;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ILineOffsetReconciler#getLineNumberForOffset(int)
|
||||
*/
|
||||
public int getLineNumberForOffset(int offset)
|
||||
{
|
||||
if( offset < currentOffset )
|
||||
resetReader();
|
||||
int lineNumber = 1;
|
||||
for( int i = currentOffset; i < offset; ++i )
|
||||
{
|
||||
int c = getChar();
|
||||
if( c == -1 )
|
||||
return -1;
|
||||
if( c == '\n' )
|
||||
++lineNumber;
|
||||
}
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
private int getChar()
|
||||
{
|
||||
int c;
|
||||
try
|
||||
{
|
||||
c = ourReader.read();
|
||||
++currentOffset;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
private void resetReader()
|
||||
{
|
||||
try
|
||||
{
|
||||
ourReader.reset();
|
||||
currentOffset = 0;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new Error( ParserMessages.getString("LineOffsetReconciler.error.couldNotResetReader") ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ILineOffsetReconciler#getOffsetRangeForLineNumber(int)
|
||||
*/
|
||||
public IOffsetDuple getOffsetRangeForLineNumber(int LineNumber)
|
||||
{
|
||||
int lineNumber = 1;
|
||||
int floor= -1, ceiling = -1;
|
||||
int offset = 0;
|
||||
while( lineNumber != LineNumber )
|
||||
{
|
||||
int c = getChar();
|
||||
++offset;
|
||||
if( c == '\n' ) ++lineNumber;
|
||||
}
|
||||
floor = offset;
|
||||
while( lineNumber == LineNumber )
|
||||
{
|
||||
int c = getChar();
|
||||
++offset;
|
||||
if( c == '\n' ) ++lineNumber;
|
||||
}
|
||||
ceiling = offset;
|
||||
return new OffsetDuple( floor, ceiling );
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue