public void testStdioBug() throws ParserException { StringBuffer buffer = new StringBuffer("#define _PTR void *\n"); // $NON-NLS-1$ buffer.append("#define __cdecl __attribute__ ((__cdecl__))\n"); // $NON-NLS-1$ buffer.append("#define _EXFUN(name, proto) __cdecl name proto\n"); // $NON-NLS-1$ buffer.append("_PTR _EXFUN(memchr,(const _PTR, int, size_t));\n"); // $NON-NLS-1$ String code = buffer.toString(); for (ParserLanguage language : languages) { IASTTranslationUnit tu = parse(code, language, true, true); final IASTPreprocessorMacroDefinition[] macroDefinitions = tu.getMacroDefinitions(); IASTPreprocessorObjectStyleMacroDefinition _PTR = (IASTPreprocessorObjectStyleMacroDefinition) macroDefinitions[0]; IASTPreprocessorFunctionStyleMacroDefinition _EXFUN = (IASTPreprocessorFunctionStyleMacroDefinition) macroDefinitions[2]; IASTSimpleDeclaration memchr = (IASTSimpleDeclaration) tu.getDeclarations()[0]; IASTNodeLocation[] locations = memchr.getNodeLocations(); assertEquals(locations.length, 4); IASTMacroExpansionLocation loc_1 = (IASTMacroExpansionLocation) locations[0]; assertEqualsMacros(_PTR, loc_1.getExpansion().getMacroDefinition()); IASTFileLocation loc_2 = (IASTFileLocation) locations[1]; assertEquals(loc_2.getNodeOffset(), code.indexOf(" _EXFUN(")); // $NON-NLS-1$ assertEquals(loc_2.getNodeLength(), " ".length()); // $NON-NLS-1$ IASTMacroExpansionLocation loc_3 = (IASTMacroExpansionLocation) locations[2]; assertEqualsMacros(_EXFUN, loc_3.getExpansion().getMacroDefinition()); IASTFileLocation loc_4 = (IASTFileLocation) locations[3]; assertEquals(loc_4.getNodeOffset(), code.indexOf(";")); // $NON-NLS-1$ assertEquals(loc_4.getNodeLength(), 1); 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]; 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$ } }