Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-02-11 15:27:26 -0500
committerSergey Prigogin2012-02-11 15:27:26 -0500
commit2fd430eb63dbbb970dd781aea41ac9c38fa726c5 (patch)
tree2d50b07d6166d019d27ca9df1a068a3ce3471e4d /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter
parentd7b07a626d8c17614b282ce82c2af74b6dc1ce40 (diff)
downloadorg.eclipse.cdt-2fd430eb63dbbb970dd781aea41ac9c38fa726c5.tar.gz
org.eclipse.cdt-2fd430eb63dbbb970dd781aea41ac9c38fa726c5.tar.xz
org.eclipse.cdt-2fd430eb63dbbb970dd781aea41ac9c38fa726c5.zip
Added IASTNode.getOriginalNode method.
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/ASTWriterVisitor.java12
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/MacroExpansionHandler.java61
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java21
3 files changed, 34 insertions, 60 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java
index ef08a0ba86..4f63e427e7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ASTWriterVisitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2012 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
@@ -19,7 +19,6 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTComment;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
-import org.eclipse.cdt.core.dom.ast.IASTCopyLocation;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@@ -27,7 +26,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
@@ -130,11 +128,9 @@ public class ASTWriterVisitor extends ASTVisitor {
private List<IASTComment> getLeadingComments(IASTNode node) {
List<IASTComment> leadingComments = commentMap.getLeadingCommentsForNode(node);
- IASTNodeLocation[] locs = node.getNodeLocations();
- if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
- IASTCopyLocation copyLoc = (IASTCopyLocation) locs[0];
- leadingComments.addAll(commentMap.getLeadingCommentsForNode(copyLoc.getOriginalNode()));
- }
+ IASTNode originalNode = node.getOriginalNode();
+ if (originalNode != node)
+ leadingComments.addAll(commentMap.getLeadingCommentsForNode(originalNode));
return leadingComments;
}
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 1a6910dfea..49315c0d27 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, 2009 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2012 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
@@ -8,6 +8,7 @@
*
* Contributors:
* Institute for Software - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -18,7 +19,6 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
-import org.eclipse.cdt.core.dom.ast.IASTCopyLocation;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -41,9 +41,9 @@ import org.eclipse.core.runtime.CoreException;
* @author Emanuel Graf IFS
*/
public class MacroExpansionHandler {
- private int lastMacroExpOffset;
private final Scribe scribe;
- private IASTTranslationUnit tu;
+ private int lastMacroExpOffset;
+ private IASTTranslationUnit ast;
private Map<String, List<IIndexName>> macroExpansion = new TreeMap<String, List<IIndexName>>();
public MacroExpansionHandler(Scribe scribe) {
@@ -81,11 +81,11 @@ public class MacroExpansionHandler {
protected boolean checkisMacroExpansionNode(IASTNode node, boolean write) {
IASTTranslationUnit unit = node.getTranslationUnit();
- if (tu == null || !tu.equals(unit)) {
+ if (ast == null || !ast.equals(unit)) {
initEmptyMacros(unit);
}
IASTNodeLocation[] locs = getNodeLocations(node);
- if (locs != null && locs.length ==1) {
+ if (locs != null && locs.length == 1) {
if (locs[0] instanceof IASTMacroExpansionLocation) {
IASTMacroExpansionLocation macroNode = (IASTMacroExpansionLocation) locs[0];
@@ -94,7 +94,7 @@ public class MacroExpansionHandler {
}
if (write) {
lastMacroExpOffset = macroNode.asFileLocation().getNodeOffset();
- node = getOriginalNode(node);
+ node = node.getOriginalNode();
scribe.print(node.getRawSignature());
}
return true;
@@ -105,24 +105,13 @@ public class MacroExpansionHandler {
return false;
}
- private IASTNode getOriginalNode(IASTNode node) {
- IASTNodeLocation[] locs = node.getNodeLocations();
- if (locs != null && locs.length == 1 && locs[0] instanceof IASTCopyLocation) {
- node = ((IASTCopyLocation) locs[0]).getOriginalNode();
- }
- return node;
- }
-
private IASTNodeLocation[] getNodeLocations(IASTNode node) {
- IASTNodeLocation[] locs = node.getNodeLocations();
- if (locs != null && locs.length == 1 && locs[0] instanceof IASTCopyLocation) {
- locs = ((IASTCopyLocation) locs[0]).getOriginalNode().getNodeLocations();
- }
- return locs;
+ return node.getOriginalNode().getNodeLocations();
}
private void handleEmptyMacroExpansion(IASTNode node) {
- if (node.getTranslationUnit() == null)return;
+ if (node.getTranslationUnit() == null)
+ return;
String file = node.getContainingFilename();
List<IIndexName> exps = macroExpansion.get(file);
if (exps != null && !exps.isEmpty()) {
@@ -144,46 +133,40 @@ public class MacroExpansionHandler {
}
private IASTFileLocation getFileLocation(IASTNode node) {
- IASTFileLocation fileLocation = node.getFileLocation();
- if (fileLocation == null) {
- IASTNodeLocation[] locs = node.getNodeLocations();
- if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
- fileLocation = ((IASTCopyLocation) locs[0]).getOriginalNode().getFileLocation();
- }
- }
- return fileLocation;
+ return node.getOriginalNode().getFileLocation();
}
private void initEmptyMacros(IASTTranslationUnit unit) {
if (unit != null) {
- tu = unit;
- IIndex index = tu.getIndex();
+ ast = unit;
+ IIndex index = ast.getIndex();
if (index != null) {
macroExpansion = new TreeMap<String, List<IIndexName>>();
- IASTPreprocessorMacroDefinition[] md = tu.getMacroDefinitions();
+ IASTPreprocessorMacroDefinition[] md = ast.getMacroDefinitions();
TreeSet<String>paths = new TreeSet<String>();
- for (IASTPreprocessorIncludeStatement is :tu.getIncludeDirectives()) {
+ for (IASTPreprocessorIncludeStatement is :ast.getIncludeDirectives()) {
if (!is.isSystemInclude()) {
paths.add(is.getContainingFilename());
}
}
- paths.add(tu.getContainingFilename());
+ paths.add(ast.getContainingFilename());
for (IASTPreprocessorMacroDefinition iastPreprocessorMacroDefinition : md) {
if (iastPreprocessorMacroDefinition.getExpansion().length() == 0) {
try {
- IIndexMacro[] macroBinding = index.findMacros(iastPreprocessorMacroDefinition.getName().toCharArray(),
+ 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)) {
+ String filename = iIndexName.getFileLocation().getFileName();
+ List<IIndexName> fileList = macroExpansion.get(filename);
+ if (paths.contains(filename)) {
if (fileList == null) {
fileList = new ArrayList<IIndexName>();
- macroExpansion.put(filename2, fileList);
+ macroExpansion.put(filename, fileList);
}
fileList.add(iIndexName);
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
index aa160a77bd..1a5e4b1e44 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/NodeWriter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2012 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
@@ -8,15 +8,14 @@
*
* Contributors:
* Institute for Software - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTComment;
-import org.eclipse.cdt.core.dom.ast.IASTCopyLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
-import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
/**
@@ -108,11 +107,9 @@ public class NodeWriter {
private List<IASTComment> getTrailingComments(IASTNode node) {
List<IASTComment> trailingComments = commentMap.getTrailingCommentsForNode(node);
- IASTNodeLocation[] locs = node.getNodeLocations();
- if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
- IASTCopyLocation loc = (IASTCopyLocation) locs[0];
- trailingComments.addAll(commentMap.getTrailingCommentsForNode(loc.getOriginalNode()));
- }
+ IASTNode originalNode = node.getOriginalNode();
+ if (originalNode != node)
+ trailingComments.addAll(commentMap.getTrailingCommentsForNode(originalNode));
return trailingComments;
}
@@ -122,11 +119,9 @@ public class NodeWriter {
private List<IASTComment> getFreestandingComments(IASTNode node) {
List<IASTComment> freestandingComments = commentMap.getFreestandingCommentsForNode(node);
- IASTNodeLocation[] locs = node.getNodeLocations();
- if (locs != null && locs.length > 0 && locs[0] instanceof IASTCopyLocation) {
- IASTCopyLocation loc = (IASTCopyLocation) locs[0];
- freestandingComments.addAll(commentMap.getFreestandingCommentsForNode(loc.getOriginalNode()));
- }
+ IASTNode originalNode = node.getOriginalNode();
+ if (originalNode != node)
+ freestandingComments.addAll(commentMap.getFreestandingCommentsForNode(originalNode));
return freestandingComments;
}

Back to the top