Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuel Graf2009-07-29 04:46:31 -0400
committerEmanuel Graf2009-07-29 04:46:31 -0400
commitb86829cf941c56d49bada748d712d7fa7f9e12c1 (patch)
tree6ac4a5b056c25c30772c4b1836f1e549bb372bbc /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter
parentdf498b476f3f3fd088bd0ea131f6f310817aee80 (diff)
downloadorg.eclipse.cdt-b86829cf941c56d49bada748d712d7fa7f9e12c1.tar.gz
org.eclipse.cdt-b86829cf941c56d49bada748d712d7fa7f9e12c1.tar.xz
org.eclipse.cdt-b86829cf941c56d49bada748d712d7fa7f9e12c1.zip
FIXED - bug 280432: Refactoring removes comments in class header file and reformats file.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=280432
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java94
1 files changed, 93 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java
index 08562c0426..89f4bb068d 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,10 +11,27 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
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.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.index.IIndexMacro;
+import org.eclipse.cdt.core.index.IIndexName;
+import org.eclipse.cdt.core.index.IndexFilter;
+import org.eclipse.cdt.internal.core.pdom.dom.PDOMMacroReferenceName;
+import org.eclipse.core.runtime.CoreException;
/**
*
@@ -27,6 +44,8 @@ public class MacroExpansionHandler {
private int lastMacroExpOffset;
private final Scribe scribe;
+ private IASTTranslationUnit tu;
+ private Map<String, List<IIndexName>> macroExpansion = new TreeMap<String, List<IIndexName>>();
public MacroExpansionHandler(Scribe scribe) {
this.scribe = scribe;
@@ -61,6 +80,10 @@ public class MacroExpansionHandler {
}
protected boolean checkisMacroExpansionNode(IASTNode node, boolean write) {
+ IASTTranslationUnit unit = node.getTranslationUnit();
+ if(tu == null || !tu.equals(unit)) {
+ initEmptyMacros(unit);
+ }
IASTNodeLocation[] locs = node.getNodeLocations();
if (locs != null && locs.length ==1) {
if (locs[0] instanceof IASTMacroExpansionLocation) {
@@ -77,9 +100,78 @@ public class MacroExpansionHandler {
}
}
+ handleEmptyMacroExpansion(node);
return false;
}
+ private void handleEmptyMacroExpansion(IASTNode node) {
+ if(node.getTranslationUnit() == null)return;
+ String file = node.getContainingFilename();
+ List<IIndexName> exps = macroExpansion.get(file);
+ if(exps != null && !exps.isEmpty()) {
+ IASTFileLocation fileLocation = node.getFileLocation();
+ if(fileLocation != null) {
+ int nOff = fileLocation.getNodeOffset();
+ for (IIndexName iIndexName : exps) {
+ if (iIndexName instanceof PDOMMacroReferenceName) {
+ PDOMMacroReferenceName mName = (PDOMMacroReferenceName) iIndexName;
+ int eOff = mName.getFileLocation().getNodeOffset();
+ int eLength = mName.getFileLocation().getNodeLength();
+ if(eOff < nOff && Math.abs((eOff+eLength-nOff)) < 3) {
+ scribe.print(mName.toString() + " ");
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ private void initEmptyMacros(IASTTranslationUnit unit) {
+ if (unit != null) {
+ tu = unit;
+ IIndex index = tu.getIndex();
+ if(index != null) {
+ macroExpansion = new TreeMap<String, List<IIndexName>>();
+ IASTPreprocessorMacroDefinition[] md = tu.getMacroDefinitions();
+
+ TreeSet<String>paths = new TreeSet<String>();
+ for(IASTPreprocessorIncludeStatement is :tu.getIncludeDirectives()) {
+ if(!is.isSystemInclude()) {
+ paths.add(is.getContainingFilename());
+ }
+ }
+ paths.add(tu.getContainingFilename());
+
+ for (IASTPreprocessorMacroDefinition iastPreprocessorMacroDefinition : md) {
+ if(iastPreprocessorMacroDefinition.getExpansion().length() == 0) {
+ try {
+ IIndexMacro[] macroBinding = index.findMacros(iastPreprocessorMacroDefinition.getName().toCharArray(), IndexFilter.ALL, null);
+ if(macroBinding.length > 0) {
+ IIndexName[] refs = index.findReferences(macroBinding[0]);
+ for (IIndexName iIndexName : refs) {
+ String filename2 = iIndexName.getFileLocation().getFileName();
+ List<IIndexName>fileList = macroExpansion.get(filename2);
+ if (paths.contains(filename2)) {
+ if(fileList == null) {
+ fileList = new ArrayList<IIndexName>();
+ macroExpansion.put(filename2, fileList);
+ }
+ fileList.add(iIndexName);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }else {
+ macroExpansion = Collections.emptyMap();
+ }
+ }
+ }
+
public void reset(){
lastMacroExpOffset = -1;
}

Back to the top