Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 25043 Details for
Bug 94989
Binary Search in Find in DOM AST VIew doesn't always work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
fix for this PR
cdt_ui_tests_patch.txt (text/plain), 48.40 KB, created by
Devin Steffler
on 2005-07-20 10:35:53 EDT
(
hide
)
Description:
fix for this PR
Filename:
MIME Type:
Creator:
Devin Steffler
Created:
2005-07-20 10:35:53 EDT
Size:
48.40 KB
patch
obsolete
>Index: src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java,v >retrieving revision 1.21 >diff -u -r1.21 CPPPopulateASTViewAction.java >--- src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java 27 Jun 2005 03:44:52 -0000 1.21 >+++ src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java 20 Jul 2005 14:33:32 -0000 >@@ -48,7 +48,6 @@ > */ > public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulateDOMASTAction { > private static final int INITIAL_PROBLEM_SIZE = 4; >- private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8; > { > shouldVisitNames = true; > shouldVisitDeclarations = true; >@@ -73,14 +72,28 @@ > this.monitor = monitor; > } > >- private int addRoot(IASTNode node) { >- if (monitor != null && monitor.isCanceled()) return PROCESS_ABORT; >- if (node == null) return PROCESS_CONTINUE; >+ private class DOMASTNodeLeafContinue extends DOMASTNodeLeaf { >+ public DOMASTNodeLeafContinue(IASTNode node) { >+ super(node); >+ } >+ } >+ >+ /** >+ * return null if the algorithm should stop (monitor was cancelled) >+ * return DOMASTNodeLeafContinue if the algorithm should continue but no valid DOMASTNodeLeaf was added (i.e. node was null >+ * return the DOMASTNodeLeaf added to the DOM AST View's model otherwise >+ * >+ * @param node >+ * @return >+ */ >+ private DOMASTNodeLeaf addRoot(IASTNode node) { >+ if (monitor != null && monitor.isCanceled()) return null; >+ if (node == null) return new DOMASTNodeLeafContinue(null); > > // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive) > if (!(node instanceof ICPPASTLinkageSpecification) && > node instanceof ASTNode && ((ASTNode)node).getLength() <= 0) >- return PROCESS_CONTINUE; >+ return new DOMASTNodeLeafContinue(null); > > DOMASTNodeParent parent = null; > >@@ -99,12 +112,10 @@ > if (parent == null) > parent = root; > >- createNode(parent, node); >- >- return PROCESS_CONTINUE; >+ return createNode(parent, node); > } > >- private void createNode(DOMASTNodeParent parent, IASTNode node) { >+ private DOMASTNodeLeaf createNode(DOMASTNodeParent parent, IASTNode node) { > DOMASTNodeParent tree = new DOMASTNodeParent(node); > parent.addChild(tree); > >@@ -121,20 +132,28 @@ > tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR); > if (node instanceof IASTPreprocessorIncludeStatement) > tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS); >+ >+ return tree; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) > */ > public int visit(IASTDeclaration declaration) { >- return addRoot(declaration); >+ DOMASTNodeLeaf temp = addRoot(declaration); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) > */ > public int visit(IASTDeclarator declarator) { >- int ret = addRoot(declarator); >+ DOMASTNodeLeaf temp = addRoot(declarator); > > IASTPointerOperator[] ops = declarator.getPointerOperators(); > for(int i=0; i<ops.length; i++) >@@ -160,58 +179,108 @@ > } > } > >- return ret; >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) > */ > public int visit(ICPPASTBaseSpecifier specifier) { >- return addRoot(specifier); >+ DOMASTNodeLeaf temp = addRoot(specifier); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) > */ > public int visit(IASTDeclSpecifier declSpec) { >- return addRoot(declSpec); >+ DOMASTNodeLeaf temp = addRoot(declSpec); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) > */ > public int visit(IASTEnumerator enumerator) { >- return addRoot(enumerator); >+ DOMASTNodeLeaf temp = addRoot(enumerator); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) > */ > public int visit(IASTExpression expression) { >- return addRoot(expression); >+ DOMASTNodeLeaf temp = addRoot(expression); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) > */ > public int visit(IASTInitializer initializer) { >- return addRoot(initializer); >+ DOMASTNodeLeaf temp = addRoot(initializer); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) > */ > public int visit(IASTName name) { >+ DOMASTNodeLeaf temp = null; > if (name.toString() != null) >- return addRoot(name); >- return PROCESS_CONTINUE; >+ temp = addRoot(name); >+ else >+ return PROCESS_CONTINUE; >+ >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) > */ > public int visit(ICPPASTNamespaceDefinition namespace) { >- return addRoot(namespace); >+ DOMASTNodeLeaf temp = addRoot(namespace); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) >@@ -219,37 +288,60 @@ > */ > public int visit( > IASTParameterDeclaration parameterDeclaration) { >- return addRoot(parameterDeclaration); >+ DOMASTNodeLeaf temp = addRoot(parameterDeclaration); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) > */ > public int visit(IASTStatement statement) { >- return addRoot(statement); >+ DOMASTNodeLeaf temp = addRoot(statement); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) > */ > public int visit(IASTTypeId typeId) { >- return addRoot(typeId); >+ DOMASTNodeLeaf temp = addRoot(typeId); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > >- private void mergeNode(ASTNode node) { >- addRoot(node); >+ private DOMASTNodeLeaf mergeNode(ASTNode node) { >+ DOMASTNodeLeaf leaf = addRoot(node); > > if (node instanceof IASTPreprocessorMacroDefinition) > addRoot(((IASTPreprocessorMacroDefinition)node).getName()); >+ >+ return leaf; > } > >- public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) { >+ public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements) { >+ DOMASTNodeLeaf[] leaves = new DOMASTNodeLeaf[statements.length]; > for(int i=0; i<statements.length; i++) { >- if (monitor != null && monitor.isCanceled()) return; >+ if (monitor != null && monitor.isCanceled()) return leaves; > > if (statements[i] instanceof ASTNode) >- mergeNode((ASTNode)statements[i]); >+ leaves[i] = mergeNode((ASTNode)statements[i]); > } >+ >+ return leaves; > } > > public void mergePreprocessorProblems(IASTProblem[] problems) { >@@ -265,45 +357,25 @@ > return root; > } > >- public 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 (monitor != null && monitor.isCanceled()) return; >- if (statements[i] instanceof IASTPreprocessorIncludeStatement) { >- if (index == includes.length) { >- includes = (IASTPreprocessorIncludeStatement[])ArrayUtil.append(IASTPreprocessorIncludeStatement.class, includes, statements[i]); >- index++; >- } else { >- includes[index++] = (IASTPreprocessorIncludeStatement)statements[i]; >- } >- } >- } >- >- // get the tree model elements corresponding to the includes >- DOMASTNodeParent[] treeIncludes = new DOMASTNodeParent[index]; >- for (int i=0; i<treeIncludes.length; i++) { >- if (monitor != null && monitor.isCanceled()) return; >- treeIncludes[i] = root.findTreeObject(includes[i], false); >- } >- >+ public void groupIncludes(DOMASTNodeLeaf[] treeIncludes) { > // loop through the includes and make sure that all of the nodes > // that are children of the TU are in the proper include (based on offset) > DOMASTNodeLeaf child = null; > outerLoop: for (int i=treeIncludes.length-1; i>=0; i--) { > if (treeIncludes[i] == null) continue; > >+ IASTNode node = null; > for(int j=root.getChildren(false).length-1; j>=0; j--) { >- if (monitor != null && monitor.isCanceled()) return; >+// if (monitor != null && monitor.isCanceled()) return; // this causes a deadlock when checked here > child = root.getChildren(false)[j]; > >+ node = treeIncludes[i].getNode(); > if (child != null && treeIncludes[i] != child && >- includes[i] instanceof ASTInclusionStatement && >- ((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)includes[i]).startOffset && >- ((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)includes[i]).endOffset) { >+ node instanceof ASTInclusionStatement && >+ ((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)node).startOffset && >+ ((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)node).endOffset) { > root.removeChild(child); >- treeIncludes[i].addChild(child); >+ ((DOMASTNodeParent)treeIncludes[i]).addChild(child); > } > } > } >Index: src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java,v >retrieving revision 1.25 >diff -u -r1.25 CPopulateASTViewAction.java >--- src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java 27 Jun 2005 03:44:52 -0000 1.25 >+++ src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java 20 Jul 2005 14:33:32 -0000 >@@ -42,7 +42,6 @@ > */ > public class CPopulateASTViewAction extends CASTVisitor implements IPopulateDOMASTAction { > private static final int INITIAL_PROBLEM_SIZE = 4; >- private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8; > { > shouldVisitNames = true; > shouldVisitDeclarations = true; >@@ -66,13 +65,27 @@ > this.monitor = monitor; > } > >- private int addRoot(IASTNode node) { >- if (monitor != null && monitor.isCanceled()) return PROCESS_ABORT; >- if (node == null) return PROCESS_CONTINUE; >+ private class DOMASTNodeLeafContinue extends DOMASTNodeLeaf { >+ public DOMASTNodeLeafContinue(IASTNode node) { >+ super(node); >+ } >+ } >+ >+ /** >+ * return null if the algorithm should stop (monitor was cancelled) >+ * return DOMASTNodeLeafContinue if the algorithm should continue but no valid DOMASTNodeLeaf was added (i.e. node was null >+ * return the DOMASTNodeLeaf added to the DOM AST View's model otherwise >+ * >+ * @param node >+ * @return >+ */ >+ private DOMASTNodeLeaf addRoot(IASTNode node) { >+ if (monitor != null && monitor.isCanceled()) return null; >+ if (node == null) return new DOMASTNodeLeafContinue(null); > > // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive) > if (node instanceof ASTNode && ((ASTNode)node).getLength() <= 0) >- return PROCESS_CONTINUE; >+ return new DOMASTNodeLeafContinue(null); > > DOMASTNodeParent parent = null; > >@@ -91,12 +104,10 @@ > if (parent == null) > parent = root; > >- createNode(parent, node); >- >- return PROCESS_CONTINUE; >+ return createNode(parent, node); > } > >- private void createNode(DOMASTNodeParent parent, IASTNode node) { >+ private DOMASTNodeLeaf createNode(DOMASTNodeParent parent, IASTNode node) { > DOMASTNodeParent tree = new DOMASTNodeParent(node); > parent.addChild(tree); > >@@ -113,20 +124,28 @@ > tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR); > if (node instanceof IASTPreprocessorIncludeStatement) > tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS); >+ >+ return tree; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) > */ > public int visit(IASTDeclaration declaration) { >- return addRoot(declaration); >+ DOMASTNodeLeaf temp = addRoot(declaration); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) > */ > public int visit(IASTDeclarator declarator) { >- int ret = addRoot(declarator); >+ DOMASTNodeLeaf temp = addRoot(declarator); > > IASTPointerOperator[] ops = declarator.getPointerOperators(); > for(int i=0; i<ops.length; i++) >@@ -138,51 +157,94 @@ > addRoot(mods[i]); > } > >- return ret; >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator) > */ > public int visit(ICASTDesignator designator) { >- return addRoot(designator); >+ DOMASTNodeLeaf temp = addRoot(designator); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) > */ > public int visit(IASTDeclSpecifier declSpec) { >- return addRoot(declSpec); >+ DOMASTNodeLeaf temp = addRoot(declSpec); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) > */ > public int visit(IASTEnumerator enumerator) { >- return addRoot(enumerator); >+ DOMASTNodeLeaf temp = addRoot(enumerator); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) > */ > public int visit(IASTExpression expression) { >- return addRoot(expression); >+ DOMASTNodeLeaf temp = addRoot(expression); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) > */ > public int visit(IASTInitializer initializer) { >- return addRoot(initializer); >+ DOMASTNodeLeaf temp = addRoot(initializer); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName) > */ > public int visit(IASTName name) { >+ DOMASTNodeLeaf temp = null; > if ( name.toString() != null ) >- return addRoot(name); >- return PROCESS_CONTINUE; >+ temp = addRoot(name); >+ else >+ return PROCESS_CONTINUE; >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) >@@ -190,37 +252,60 @@ > */ > public int visit( > IASTParameterDeclaration parameterDeclaration) { >- return addRoot(parameterDeclaration); >+ DOMASTNodeLeaf temp = addRoot(parameterDeclaration); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) > */ > public int visit(IASTStatement statement) { >- return addRoot(statement); >+ DOMASTNodeLeaf temp = addRoot(statement); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > > /* (non-Javadoc) > * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) > */ > public int visit(IASTTypeId typeId) { >- return addRoot(typeId); >+ DOMASTNodeLeaf temp = addRoot(typeId); >+ if (temp == null) >+ return PROCESS_ABORT; >+ else if (temp instanceof DOMASTNodeLeafContinue) >+ return PROCESS_CONTINUE; >+ else >+ return PROCESS_CONTINUE; > } > >- private void mergeNode(ASTNode node) { >- addRoot(node); >+ private DOMASTNodeLeaf mergeNode(ASTNode node) { >+ DOMASTNodeLeaf temp = addRoot(node); > > if (node instanceof IASTPreprocessorMacroDefinition ) > addRoot(((IASTPreprocessorMacroDefinition)node).getName()); >+ >+ return temp; > } > >- public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) { >+ public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements) { >+ DOMASTNodeLeaf[] leaves = new DOMASTNodeLeaf[statements.length]; > for(int i=0; i<statements.length; i++) { >- if (monitor != null && monitor.isCanceled()) return; >+ if (monitor != null && monitor.isCanceled()) return leaves; > > if (statements[i] instanceof ASTNode) >- mergeNode((ASTNode)statements[i]); >+ leaves[i] = mergeNode((ASTNode)statements[i]); > } >+ >+ return leaves; > } > > public void mergePreprocessorProblems(IASTProblem[] problems) { >@@ -236,46 +321,26 @@ > return root; > } > >- public 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 (monitor != null && monitor.isCanceled()) return; >- if (statements[i] instanceof IASTPreprocessorIncludeStatement) { >- if (index == includes.length) { >- includes = (IASTPreprocessorIncludeStatement[])ArrayUtil.append(IASTPreprocessorIncludeStatement.class, includes, statements[i]); >- index++; >- } else { >- includes[index++] = (IASTPreprocessorIncludeStatement)statements[i]; >- } >- } >- } >- >- // get the tree model elements corresponding to the includes >- DOMASTNodeParent[] treeIncludes = new DOMASTNodeParent[index]; >- for (int i=0; i<treeIncludes.length; i++) { >- if (monitor != null && monitor.isCanceled()) return; >- treeIncludes[i] = root.findTreeObject(includes[i], false); >- } >- >+ public void groupIncludes(DOMASTNodeLeaf[] treeIncludes) { > // loop through the includes and make sure that all of the nodes > // that are children of the TU are in the proper include (based on offset) > DOMASTNodeLeaf child = null; > outerLoop: for (int i=treeIncludes.length-1; i>=0; i--) { > if (treeIncludes[i] == null) continue; > >+ IASTNode node = null; > for(int j=root.getChildren(false).length-1; j>=0; j--) { >- if (monitor != null && monitor.isCanceled()) return; >- child = root.getChildren(false)[j]; >+// if (monitor != null && monitor.isCanceled()) return; // this causes a deadlock when checked here >+ child = root.getChildren(false)[j]; > >+ node = treeIncludes[i].getNode(); > if (child != null && > treeIncludes[i] != child && >- includes[i] instanceof ASTInclusionStatement && >- ((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)includes[i]).startOffset && >- ((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)includes[i]).endOffset) { >+ node instanceof ASTInclusionStatement && >+ ((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)node).startOffset && >+ ((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)node).endOffset) { > root.removeChild(child); >- treeIncludes[i].addChild(child); >+ ((DOMASTNodeParent)treeIncludes[i]).addChild(child); > } > } > } >Index: src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java,v >retrieving revision 1.42 >diff -u -r1.42 DOMAST.java >--- src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java 27 Jun 2005 03:44:52 -0000 1.42 >+++ src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java 20 Jul 2005 14:33:32 -0000 >@@ -404,7 +404,7 @@ > monitor.subTask(MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_); > start=System.currentTimeMillis(); > // merge preprocessor statements to the tree >- action.mergePreprocessorStatements(statements); >+ DOMASTNodeLeaf[] includeStatements = action.mergePreprocessorStatements(statements); > monitor.worked(2); > System.out.println(DOM_AST_VIEW_DONE + MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_ + COLON_SPACE + (System.currentTimeMillis()- start) ); > >@@ -426,7 +426,7 @@ > monitor.subTask(GROUPING_AST); > start=System.currentTimeMillis(); > // group #includes >- action.groupIncludes(statements); >+ action.groupIncludes(includeStatements); > monitor.worked(30); > System.out.println(DOM_AST_VIEW_DONE + GROUPING_AST + COLON_SPACE + (System.currentTimeMillis()- start) ); > >@@ -811,141 +811,141 @@ > } > > private void makeActions() { >- loadActiveEditorAction = new Action() { >- public void run() { >- openDOMASTView(getActiveEditor()); >- } >- }; >- loadActiveEditorAction.setText(LOAD_ACTIVE_EDITOR); >- loadActiveEditorAction.setToolTipText(LOAD_ACTIVE_EDITOR); >- loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_RELOAD_VIEW); >- >- refreshAction = new Action() { >- public void run() { >- // take a snapshot of the tree expansion >- Object[] expanded = viewer.getExpandedElements(); >- >- // set the new content provider >- setContentProvider(new ViewContentProvider(file, expanded)); >- } >- }; >- refreshAction.setText(REFRESH_DOM_AST); >- refreshAction.setToolTipText(REFRESH_DOM_AST); >- refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_REFRESH_VIEW); >- >- expandAllAction = new Action() { >- public void run() { >- viewer.expandAll(); >- } >- }; >- expandAllAction.setText(EXPAND_ALL); >- expandAllAction.setToolTipText(EXPAND_ALL); >- expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL); >- >- collapseAllAction = new Action() { >- public void run() { >- viewer.collapseAll(); >- } >- }; >- collapseAllAction.setText(COLLAPSE_ALL); >- collapseAllAction.setToolTipText(COLLAPSE_ALL); >- collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL); >- >- clearAction = new Action() { >- public void run() { >- viewer.setContentProvider(new ViewContentProvider(null)); >- viewer.refresh(); >- } >- }; >- clearAction.setText(CLEAR); >- clearAction.setToolTipText(CLEAR); >- clearAction.setImageDescriptor(DOMASTPluginImages.DESC_CLEAR); >- >- searchNamesAction = new Action() { >- private void performSearch() { >- if (viewer.getTree().getItems().length == 0) { >- showMessage(DOM_AST_HAS_NO_CONTENT); >- } >- >- FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer, lang)); >- dialog.open(); >- } >- >- public void run() { >- performSearch(); >- } >- }; >- searchNamesAction.setText(SEARCH_FOR_IASTNAME); >- searchNamesAction.setToolTipText(SEARCH_FOR_IASTNAME); >- searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES); >- >- openDeclarationsAction = new DisplayDeclarationsAction(); >- openDeclarationsAction.setText(OPEN_DECLARATIONS); >- openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >- >- openReferencesAction = new DisplayReferencesAction(); >- openReferencesAction.setText(OPEN_REFERENCES); >- openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >- >- displayProblemsAction = new DisplayProblemsResultAction(); >- displayProblemsAction.setText(DISPLAY_PROBLEMS); >- displayProblemsAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTProblem); >- >- displayNodeTypeAction = new Action() { >- public void run() { >- ISelection selection = viewer.getSelection(); >- if (selection instanceof IStructuredSelection && >- ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >- ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) { >- showMessage("ASTUtil#getNodeType(IASTNode): \"" + ASTTypeUtil.getNodeType(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- } }; >- displayNodeTypeAction.setText(DISPLAY_TYPE); >- displayNodeTypeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >- >- displayNodeSignatureAction = new Action() { >- public void run() { >- ISelection selection = viewer.getSelection(); >- if (selection instanceof IStructuredSelection && >- ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >- ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) { >- showMessage("ASTSignatureUtil#getNodeSignature(IASTNode): \"" + ASTSignatureUtil.getNodeSignature(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- } }; >- displayNodeSignatureAction.setText(DISPLAY_SIGNATURE); >- displayNodeSignatureAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >- >- displayExpressionAction = new Action() { >- public void run() { >- ISelection selection = viewer.getSelection(); >- if (selection instanceof IStructuredSelection && >- ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >- ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTExpression) { >- showMessage("ASTSignatureUtil#getExpressionString(IASTExpression): \"" + ASTSignatureUtil.getExpressionString((IASTExpression)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- } }; >- displayExpressionAction.setText(DISPLAY_EXPRESSION); >- displayExpressionAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >- >- displayInitializerAction = new Action() { >- public void run() { >- ISelection selection = viewer.getSelection(); >- if (selection instanceof IStructuredSelection && >- ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >- ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTInitializer) { >- showMessage("ASTSignatureUtil#getInitializerString(IASTInitializer): \"" + ASTSignatureUtil.getInitializerString((IASTInitializer)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- } }; >- displayInitializerAction.setText(DISPLAY_INITIALIZER); >- displayInitializerAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >- .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >- >- singleClickAction = new ASTHighlighterAction(part); >+ loadActiveEditorAction = new Action() { >+ public void run() { >+ openDOMASTView(getActiveEditor()); >+ } >+ }; >+ loadActiveEditorAction.setText(LOAD_ACTIVE_EDITOR); >+ loadActiveEditorAction.setToolTipText(LOAD_ACTIVE_EDITOR); >+ loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_RELOAD_VIEW); >+ >+ refreshAction = new Action() { >+ public void run() { >+ // take a snapshot of the tree expansion >+ Object[] expanded = viewer.getExpandedElements(); >+ >+ // set the new content provider >+ setContentProvider(new ViewContentProvider(file, expanded)); >+ } >+ }; >+ refreshAction.setText(REFRESH_DOM_AST); >+ refreshAction.setToolTipText(REFRESH_DOM_AST); >+ refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_REFRESH_VIEW); >+ >+ expandAllAction = new Action() { >+ public void run() { >+ viewer.expandAll(); >+ } >+ }; >+ expandAllAction.setText(EXPAND_ALL); >+ expandAllAction.setToolTipText(EXPAND_ALL); >+ expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL); >+ >+ collapseAllAction = new Action() { >+ public void run() { >+ viewer.collapseAll(); >+ } >+ }; >+ collapseAllAction.setText(COLLAPSE_ALL); >+ collapseAllAction.setToolTipText(COLLAPSE_ALL); >+ collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL); >+ >+ clearAction = new Action() { >+ public void run() { >+ viewer.setContentProvider(new ViewContentProvider(null)); >+ viewer.refresh(); >+ } >+ }; >+ clearAction.setText(CLEAR); >+ clearAction.setToolTipText(CLEAR); >+ clearAction.setImageDescriptor(DOMASTPluginImages.DESC_CLEAR); >+ >+ searchNamesAction = new Action() { >+ private void performSearch() { >+ if (viewer.getTree().getItems().length == 0) { >+ showMessage(DOM_AST_HAS_NO_CONTENT); >+ } >+ >+ FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer, lang)); >+ dialog.open(); >+ } >+ >+ public void run() { >+ performSearch(); >+ } >+ }; >+ searchNamesAction.setText(SEARCH_FOR_IASTNAME); >+ searchNamesAction.setToolTipText(SEARCH_FOR_IASTNAME); >+ searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES); >+ >+ openDeclarationsAction = new DisplayDeclarationsAction(); >+ openDeclarationsAction.setText(OPEN_DECLARATIONS); >+ openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >+ .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >+ >+ openReferencesAction = new DisplayReferencesAction(); >+ openReferencesAction.setText(OPEN_REFERENCES); >+ openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >+ .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >+ >+ displayProblemsAction = new DisplayProblemsResultAction(); >+ displayProblemsAction.setText(DISPLAY_PROBLEMS); >+ displayProblemsAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTProblem); >+ >+ displayNodeTypeAction = new Action() { >+ public void run() { >+ ISelection selection = viewer.getSelection(); >+ if (selection instanceof IStructuredSelection && >+ ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >+ ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) { >+ showMessage("ASTUtil#getNodeType(IASTNode): \"" + ASTTypeUtil.getNodeType(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } }; >+ displayNodeTypeAction.setText(DISPLAY_TYPE); >+ displayNodeTypeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >+ .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >+ >+ displayNodeSignatureAction = new Action() { >+ public void run() { >+ ISelection selection = viewer.getSelection(); >+ if (selection instanceof IStructuredSelection && >+ ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >+ ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) { >+ showMessage("ASTSignatureUtil#getNodeSignature(IASTNode): \"" + ASTSignatureUtil.getNodeSignature(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } }; >+ displayNodeSignatureAction.setText(DISPLAY_SIGNATURE); >+ displayNodeSignatureAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >+ .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >+ >+ displayExpressionAction = new Action() { >+ public void run() { >+ ISelection selection = viewer.getSelection(); >+ if (selection instanceof IStructuredSelection && >+ ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >+ ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTExpression) { >+ showMessage("ASTSignatureUtil#getExpressionString(IASTExpression): \"" + ASTSignatureUtil.getExpressionString((IASTExpression)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } }; >+ displayExpressionAction.setText(DISPLAY_EXPRESSION); >+ displayExpressionAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >+ .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >+ >+ displayInitializerAction = new Action() { >+ public void run() { >+ ISelection selection = viewer.getSelection(); >+ if (selection instanceof IStructuredSelection && >+ ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && >+ ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTInitializer) { >+ showMessage("ASTSignatureUtil#getInitializerString(IASTInitializer): \"" + ASTSignatureUtil.getInitializerString((IASTInitializer)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } }; >+ displayInitializerAction.setText(DISPLAY_INITIALIZER); >+ displayInitializerAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() >+ .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); >+ >+ singleClickAction = new ASTHighlighterAction(part); > } > > protected IEditorPart getActiveEditor() { >Index: src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java,v >retrieving revision 1.4 >diff -u -r1.4 DOMASTNodeParent.java >--- src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java 27 Jun 2005 03:44:52 -0000 1.4 >+++ src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java 20 Jul 2005 14:33:33 -0000 >@@ -10,12 +10,12 @@ > *******************************************************************************/ > package org.eclipse.cdt.ui.tests.DOMAST; > >+import java.lang.reflect.Array; > import java.util.Arrays; > import java.util.Comparator; > > 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.IASTPreprocessorStatement; > import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; > import org.eclipse.cdt.core.parser.util.ArrayUtil; >@@ -88,11 +88,87 @@ > return children; > } > >+ /** >+ * Inserts obj into the array at position pos and if this is not possible (due to a bad offset) >+ * then the obj is just appended to the end of the array. >+ * >+ * @param c >+ * @param array >+ * @param obj >+ * @param pos >+ * @return >+ */ >+ public Object[] insert(Class c, Object[] array, Object obj, int pos) { >+ if (pos < 0 || pos >= array.length) { >+ return ArrayUtil.append(c, array, obj); >+ } >+ >+ Object[] temp = (Object[]) Array.newInstance( c, array.length + 1 ); >+ if (pos > 0) { >+ System.arraycopy( array, 0, temp, 0, pos ); >+ temp[pos] = obj; >+ System.arraycopy( array, pos, temp, pos + 1, array.length - pos ); >+ } else { >+ temp[0] = obj; >+ System.arraycopy( array, 0, temp, 1, array.length ); >+ } >+ >+ return temp; >+ } >+ > public void cleanChildren() { > // remove null elements > children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children); > > // sort the elements >+// if (indexFirstPreproStmnt >= 0) { // TODO Devin what if it's ALL preprocessor statements ? >+ int firstOffset=0; >+ int firstLength=0; >+ int checkOffset=0; >+ int checkLength=0; >+ boolean moved=false; >+ for (int j=0, i=0; j<children.length; ) { // TODO Devin need to update indexFirstPreproStmnt >+ i=0; // TODO Devin there is a problem with this... but work on this patch over the weekend instead of at work... >+ >+ while(true) { >+ if (i==j) break; // don't need to check itself or anything after it //TODO Devin is this completely correct? even with #incluedes? >+ >+ checkOffset = ((ASTNode)children[j].getNode()).getOffset(); >+ checkLength = ((ASTNode)children[j].getNode()).getLength(); >+ firstOffset = ((ASTNode)children[i].getNode()).getOffset(); >+ firstLength = ((ASTNode)children[i].getNode()).getLength(); >+ >+ // if the checking element comes before the first element then move the checking element before the first element >+ if (checkOffset < firstOffset && checkOffset + checkLength < firstOffset + firstLength) { >+ // TODO Devin would it be possible to do a switch instead of insert and then remove nulls ??? >+ DOMASTNodeLeaf temp = children[j]; >+ children[j] = null; >+ children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children); >+ children = (DOMASTNodeLeaf[])insert(DOMASTNodeLeaf.class, children, temp, i); >+ break; >+ } >+ >+ // if the checking element is within the bounds of the first element then it must be a child of that element >+ if (checkOffset > firstOffset && checkOffset + checkLength < firstOffset + firstLength) { >+ DOMASTNodeLeaf temp = children[j]; >+ children[j] = null; >+ children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children); >+ ((DOMASTNodeParent)children[i]).addChild(temp); >+ moved=true; >+ break; >+ } >+ >+ i++; >+ } >+ >+ if (!moved) { >+ j++; >+ } else { >+ moved=false; >+ } >+ } >+// } >+ > Arrays.sort(children, new Comparator() { > public int compare(Object a, Object b) { > if(a instanceof DOMASTNodeLeaf && b instanceof DOMASTNodeLeaf && >@@ -157,7 +233,7 @@ > if (nodeChain[i] != null) { > parentToFind = nodeChain[i]; > >- for(; j>=indexFirstPreproStmnt; j--) { >+ for(; j>=0; j--) { > if (childrenToSearch[j] instanceof DOMASTNodeParent) { > if ( childrenToSearch[j].getNode() == node.getParent() ) { > return (DOMASTNodeParent)childrenToSearch[j]; >@@ -270,80 +346,36 @@ > if (equalNodes(node, this.getNode(), useOffset)) { > return this; > } >- if( !useOffset || node instanceof IASTPreprocessorStatement) { >- IASTNode nodeToFind = node; >- // build the chain of nodes... and use it to search the tree for the DOMASTNodeParent that contains the node >- IASTNode[] nodeChain = new IASTNode[DEFAULT_NODE_CHAIN_SIZE]; >- IASTNode topNode = node; >- nodeChain = (IASTNode[])ArrayUtil.append(IASTNode.class, nodeChain, topNode); >- while(topNode.getParent() != null && !(topNode.getParent() instanceof IASTTranslationUnit)) { >- topNode = topNode.getParent(); >- nodeChain = (IASTNode[])ArrayUtil.append(IASTNode.class, nodeChain, topNode); >- } >- >- // loop through the chain of nodes and use it to only search the necessary children required to find the node >- DOMASTNodeLeaf[] childrenToSearch = children; >- outerLoop: for(int i=nodeChain.length-1; i>=0; i--) { >- if (nodeChain[i] != null) { >- nodeToFind = nodeChain[i]; >- >- for(int j=0; j<childrenToSearch.length; j++) { >- if (childrenToSearch[j] instanceof DOMASTNodeParent) { >- >- if ( equalNodes(childrenToSearch[j].getNode(), node, useOffset) ) { >- return (DOMASTNodeParent)childrenToSearch[j]; >- } >- >- if ( equalNodes(childrenToSearch[j].getNode(), nodeToFind, useOffset) ) { >- childrenToSearch = ((DOMASTNodeParent)childrenToSearch[j]).getChildren(false); >- continue outerLoop; >- } >- >- // since the nodeChain doesn't include #includes, if an #include is encountered then search it's children >- if (childrenToSearch[j].getNode() instanceof IASTPreprocessorIncludeStatement) { >- DOMASTNodeParent foundParentInInclude = ((DOMASTNodeParent)childrenToSearch[j]).findTreeObject(node, useOffset); >- if(foundParentInInclude != null) { >- return foundParentInInclude; >- } >- } >- } >- } >- } >- } >- } else { >- if( children.length == 0 ) >- return null; >- if( !cleanupedElements ){ >- cleanChildren(); >- } >- int a = 0, z = children.length - 1; >- int idx = (z - a) / 2 ; >- while( true ){ >- int compare = children[ idx ].relativeNodePosition( node ); >- if( compare == 0 ){ >- if( children[idx] instanceof DOMASTNodeParent ){ >- return ((DOMASTNodeParent)children[idx]).findTreeObject( node, useOffset ); >- } >- return null; //?? >- } else if( compare == -1 ) >- z = idx; >- else >- a = idx; >- int diff = z - a; >- if( diff == 0 ) >- return null; >- else if( diff == 1 ) >- idx = ( idx == z ) ? a : z; >- else >- idx = a + ( z - a ) / 2; >- if( z == a ) >- return null; >- if( z - a == 1 && children[ a ].relativeNodePosition( node ) == 1 && children[ z ].relativeNodePosition( node ) == -1 ) >- return null; >- } >+ if( children.length == 0 ) >+ return null; >+ if( !cleanupedElements ){ >+ cleanChildren(); > } >- >- return null; // nothing found >+ int a = 0, z = children.length - 1; >+ int idx = (z - a) / 2 ; >+ while( true ){ >+ int compare = children[ idx ].relativeNodePosition( node ); >+ if( compare == 0 ){ >+ if( children[idx] instanceof DOMASTNodeParent ){ >+ return ((DOMASTNodeParent)children[idx]).findTreeObject( node, useOffset ); >+ } >+ return null; //?? >+ } else if( compare == -1 ) >+ z = idx; >+ else >+ a = idx; >+ int diff = z - a; >+ if( diff == 0 ) >+ return null; >+ else if( diff == 1 ) >+ idx = ( idx == z ) ? a : z; >+ else >+ idx = a + ( z - a ) / 2; >+ if( z == a ) >+ return null; >+ if( z - a == 1 && children[ a ].relativeNodePosition( node ) == 1 && children[ z ].relativeNodePosition( node ) == -1 ) >+ return null; >+ } > } > > private boolean equalNodes(IASTNode node1, IASTNode node2, boolean useOffset) { >Index: src/org/eclipse/cdt/ui/tests/DOMAST/IPopulateDOMASTAction.java >=================================================================== >RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/IPopulateDOMASTAction.java,v >retrieving revision 1.4 >diff -u -r1.4 IPopulateDOMASTAction.java >--- src/org/eclipse/cdt/ui/tests/DOMAST/IPopulateDOMASTAction.java 27 Jun 2005 03:44:52 -0000 1.4 >+++ src/org/eclipse/cdt/ui/tests/DOMAST/IPopulateDOMASTAction.java 20 Jul 2005 14:33:33 -0000 >@@ -18,7 +18,7 @@ > */ > public interface IPopulateDOMASTAction { > public DOMASTNodeParent getTree(); >- public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements); >+ public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements); > public void mergePreprocessorProblems(IASTProblem[] problems); >- public void groupIncludes(IASTPreprocessorStatement[] statements); >+ public void groupIncludes(DOMASTNodeLeaf[] statements); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
bjorn.freeman-benson
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 94989
: 25043