mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Further DOM/AST fixes (w/viewer).
This commit is contained in:
parent
d7b97a7f42
commit
b811a0479b
5 changed files with 547 additions and 514 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
|
@ -165,5 +166,18 @@ public class DOMLocationTests extends AST2BaseTest {
|
||||||
IASTIdExpression expression = (IASTIdExpression) returnStatement.getReturnValue();
|
IASTIdExpression expression = (IASTIdExpression) returnStatement.getReturnValue();
|
||||||
assertSoleLocation( expression, code.indexOf( "return ") + "return ".length(), 1 ); //$NON-NLS-1$ //$NON-NLS-2$
|
assertSoleLocation( expression, code.indexOf( "return ") + "return ".length(), 1 ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testElaboratedTypeSpecifier() throws ParserException {
|
||||||
|
String code = "/* blah */ struct A anA; /* blah */"; //$NON-NLS-1$
|
||||||
|
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||||
|
: null) {
|
||||||
|
IASTTranslationUnit tu = parse(code, p);
|
||||||
|
IASTSimpleDeclaration declaration = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||||
|
IASTElaboratedTypeSpecifier elabType = (IASTElaboratedTypeSpecifier) declaration.getDeclSpecifier();
|
||||||
|
assertSoleLocation( elabType, code.indexOf( "struct"), "struct A".length() ); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1672,6 +1672,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
name.setParent(result);
|
name.setParent(result);
|
||||||
name.setPropertyInParent(IASTElaboratedTypeSpecifier.TYPE_NAME);
|
name.setPropertyInParent(IASTElaboratedTypeSpecifier.TYPE_NAME);
|
||||||
result.setKind(eck);
|
result.setKind(eck);
|
||||||
|
((ASTNode)result).setOffsetAndLength( t.getOffset(), calculateEndOffset(name) - t.getOffset() );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,14 @@ import org.eclipse.cdt.internal.core.dom.parser.c.GCCParserExtensionConfiguratio
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
import org.eclipse.cdt.internal.core.dom.parser.c.GNUCSourceParser;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
|
import org.eclipse.cdt.internal.core.dom.parser.c.ICParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ANSICPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.GNUCPPSourceParser;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPParserExtensionConfiguration;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPParserExtensionConfiguration;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.InternalParserUtil;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.DOMScanner;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.GCCScannerExtensionConfiguration;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.GPPScannerExtensionConfiguration;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.IScannerExtensionConfiguration;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -50,7 +55,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
*/
|
*/
|
||||||
public class InternalASTServiceProvider implements IASTServiceProvider {
|
public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
|
|
||||||
private static final String[] dialects = { "C99", //$NON-NLS-1$
|
protected static final GCCScannerExtensionConfiguration C_GNU_SCANNER_EXTENSION = new GCCScannerExtensionConfiguration();
|
||||||
|
protected static final GPPScannerExtensionConfiguration CPP_GNU_SCANNER_EXTENSION = new GPPScannerExtensionConfiguration();
|
||||||
|
private static final String[] dialects = { "C99", //$NON-NLS-1$
|
||||||
"C++98", //$NON-NLS-1$
|
"C++98", //$NON-NLS-1$
|
||||||
"GNUC", //$NON-NLS-1$
|
"GNUC", //$NON-NLS-1$
|
||||||
"GNUC++" }; //$NON-NLS-1$
|
"GNUC++" }; //$NON-NLS-1$
|
||||||
|
@ -110,9 +117,14 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
|
||||||
if( configuration == null )
|
if( configuration == null )
|
||||||
{
|
{
|
||||||
ParserLanguage l = getLanguage(fileToParse);
|
ParserLanguage l = getLanguage(fileToParse);
|
||||||
scanner = ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
IScannerExtensionConfiguration scannerExtensionConfiguration = null;
|
||||||
l, NULL_REQUESTOR,
|
if( l == ParserLanguage.CPP )
|
||||||
ParserUtil.getScannerLogService(), Collections.EMPTY_LIST);
|
scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION;
|
||||||
|
else
|
||||||
|
scannerExtensionConfiguration = C_GNU_SCANNER_EXTENSION;
|
||||||
|
|
||||||
|
scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE,
|
||||||
|
l, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, fileCreator );
|
||||||
//assume GCC
|
//assume GCC
|
||||||
if( l == ParserLanguage.C )
|
if( l == ParserLanguage.C )
|
||||||
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() );
|
parser = new GNUCSourceParser( scanner, ParserMode.COMPLETE_PARSE, ParserUtil.getParserLogService(), new GCCParserExtensionConfiguration() );
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,8 +10,10 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ public class TreeObject implements IAdaptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
if( node == null ) return ""; //$NON-NLS-1$ //TODO Devin is this the best way???
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
Class[] classes = node.getClass().getInterfaces();
|
Class[] classes = node.getClass().getInterfaces();
|
||||||
|
@ -80,17 +83,25 @@ public class TreeObject implements IAdaptable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFilename()
|
||||||
|
{
|
||||||
|
IASTNodeLocation [] location = node.getNodeLocations();
|
||||||
|
if( location[0] instanceof IASTFileLocation )
|
||||||
|
return ((IASTFileLocation)location[0]).getFileName();
|
||||||
|
return ""; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
if (node instanceof ASTNode)
|
IASTNodeLocation [] location = node.getNodeLocations();
|
||||||
return ((ASTNode)node).getOffset();
|
if( location.length == 1 )
|
||||||
|
return location[0].getNodeOffset();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
if (node instanceof ASTNode)
|
IASTNodeLocation [] location = node.getNodeLocations();
|
||||||
return ((ASTNode)node).getLength();
|
if( location.length == 1 )
|
||||||
|
return location[0].getNodeLength();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue