From f19c9e90612f49b6dd2ae34f9f2a55fdb3c6ce36 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Wed, 1 Jun 2005 13:56:45 +0000 Subject: [PATCH] Fixed Bug 94933 - IASTTranslationUnit.flattenLocationsToFile does not work correctly --- .../parser/tests/ast2/DOMLocationMacroTests.java | 14 ++++++++++++++ .../internal/core/parser/scanner2/LocationMap.java | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java index 1ff20107243..df451112ee2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core.parser.tests.ast2; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; +import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition; import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; @@ -322,4 +323,17 @@ public class DOMLocationMacroTests extends AST2BaseTest { assertEquals( "MACRO".length(), loc.getNodeLength() ); //$NON-NLS-1$ } } + + public void testBug94933() throws Exception { + StringBuffer buffer = new StringBuffer( "#define API extern\n" ); + buffer.append( "#define MYAPI API\n"); + buffer.append( "MYAPI void func() {}" ); + String code = buffer.toString(); + for (ParserLanguage p = ParserLanguage.C; p != null; p = (p == ParserLanguage.C) ? ParserLanguage.CPP + : null) { + IASTTranslationUnit tu = parse(code, p); + IASTFunctionDefinition f = (IASTFunctionDefinition) tu.getDeclarations()[0]; + assertNotNull( f.getFileLocation() ); + } + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 5491df4c4f3..674ec3fd42f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -2395,8 +2395,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } else { if( result[i] != null && !result[i].getFileName().equals( filename ) ) return null; + if( result[i].getNodeOffset() == result[i-1].getNodeOffset() ) + continue; if (result[i] != null - && result[i].getNodeOffset() != (offset + length)) + && result[i].getNodeOffset() != (offset + length) ) return null; if (result[i] != null) length += result[i].getNodeLength();