1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Moved clients towards IASTNode.getFileLocation() and away from IASTTranslationUnit.flattenLocations( ... ).

This commit is contained in:
John Camelon 2005-05-30 20:32:56 +00:00
parent e4f34ad3b5
commit 24648ae9ed
13 changed files with 41 additions and 60 deletions

View file

@ -1632,7 +1632,7 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest {
IASTTranslationUnit tu = parse(file, ParserLanguage.CPP, false, true);
IASTPreprocessorStatement[] stmts = tu.getAllPreprocessorStatements();
IASTFileLocation fileLoc = tu.flattenLocationsToFile(stmts[5].getNodeLocations());
IASTFileLocation fileLoc = stmts[5].getFileLocation();
int fileOffset = test2_h.indexOf("#ifndef _WINGDI_H");
int fileLocOffset = fileLoc.getNodeOffset();
assertEquals(fileOffset, fileLocOffset);

View file

@ -344,7 +344,7 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
IASTPreprocessorMacroDefinition INCLUDE_H = macro_defs[1];
final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName().getNodeLocations();
assertEquals( nodeLocations.length, 1 );
final IASTFileLocation flatLoc = tu.flattenLocationsToFile( nodeLocations );
final IASTFileLocation flatLoc = INCLUDE_H.getName().getFileLocation();
assertNotNull( flatLoc );
assertEquals( include_file.getLocation().toOSString(), flatLoc.getFileName() );
assertEquals( inc_file_code.indexOf( "#define _INCLUDE_H_") + "#define ".length(), flatLoc.getNodeOffset() ); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -209,7 +209,7 @@ public class DOMLocationMacroTests extends AST2BaseTest {
IASTFileLocation tenth_loc = (IASTFileLocation) nodeLocations[9];
assertEquals( 1, tenth_loc.getNodeLength() );
final IASTFileLocation flatLocation = tu.flattenLocationsToFile(nodeLocations);
final IASTFileLocation flatLocation = var.getFileLocation();
assertNotNull( flatLocation);
assertEquals( code.indexOf("XYZ IT C_PO C_PO V;"), flatLocation.getNodeOffset() ); //$NON-NLS-1$
assertEquals( "XYZ IT C_PO C_PO V;".length(), flatLocation.getNodeLength() ); //$NON-NLS-1$
@ -244,13 +244,13 @@ public class DOMLocationMacroTests extends AST2BaseTest {
IASTFileLocation loc_4 = (IASTFileLocation) locations[3];
assertEquals( loc_4.getNodeOffset(), code.indexOf( ";")); //$NON-NLS-1$
assertEquals( loc_4.getNodeLength(), 1 );
IASTFileLocation flat = tu.flattenLocationsToFile(locations);
IASTFileLocation flat = memchr.getFileLocation();
assertEquals( flat.getNodeOffset() , code.indexOf( "_PTR _EXFUN(memchr,(const _PTR, int, size_t));")); //$NON-NLS-1$
assertEquals( flat.getNodeLength(), "_PTR _EXFUN(memchr,(const _PTR, int, size_t));".length() ); //$NON-NLS-1$
IASTDeclarator d = memchr.getDeclarators()[0];
final IASTNodeLocation[] declaratorLocations = d.getNodeLocations();
IASTFileLocation f = tu.flattenLocationsToFile( declaratorLocations );
IASTFileLocation f = d.getFileLocation();
assertEquals( code.indexOf( "_PTR _EXFUN(memchr,(const _PTR, int, size_t))"), f.getNodeOffset() ); //$NON-NLS-1$
assertEquals( "_PTR _EXFUN(memchr,(const _PTR, int, size_t))".length(), f.getNodeLength() ); //$NON-NLS-1$
}

View file

@ -53,6 +53,7 @@ public abstract class ASTNode implements IASTNode {
}
private IASTNodeLocation[] locations = null;
private IASTFileLocation fileLocation = null;
/*
* (non-Javadoc)
@ -83,6 +84,9 @@ public abstract class ASTNode implements IASTNode {
}
public IASTFileLocation getFileLocation() {
return getTranslationUnit().flattenLocationsToFile( getNodeLocations() );
if( fileLocation != null )
return fileLocation;
fileLocation = getTranslationUnit().flattenLocationsToFile( getNodeLocations() );
return fileLocation;
}
}

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
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.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
@ -197,8 +196,7 @@ public class ProblemBinding implements IProblemBinding, IType, IScope {
public int getLineNumber() {
if( node != null ){
IASTNodeLocation [] locs = node.getNodeLocations();
IASTFileLocation fileLoc = node.getTranslationUnit().flattenLocationsToFile( locs );
IASTFileLocation fileLoc = node.getFileLocation();
return fileLoc.getStartingLineNumber();
}
return -1;

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.parser.ParserMessages;
@ -270,24 +269,19 @@ public class CASTProblem extends CASTNode implements IASTProblem {
msg = MessageFormat.format(msg, new Object[] { new String(arg) });
}
IASTNodeLocation [] locs = getNodeLocations();
String file = null;
int offset = 0;
if( locs != null && locs.length == 1 && locs[0] instanceof IASTFileLocation ){
file = ((IASTFileLocation) locs[0]).getFileName();
offset = locs[0].getNodeOffset();
} else {
IASTFileLocation f = getTranslationUnit().flattenLocationsToFile(locs);
if( f == null )
{
file = ""; //$NON-NLS-1$
offset = 0;
}
else
{
file = f.getFileName();
offset = f.getNodeOffset();
}
IASTFileLocation f = getFileLocation();
if( f == null )
{
file = ""; //$NON-NLS-1$
offset = 0;
}
else
{
file = f.getFileName();
offset = f.getNodeOffset();
}
Object[] args = new Object[] { msg, file, new Integer( offset ) }; //$NON-NLS-1$

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.parser.ParserMessages;
@ -269,24 +268,19 @@ public class CPPASTProblem extends CPPASTNode implements IASTProblem {
msg = MessageFormat.format(msg, new Object[] { new String(arg) });
}
IASTNodeLocation [] locs = getNodeLocations();
String file = null;
int offset = 0;
if( locs != null && locs.length == 1 && locs[0] instanceof IASTFileLocation ){
file = ((IASTFileLocation) locs[0]).getFileName();
offset = locs[0].getNodeOffset();
} else {
IASTFileLocation f = getTranslationUnit().flattenLocationsToFile(locs);
if( f == null )
{
file = ""; //$NON-NLS-1$
offset = 0;
}
else
{
file = f.getFileName();
offset = f.getNodeOffset();
}
IASTFileLocation f = getFileLocation();
if( f == null )
{
file = ""; //$NON-NLS-1$
offset = 0;
}
else
{
file = f.getFileName();
offset = f.getNodeOffset();
}
Object[] args = new Object[] { msg, file, new Integer(offset) }; //$NON-NLS-1$
message = ParserMessages.getFormattedString(AST_PROBLEM_PATTERN, args);

View file

@ -91,7 +91,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
}
public IASTFileLocation asFileLocation() {
return rootNode.flattenLocationsToFile(getExpansionLocations());
return rootNode.flattenLocationsToFile(locations);
}
public String toString() {

View file

@ -284,30 +284,21 @@ public class DOMASTNodeLeaf implements IAdaptable {
public String getFilename()
{
if ( node == null ) return BLANK_STRING;
IASTNodeLocation [] location = node.getNodeLocations();
if( location.length == 1 && location[0] instanceof IASTFileLocation )
return ((IASTFileLocation)location[0]).getFileName();
IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location);
IASTFileLocation f = node.getFileLocation();
if( f == null )
return BLANK_STRING; //$NON-NLS-1$
return f.getFileName();
}
public int getOffset() {
IASTNodeLocation [] location = node.getNodeLocations();
if( location.length == 1 && location[0] instanceof IASTFileLocation )
return location[0].getNodeOffset();
IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location);
IASTFileLocation f = node.getFileLocation();
if( f == null )
return 0; //$NON-NLS-1$
return f.getNodeOffset();
}
public int getLength() {
IASTNodeLocation [] location = node.getNodeLocations();
if( location.length == 1 && location[0] instanceof IASTFileLocation )
return location[0].getNodeLength();
IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location);
IASTFileLocation f = node.getFileLocation();
if( f == null )
return 0; //$NON-NLS-1$
return f.getNodeLength();

View file

@ -93,7 +93,7 @@ public class DOMDisplaySearchNames extends CSearchQuery implements ISearchQuery
int start = 0;
int end = 0;
if ( nodes[i] != null ) {
IASTFileLocation location = nodes[i].getTranslationUnit().flattenLocationsToFile( nodes[i].getNodeLocations() );
IASTFileLocation location = nodes[i].getFileLocation();
if (location == null) {
return new Status(IStatus.ERROR, CUIPlugin.getPluginId(), 0, "Null Location associated with IASTFileLocation.", null); //$NON-NLS-1$
}

View file

@ -118,7 +118,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
int end = 0;
if ( foundNames[i].getTranslationUnit() != null ) {
IASTFileLocation location = foundNames[i].getTranslationUnit().flattenLocationsToFile( foundNames[i].getNodeLocations() );
IASTFileLocation location = foundNames[i].getFileLocation();
fileName = location.getFileName();
start = location.getNodeOffset();
end = location.getNodeOffset() + location.getNodeLength();

View file

@ -149,7 +149,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
int end=0;
if ( domNames[0].getTranslationUnit() != null ) {
IASTFileLocation location = domNames[0].getTranslationUnit().flattenLocationsToFile( domNames[0].getNodeLocations() );
IASTFileLocation location = domNames[0].getFileLocation();
fileName = location.getFileName();
start = location.getNodeOffset();
end = location.getNodeOffset() + location.getNodeLength();

View file

@ -161,7 +161,7 @@ public class OpenDefinitionAction extends SelectionParseAction implements
int end=0;
if ( domNames[0].getTranslationUnit() != null ) {
IASTFileLocation location = domNames[0].getTranslationUnit().flattenLocationsToFile( domNames[0].getNodeLocations() );
IASTFileLocation location = domNames[0].getFileLocation();
fileName = location.getFileName();
start = location.getNodeOffset();
end = location.getNodeOffset() + location.getNodeLength();