From ed6c4dc4a0490089fddf8c45183988db8c8802c6 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 29 May 2008 12:38:27 +0000 Subject: [PATCH] Fix undef-statements in index, bug 234591. --- .../org/eclipse/cdt/internal/core/pdom/PDOM.java | 8 ++++++-- .../eclipse/cdt/internal/core/pdom/dom/PDOMFile.java | 11 ++++++----- .../eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java | 5 ++--- .../eclipse/cdt/internal/ui/viewsupport/IndexUI.java | 6 +++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java index 2cb12a1bdb6..95eea8b18fd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOM.java @@ -104,7 +104,7 @@ public class PDOM extends PlatformObject implements IPDOM { private static int version(int major, int minor) { return major << 16 + minor; } - public static final int MAJOR_VERSION = 60; + public static final int MAJOR_VERSION = 61; public static final int MINOR_VERSION = 0; // minor versions must be compatible public static final int CURRENT_VERSION= version(MAJOR_VERSION, MINOR_VERSION); @@ -174,6 +174,7 @@ public class PDOM extends PlatformObject implements IPDOM { * 58.0 - non-type parameters (bug 207840) * 59.0 - changed modeling of deferred class instances (bug 229218) * 60.0 - store integral values with basic types (bug 207871) + * 61.0 - properly insert macro undef statements into macro-containers (bug 234591) */ public static final int LINKAGES = Database.DATA_AREA; @@ -800,7 +801,10 @@ public class PDOM extends PlatformObject implements IPDOM { throws CoreException { if ((options & FIND_DEFINITIONS) != 0) { for (PDOMMacro macro= container.getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) { - names.add(macro.getDefinition()); + final IIndexFragmentName name = macro.getDefinition(); + if (name != null) { + names.add(name); + } } } if ((options & FIND_REFERENCES) != 0) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index 4bde0394170..dd9feab4465 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -472,12 +472,13 @@ public class PDOMFile implements IIndexFragmentFile { } } - for (PDOMMacro name= getFirstMacro(); name != null; name= name.getNextMacro()) { - int nameOffset= name.getNodeOffset(); + for (PDOMMacro macro= getFirstMacro(); macro != null; macro= macro.getNextMacro()) { + int nameOffset= macro.getNodeOffset(); if (nameOffset >= offset) { - if (nameOffset + name.getNodeLength() <= offset+length) { - if (name.isMacroDefinition()) { - result.add(name.getDefinition()); + if (nameOffset + macro.getNodeLength() <= offset+length) { + IIndexFragmentName name= macro.getDefinition(); + if (name != null) { + result.add(name); } } else { break; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java index 208880e35c0..c349629d86d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java @@ -10,7 +10,6 @@ * Markus Schorn (Wind River Systems) * Andrew Ferguson (Symbian) *******************************************************************************/ - package org.eclipse.cdt.internal.core.pdom.dom; import java.net.URI; @@ -90,8 +89,6 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo } db.putInt(fRecord + PARAMETERS, db.newString(buf.toString().toCharArray()).getRecord()); } - - container.addDefinition(this); } public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorUndefStatement undef, PDOMFile file) throws CoreException { @@ -109,6 +106,8 @@ public class PDOMMacro implements IIndexMacro, IIndexFragmentBinding, IASTFileLo db.putInt(fRecord + FILE, file.getRecord()); db.putInt(fRecord + NAME_OFFSET, fileloc.getNodeOffset()); db.putShort(fRecord + NAME_LENGTH, (short) fileloc.getNodeLength()); + + container.addDefinition(this); } public PDOM getPDOM() { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 981ec640e2e..1346017323c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -345,9 +345,9 @@ public class IndexUI { throws CoreException { ITranslationUnit tu= getTranslationUnit(preferProject, macro.getFileLocation()); if (tu != null) { - IIndexName def= macro.getDefinition(); - if (def != null) { - IRegion region= new Region(def.getNodeOffset(), def.getNodeLength()); + IIndexName name= macro.getDefinition(); + if (name != null) { + IRegion region= new Region(name.getNodeOffset(), name.getNodeLength()); long timestamp= macro.getFile().getTimestamp(); return CElementHandleFactory.create(tu, macro, region, timestamp); }