mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Fixed failing JUnit tests.
Fixed Macro Definition offsets in inclusions.
This commit is contained in:
parent
b2ff153008
commit
736de0128d
6 changed files with 164 additions and 122 deletions
|
@ -972,7 +972,9 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals( decls.length, 1 );
|
||||
assertEquals( decls[0], fdef.getDeclarator().getName() );
|
||||
|
||||
decls = tu.getDeclarations( ((IASTElaboratedTypeSpecifier)((IASTCastExpression)((IASTFieldReference)expStatement.getExpression()).getFieldOwner()).getTypeId().getDeclSpecifier()).getName().resolveBinding() );
|
||||
IASTCastExpression castExpression = (IASTCastExpression) ((IASTUnaryExpression)((IASTFieldReference)expStatement.getExpression()).getFieldOwner()).getOperand();
|
||||
IASTElaboratedTypeSpecifier elaboratedTypeSpecifier = ((IASTElaboratedTypeSpecifier)castExpression.getTypeId().getDeclSpecifier());
|
||||
decls = tu.getDeclarations( elaboratedTypeSpecifier.getName().resolveBinding() );
|
||||
assertEquals( decls.length, 1 );
|
||||
assertEquals( decls[0], compType.getName() );
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ 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.IASTPreprocessorIncludeStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
@ -54,11 +55,11 @@ import org.eclipse.core.resources.IFile;
|
|||
public class DOMLocationInclusionTests extends FileBasePluginTest {
|
||||
|
||||
private static final IScannerInfo SCANNER_INFO = new ScannerInfo();
|
||||
|
||||
private static final IParserLogService NULL_LOG = new NullLogService();
|
||||
private static final ICodeReaderFactory factory = CDOM
|
||||
.getInstance()
|
||||
.getCodeReaderFactory(
|
||||
CDOM.PARSE_SAVED_RESOURCES);
|
||||
|
||||
private static final ICodeReaderFactory factory = CDOM.getInstance()
|
||||
.getCodeReaderFactory(CDOM.PARSE_SAVED_RESOURCES);
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
@ -72,8 +73,9 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
throws Exception {
|
||||
InputStream stream = code.getContents();
|
||||
IScanner scanner = new DOMScanner(new CodeReader(code.getLocation()
|
||||
.toOSString(), stream), SCANNER_INFO, ParserMode.COMPLETE_PARSE,
|
||||
language, NULL_LOG, getScannerConfig(language), factory);
|
||||
.toOSString(), stream), SCANNER_INFO,
|
||||
ParserMode.COMPLETE_PARSE, language, NULL_LOG,
|
||||
getScannerConfig(language), factory);
|
||||
ISourceCodeParser parser = null;
|
||||
if (language == ParserLanguage.CPP) {
|
||||
parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE,
|
||||
|
@ -146,10 +148,12 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
|
||||
assertSoleFileLocation(FOO,
|
||||
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
IASTPreprocessorIncludeStatement [] incs = tu.getIncludeDirectives();
|
||||
assertNotNull( incs );
|
||||
assertEquals( incs.length, 1 );
|
||||
assertSoleFileLocation( incs[0], "code.cpp", code.indexOf( "#inc"), code.indexOf( ".h\"\n") + ".h\"".length() - code.indexOf( "#inc") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||
IASTPreprocessorIncludeStatement[] incs = tu.getIncludeDirectives();
|
||||
assertNotNull(incs);
|
||||
assertEquals(incs.length, 1);
|
||||
assertSoleFileLocation(
|
||||
incs[0],
|
||||
"code.cpp", code.indexOf("#inc"), code.indexOf(".h\"\n") + ".h\"".length() - code.indexOf("#inc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,18 +172,42 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
|||
IASTSimpleDeclaration bar = (IASTSimpleDeclaration) declarations[0];
|
||||
IASTSimpleDeclaration FOO = (IASTSimpleDeclaration) declarations[1];
|
||||
IASTSimpleDeclaration byob = (IASTSimpleDeclaration) declarations[2];
|
||||
assertSoleFileLocation(bar,
|
||||
"code.cpp", code.indexOf("int"), code.indexOf("r;") + 2 - code.indexOf( "int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
assertSoleFileLocation(FOO,
|
||||
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1 - foo.indexOf( "int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
assertSoleFileLocation( byob, "code.cpp", code.indexOf( "float"), code.indexOf( "b;") + 2 - code.indexOf( "float") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
IASTPreprocessorIncludeStatement [] incs = tu.getIncludeDirectives();
|
||||
assertNotNull( incs );
|
||||
assertEquals( incs.length, 1 );
|
||||
assertSoleFileLocation( incs[0], "code.cpp", code.indexOf( "#inc"), code.indexOf( ".h\"\n") + ".h\"".length() - code.indexOf( "#inc") ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||
assertSoleFileLocation(
|
||||
bar,
|
||||
"code.cpp", code.indexOf("int"), code.indexOf("r;") + 2 - code.indexOf("int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
assertSoleFileLocation(
|
||||
FOO,
|
||||
"foo.h", foo.indexOf("int"), foo.indexOf(";") + 1 - foo.indexOf("int")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
assertSoleFileLocation(
|
||||
byob,
|
||||
"code.cpp", code.indexOf("float"), code.indexOf("b;") + 2 - code.indexOf("float")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
IASTPreprocessorIncludeStatement[] incs = tu.getIncludeDirectives();
|
||||
assertNotNull(incs);
|
||||
assertEquals(incs.length, 1);
|
||||
assertSoleFileLocation(
|
||||
incs[0],
|
||||
"code.cpp", code.indexOf("#inc"), code.indexOf(".h\"\n") + ".h\"".length() - code.indexOf("#inc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||
}
|
||||
}
|
||||
|
||||
public void testMacrosInIncludeFile() throws Exception {
|
||||
String c_file_code = "#define X 4\n\n#include \"blarg.h\"\n\n"; //$NON-NLS-1$
|
||||
String h_file_code = "#ifndef _BLARG_H_\r\n#define _BLARG_H_\r\n// macro\r\n#define PRINT(s,m) printf(s,m)\r\n#endif //_BLARG_H_\r\n"; //$NON-NLS-1$
|
||||
importFile( "blarg.h", h_file_code ); //$NON-NLS-1$
|
||||
IFile c_file = importFile( "blarg.c", c_file_code ); //$NON-NLS-1$
|
||||
for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP
|
||||
: null) {
|
||||
IASTTranslationUnit tu = parse(c_file, p); //$NON-NLS-1$
|
||||
assertEquals( tu.getDeclarations().length, 0 );
|
||||
IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions();
|
||||
assertNotNull( macroDefinitions );
|
||||
assertEquals( macroDefinitions.length, 3 );
|
||||
assertSoleFileLocation( macroDefinitions[0], "blarg.c", c_file_code.indexOf( "#define"), c_file_code.indexOf( "4" ) + 1- c_file_code.indexOf( "#define" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
assertSoleFileLocation( macroDefinitions[1], "blarg.h", h_file_code.indexOf( "#define _BLARG_H_"), "#define _BLARG_H_\r".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
assertSoleFileLocation( macroDefinitions[2], "blarg.h", h_file_code.indexOf( "#define PRINT(s,m) printf(s,m)\r"), "#define PRINT(s,m) printf(s,m)".length() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite(DOMLocationInclusionTests.class);
|
||||
|
|
|
@ -504,6 +504,11 @@ public class CVisitor {
|
|||
return ((IVariable)binding).getType();
|
||||
}
|
||||
}
|
||||
else if( expression instanceof IASTUnaryExpression )
|
||||
{
|
||||
if( ((IASTUnaryExpression)expression).getOperator() == IASTUnaryExpression.op_bracketedPrimary )
|
||||
return getExpressionType(((IASTUnaryExpression)expression).getOperand() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -1346,6 +1346,11 @@ public class CPPVisitor {
|
|||
return fType.getReturnType();
|
||||
}
|
||||
}
|
||||
else if( expression instanceof IASTUnaryExpression )
|
||||
{
|
||||
if( ((IASTUnaryExpression)expression).getOperator() == IASTUnaryExpression.op_bracketedPrimary )
|
||||
return getExpressionType(((IASTUnaryExpression)expression).getOperand() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,10 +114,10 @@ public class DOMScanner extends BaseScanner {
|
|||
int textEnd, int endingLine, IMacro macro) {
|
||||
if (macro instanceof FunctionStyleMacro)
|
||||
locationMap.defineFunctionStyleMacro((FunctionStyleMacro) macro,
|
||||
startingOffset, idstart, idend, textEnd);
|
||||
resolveOffset( startingOffset ), resolveOffset( idstart ), resolveOffset( idend ), resolveOffset( textEnd) );
|
||||
else if (macro instanceof ObjectStyleMacro)
|
||||
locationMap.defineObjectStyleMacro((ObjectStyleMacro) macro,
|
||||
startingOffset, idstart, idend, textEnd);
|
||||
resolveOffset( startingOffset ), resolveOffset( idstart ), resolveOffset( idend ), resolveOffset( textEnd ) );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -712,6 +712,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
|||
_Context nextContext = (_Context) subContexts.get(i);
|
||||
if (nextContext.context_directive_end < offset)
|
||||
bestContext = nextContext;
|
||||
else if( nextContext.context_directive_start < offset && nextContext.context_ends > offset )
|
||||
bestContext = nextContext;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue