mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Devin Steffler.
Further AST View - Preprocessor statements.
This commit is contained in:
parent
d6b9097bd5
commit
b0f858c25b
2 changed files with 54 additions and 41 deletions
|
@ -44,6 +44,7 @@ import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTInclusionSta
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
*/
|
*/
|
||||||
public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IPopulateDOMASTAction {
|
public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IPopulateDOMASTAction {
|
||||||
|
private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8;
|
||||||
{
|
{
|
||||||
processNames = true;
|
processNames = true;
|
||||||
processDeclarations = true;
|
processDeclarations = true;
|
||||||
|
@ -215,10 +216,10 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
||||||
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeMacros(IASTPreprocessorMacroDefinition[] macros) {
|
private void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||||
for(int i=0; i<macros.length; i++) {
|
for(int i=0; i<statements.length; i++) {
|
||||||
if (macros[i] instanceof ASTNode)
|
if (statements[i] instanceof ASTNode)
|
||||||
mergeNode((ASTNode)macros[i]);
|
mergeNode((ASTNode)statements[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,35 +230,41 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeIncludeDirectives(IASTPreprocessorIncludeStatement[] includes) {
|
|
||||||
for(int i=0; i<includes.length; i++) {
|
|
||||||
if (includes[i] instanceof ASTNode)
|
|
||||||
mergeNode((ASTNode)includes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TreeParent getTree() {
|
public TreeParent getTree() {
|
||||||
if (root.getNode() instanceof IASTTranslationUnit) {
|
if (root.getNode() instanceof IASTTranslationUnit) {
|
||||||
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
||||||
|
|
||||||
// merge macro definitions to the tree
|
IASTPreprocessorStatement[] statements = tu.getAllPreprocessorStatements();
|
||||||
mergeMacros(tu.getMacroDefinitions());
|
// merge preprocessor statements to the tree
|
||||||
|
mergePreprocessorStatements(statements);
|
||||||
|
|
||||||
// merge preprocessor problems to the tree
|
// merge preprocessor problems to the tree
|
||||||
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
||||||
|
|
||||||
// merge include directives
|
|
||||||
IASTPreprocessorIncludeStatement[] includes = tu.getIncludeDirectives();
|
|
||||||
mergeIncludeDirectives(includes);
|
|
||||||
|
|
||||||
// group #includes
|
// group #includes
|
||||||
groupIncludes(includes);
|
groupIncludes(statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void groupIncludes(IASTPreprocessorIncludeStatement[] includes) {
|
private void groupIncludes(IASTPreprocessorStatement[] statements) {
|
||||||
|
// get all of the includes from the preprocessor statements (need the object since .equals isn't implemented)
|
||||||
|
IASTPreprocessorIncludeStatement[] includes = new IASTPreprocessorIncludeStatement[INITIAL_INCLUDE_STATEMENT_SIZE];
|
||||||
|
int index = 0;
|
||||||
|
for(int i=0; i<statements.length; i++) {
|
||||||
|
if (index+1 > includes.length) {
|
||||||
|
IASTPreprocessorIncludeStatement[] newIncludes = new IASTPreprocessorIncludeStatement[includes.length * 2];
|
||||||
|
for (int j=0; j<includes.length; j++) {
|
||||||
|
newIncludes[j] = includes[j];
|
||||||
|
}
|
||||||
|
includes = newIncludes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statements[i] instanceof IASTPreprocessorIncludeStatement)
|
||||||
|
includes[index++] = (IASTPreprocessorIncludeStatement)statements[i];
|
||||||
|
}
|
||||||
|
|
||||||
// get the tree model elements corresponding to the includes
|
// get the tree model elements corresponding to the includes
|
||||||
TreeParent[] treeIncludes = new TreeParent[includes.length];
|
TreeParent[] treeIncludes = new TreeParent[includes.length];
|
||||||
for (int i=0; i<treeIncludes.length; i++) {
|
for (int i=0; i<treeIncludes.length; i++) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTInclusionSta
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
*/
|
*/
|
||||||
public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopulateDOMASTAction {
|
public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopulateDOMASTAction {
|
||||||
|
private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8;
|
||||||
{
|
{
|
||||||
processNames = true;
|
processNames = true;
|
||||||
processDeclarations = true;
|
processDeclarations = true;
|
||||||
|
@ -194,10 +195,10 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
||||||
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeMacros(IASTPreprocessorMacroDefinition[] macros) {
|
private void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
|
||||||
for(int i=0; i<macros.length; i++) {
|
for(int i=0; i<statements.length; i++) {
|
||||||
if (macros[i] instanceof ASTNode)
|
if (statements[i] instanceof ASTNode)
|
||||||
mergeNode((ASTNode)macros[i]);
|
mergeNode((ASTNode)statements[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,35 +209,41 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeIncludeDirectives(IASTPreprocessorIncludeStatement[] includes) {
|
|
||||||
for(int i=0; i<includes.length; i++) {
|
|
||||||
if (includes[i] instanceof ASTNode)
|
|
||||||
mergeNode((ASTNode)includes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TreeParent getTree() {
|
public TreeParent getTree() {
|
||||||
if (root.getNode() instanceof IASTTranslationUnit) {
|
if (root.getNode() instanceof IASTTranslationUnit) {
|
||||||
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
||||||
|
|
||||||
// merge macro definitions to the tree
|
IASTPreprocessorStatement[] statements = tu.getAllPreprocessorStatements();
|
||||||
mergeMacros(tu.getMacroDefinitions());
|
// merge preprocessor statements to the tree
|
||||||
|
mergePreprocessorStatements(statements);
|
||||||
|
|
||||||
// merge preprocessor problems to the tree
|
// merge preprocessor problems to the tree
|
||||||
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
||||||
|
|
||||||
// merge include directives
|
|
||||||
IASTPreprocessorIncludeStatement[] includes = tu.getIncludeDirectives();
|
|
||||||
mergeIncludeDirectives(includes);
|
|
||||||
|
|
||||||
// group #includes
|
// group #includes
|
||||||
groupIncludes(includes);
|
groupIncludes(statements);
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void groupIncludes(IASTPreprocessorIncludeStatement[] includes) {
|
private void groupIncludes(IASTPreprocessorStatement[] statements) {
|
||||||
|
// get all of the includes from the preprocessor statements (need the object since .equals isn't implemented)
|
||||||
|
IASTPreprocessorIncludeStatement[] includes = new IASTPreprocessorIncludeStatement[INITIAL_INCLUDE_STATEMENT_SIZE];
|
||||||
|
int index = 0;
|
||||||
|
for(int i=0; i<statements.length; i++) {
|
||||||
|
if (index+1 > includes.length) {
|
||||||
|
IASTPreprocessorIncludeStatement[] newIncludes = new IASTPreprocessorIncludeStatement[includes.length * 2];
|
||||||
|
for (int j=0; j<includes.length; j++) {
|
||||||
|
newIncludes[j] = includes[j];
|
||||||
|
}
|
||||||
|
includes = newIncludes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statements[i] instanceof IASTPreprocessorIncludeStatement)
|
||||||
|
includes[index++] = (IASTPreprocessorIncludeStatement)statements[i];
|
||||||
|
}
|
||||||
|
|
||||||
// get the tree model elements corresponding to the includes
|
// get the tree model elements corresponding to the includes
|
||||||
TreeParent[] treeIncludes = new TreeParent[includes.length];
|
TreeParent[] treeIncludes = new TreeParent[includes.length];
|
||||||
for (int i=0; i<treeIncludes.length; i++) {
|
for (int i=0; i<treeIncludes.length; i++) {
|
||||||
|
@ -262,5 +269,4 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue