mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Fixed 88802 - [DOM AST] IASTTranslationUnit needs a method to return include directives in order in which they were encountered
This commit is contained in:
parent
a09f08ae6f
commit
01c4750bab
5 changed files with 127 additions and 2 deletions
|
@ -155,6 +155,7 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
||||||
assertSoleFileLocation(
|
assertSoleFileLocation(
|
||||||
incs[0],
|
incs[0],
|
||||||
"code.cpp", code.indexOf("#inc"), code.indexOf(".h\"\n") + ".h\"".length() - code.indexOf("#inc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
"code.cpp", code.indexOf("#inc"), code.indexOf(".h\"\n") + ".h\"".length() - code.indexOf("#inc")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,6 +255,10 @@ public class DOMLocationInclusionTests extends FileBasePluginTest {
|
||||||
"source.c", cpp_code.indexOf("#include \"header2.h\""), "#include \"header2.h\"".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
"source.c", cpp_code.indexOf("#include \"header2.h\""), "#include \"header2.h\"".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
assertSoleFileLocation(declarations[2],
|
assertSoleFileLocation(declarations[2],
|
||||||
"source.c", cpp_code.indexOf("int z;"), "int z;".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
"source.c", cpp_code.indexOf("int z;"), "int z;".length()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
|
||||||
|
IASTTranslationUnit.IDependencyTree tree = tu.getDependencyTree();
|
||||||
|
assertEquals( tree.getInclusions().length, 2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2004 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
|
|
||||||
|
public class DependencyTree implements IASTTranslationUnit.IDependencyTree, IDependencyNodeHost {
|
||||||
|
|
||||||
|
private final String tu_path;
|
||||||
|
|
||||||
|
public DependencyTree( String path )
|
||||||
|
{
|
||||||
|
tu_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTranslationUnitPath() {
|
||||||
|
return tu_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IASTInclusionNode [] incs = new IASTInclusionNode[2];
|
||||||
|
|
||||||
|
public IASTInclusionNode[] getInclusions() {
|
||||||
|
incs = (IASTInclusionNode[]) ArrayUtil.removeNulls( IASTInclusionNode.class, incs );
|
||||||
|
return incs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInclusionNode(IASTInclusionNode node) {
|
||||||
|
incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2004 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||||
|
|
||||||
|
public interface IDependencyNodeHost {
|
||||||
|
|
||||||
|
public void addInclusionNode( IASTInclusionNode node );
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2004 IBM Corporation and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Common Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* IBM - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.core.parser.scanner2;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||||
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
|
|
||||||
|
public class InclusionNode implements IASTInclusionNode, IDependencyNodeHost {
|
||||||
|
|
||||||
|
private final IASTPreprocessorIncludeStatement stmt;
|
||||||
|
|
||||||
|
public InclusionNode(IASTPreprocessorIncludeStatement stmt) {
|
||||||
|
this.stmt = stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IASTPreprocessorIncludeStatement getIncludeDirective() {
|
||||||
|
return stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IASTInclusionNode [] incs = new IASTInclusionNode[2];
|
||||||
|
|
||||||
|
public IASTInclusionNode[] getNestedInclusions() {
|
||||||
|
incs = (IASTInclusionNode[]) ArrayUtil.removeNulls( IASTInclusionNode.class, incs );
|
||||||
|
return incs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInclusionNode(IASTInclusionNode node) {
|
||||||
|
incs = (IASTInclusionNode[]) ArrayUtil.append( IASTInclusionNode.class, incs, node );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit.IDependencyTree.IASTInclusionNode;
|
||||||
import org.eclipse.cdt.core.parser.CodeReader;
|
import org.eclipse.cdt.core.parser.CodeReader;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
||||||
|
@ -2363,8 +2364,28 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDependencyTree getDependencyTree() {
|
public IDependencyTree getDependencyTree() {
|
||||||
// TODO Auto-generated method stub
|
DependencyTree result = new DependencyTree(getTranslationUnitPath());
|
||||||
return null;
|
buildDependencyTree( result, tu );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void buildDependencyTree(IDependencyNodeHost result, _CompositeFileContext context) {
|
||||||
|
_Context [] subs = context.getSubContexts();
|
||||||
|
for( int i = 0; i < subs.length; ++i )
|
||||||
|
{
|
||||||
|
if( subs[i] instanceof _Inclusion )
|
||||||
|
{
|
||||||
|
IASTTranslationUnit.IDependencyTree.IASTInclusionNode node = createDepTreeNode( (_Inclusion)subs[i] );
|
||||||
|
result.addInclusionNode( node );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IASTInclusionNode createDepTreeNode(_Inclusion inclusion) {
|
||||||
|
IASTPreprocessorIncludeStatement stmt = createASTInclusion( inclusion );
|
||||||
|
InclusionNode node = new InclusionNode( stmt );
|
||||||
|
buildDependencyTree(node, inclusion);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMacroDefinition registerBuiltinObjectStyleMacro(ObjectStyleMacro macro) {
|
public IMacroDefinition registerBuiltinObjectStyleMacro(ObjectStyleMacro macro) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue