1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Start of Scope2 and cleaned up ASTNode a little.

This commit is contained in:
Doug Schaefer 2005-11-11 02:45:18 +00:00
parent 416f05ffe1
commit 4108c84536
10 changed files with 132 additions and 314 deletions

View file

@ -17,14 +17,15 @@ package org.eclipse.cdt.core.dom.ast;
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public interface IASTNode { public interface IASTNode {
public static final IASTNode [] EMPTY_NODE_ARRAY = new IASTNode[0]; public static final IASTNode [] EMPTY_NODE_ARRAY = new IASTNode[0];
/** /**
* Get the translation unit (master) node that is the ancestor of all nodes * Get the translation unit (master) node that is the ancestor of all nodes
* in this AST. * in this AST.
* *
* @return <code>IASTTranslationUnit</code> * @return <code>IASTTranslationUnit</code>
*/ */
public IASTTranslationUnit getTranslationUnit(); public IASTTranslationUnit getTranslationUnit();
/** /**
@ -44,7 +45,6 @@ public interface IASTNode {
*/ */
public IASTNodeLocation[] getNodeLocations(); public IASTNodeLocation[] getNodeLocations();
/** /**
* Get the location of the node as a file. * Get the location of the node as a file.
* *
@ -52,7 +52,6 @@ public interface IASTNode {
*/ */
public IASTFileLocation getFileLocation(); public IASTFileLocation getFileLocation();
/** /**
* Lightweight check for understanding what file we are in. * Lightweight check for understanding what file we are in.
* *
@ -109,4 +108,14 @@ public interface IASTNode {
*/ */
public String getRawSignature(); public String getRawSignature();
/**
* Internal interface.
*
* Get the scope for this node. Different children may get different nodes.
*
* @param childProperty
* @return
*/
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty);
} }

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2005 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
* @author Doug Schaefer
*
*/
public interface IScope2 {
}

View file

@ -10,20 +10,42 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IScope2;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public abstract class ASTNode implements IASTNode { public abstract class ASTNode implements IASTNode {
private int length; private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0];
private IASTNode parent;
private ASTNodeProperty property;
private int length;
private int offset; private int offset;
private static final IASTNodeLocation[] EMPTY_LOCATION_ARRAY = new IASTNodeLocation[0]; public IASTNode getParent() {
return parent;
}
public void setParent(IASTNode node) {
this.parent = node;
}
public ASTNodeProperty getPropertyInParent() {
return property;
}
public void setPropertyInParent(ASTNodeProperty property) {
this.property = property;
}
public int getOffset() { public int getOffset() {
return offset; return offset;
@ -56,11 +78,6 @@ public abstract class ASTNode implements IASTNode {
private IASTNodeLocation[] locations = null; private IASTNodeLocation[] locations = null;
private IASTFileLocation fileLocation = null; private IASTFileLocation fileLocation = null;
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getNodeLocations()
*/
public IASTNodeLocation[] getNodeLocations() { public IASTNodeLocation[] getNodeLocations() {
if (locations != null) if (locations != null)
return locations; return locations;
@ -70,11 +87,6 @@ public abstract class ASTNode implements IASTNode {
return locations; return locations;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getRawSignature()
*/
public String getRawSignature() { public String getRawSignature() {
return getTranslationUnit().getUnpreprocessedSignature( return getTranslationUnit().getUnpreprocessedSignature(
getNodeLocations()); getNodeLocations());
@ -90,4 +102,17 @@ public abstract class ASTNode implements IASTNode {
fileLocation = getTranslationUnit().flattenLocationsToFile( getNodeLocations() ); fileLocation = getTranslationUnit().flattenLocationsToFile( getNodeLocations() );
return fileLocation; return fileLocation;
} }
public IScope2 getScope(IASTNode child, ASTNodeProperty childProperty) {
return parent != null ? parent.getScope(this, property) : null;
}
public IASTTranslationUnit getTranslationUnit() {
return parent != null ? parent.getTranslationUnit() : null;
}
public boolean accept(ASTVisitor visitor) {
return true;
}
} }

View file

@ -1132,6 +1132,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
public static class FoundDeclaratorException extends Exception public static class FoundDeclaratorException extends Exception
{ {
private static final long serialVersionUID = 0;
public final IASTDeclarator declarator; public final IASTDeclarator declarator;
public final IToken currToken; public final IToken currToken;
public IASTDeclSpecifier declSpec; public IASTDeclSpecifier declSpec;

View file

@ -10,60 +10,13 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public abstract class CASTNode extends ASTNode implements IASTNode { public abstract class CASTNode extends ASTNode {
private IASTNode parent; // A little empty isn't it...
private ASTNodeProperty property;
public IASTNode getParent() {
return parent;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
*/
public ASTNodeProperty getPropertyInParent() {
return property;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void setParent(IASTNode parent) {
this.parent = parent;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.IASTNodeProperty)
*/
public void setPropertyInParent(ASTNodeProperty property) {
this.property = property;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() {
if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this;
IASTNode node = getParent();
while( ! (node instanceof IASTTranslationUnit ) && node != null )
{
node = node.getParent();
}
return (IASTTranslationUnit) node;
}
// public boolean accept( ASTVisitor action ){
// return true;
// }
} }

View file

@ -76,6 +76,10 @@ public class CASTTranslationUnit extends CASTNode implements
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0]; private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
public IASTTranslationUnit getTranslationUnit() {
return this;
}
public void addDeclaration(IASTDeclaration d) { public void addDeclaration(IASTDeclaration d) {
if (d != null) { if (d != null) {
declsPos++; declsPos++;

View file

@ -10,57 +10,13 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
/** /**
* @author jcamelon * @author jcamelon
*/ */
public abstract class CPPASTNode extends ASTNode implements IASTNode { public abstract class CPPASTNode extends ASTNode {
private IASTNode parent; // A little empty isn't it...
private ASTNodeProperty property;
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() {
if( this instanceof IASTTranslationUnit ) return (IASTTranslationUnit) this;
IASTNode node = getParent();
while(node != null && !(node instanceof IASTTranslationUnit))
node = node.getParent();
return (IASTTranslationUnit) node;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getParent()
*/
public IASTNode getParent() {
return parent;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void setParent(IASTNode node) {
this.parent = node;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
*/
public ASTNodeProperty getPropertyInParent() {
return property;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.ASTNodeProperty)
*/
public void setPropertyInParent(ASTNodeProperty property) {
this.property = property;
}
} }

View file

@ -89,6 +89,10 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0]; private static final IASTName[] EMPTY_NAME_ARRAY = new IASTName[0];
public IASTTranslationUnit getTranslationUnit() {
return this;
}
public void addDeclaration(IASTDeclaration d) { public void addDeclaration(IASTDeclaration d) {
decls = (IASTDeclaration [])ArrayUtil.append( IASTDeclaration.class, decls, d ); decls = (IASTDeclaration [])ArrayUtil.append( IASTDeclaration.class, decls, d );
} }

View file

@ -10,8 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.parser.scanner2; package org.eclipse.cdt.internal.core.parser.scanner2;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter; import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion; import org.eclipse.cdt.core.dom.ast.IASTMacroExpansion;
@ -108,7 +106,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTEndif extends ScannerASTNode implements public static class ASTEndif extends ASTNode implements
IASTPreprocessorEndifStatement { IASTPreprocessorEndifStatement {
} }
@ -116,7 +114,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTElif extends ScannerASTNode implements public static class ASTElif extends ASTNode implements
IASTPreprocessorElifStatement { IASTPreprocessorElifStatement {
private final boolean taken; private final boolean taken;
@ -142,7 +140,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTElse extends ScannerASTNode implements public static class ASTElse extends ASTNode implements
IASTPreprocessorElseStatement { IASTPreprocessorElseStatement {
private final boolean taken; private final boolean taken;
@ -167,7 +165,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTIfndef extends ScannerASTNode implements public static class ASTIfndef extends ASTNode implements
IASTPreprocessorIfndefStatement { IASTPreprocessorIfndefStatement {
private final boolean taken; private final boolean taken;
@ -193,7 +191,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTIfdef extends ScannerASTNode implements public static class ASTIfdef extends ASTNode implements
IASTPreprocessorIfdefStatement { IASTPreprocessorIfdefStatement {
private final boolean taken; private final boolean taken;
@ -219,7 +217,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTIf extends ScannerASTNode implements public static class ASTIf extends ASTNode implements
IASTPreprocessorIfStatement { IASTPreprocessorIfStatement {
private final boolean taken; private final boolean taken;
@ -245,7 +243,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTError extends ScannerASTNode implements public static class ASTError extends ASTNode implements
IASTPreprocessorErrorStatement { IASTPreprocessorErrorStatement {
} }
@ -253,7 +251,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTPragma extends ScannerASTNode implements public static class ASTPragma extends ASTNode implements
IASTPreprocessorPragmaStatement { IASTPreprocessorPragmaStatement {
} }
@ -261,7 +259,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTUndef extends ScannerASTNode implements public static class ASTUndef extends ASTNode implements
IASTPreprocessorUndefStatement { IASTPreprocessorUndefStatement {
public ASTUndef( IASTName n ) public ASTUndef( IASTName n )
@ -439,7 +437,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTInclusionStatement extends ScannerASTNode implements public static class ASTInclusionStatement extends ASTNode implements
IASTPreprocessorIncludeStatement { IASTPreprocessorIncludeStatement {
private final char[] path; private final char[] path;
@ -474,7 +472,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTFunctionMacro extends ScannerASTNode implements public static class ASTFunctionMacro extends ASTNode implements
IASTPreprocessorFunctionStyleMacroDefinition { IASTPreprocessorFunctionStyleMacroDefinition {
private IASTName name; private IASTName name;
@ -596,9 +594,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
if( expansionName == null ) if( expansionName == null )
{ {
expansionName = new ASTMacroName( name ); expansionName = new ASTMacroName( name );
((ScannerASTNode)expansionName).setParent( rootNode ); expansionName.setParent( rootNode );
((ScannerASTNode)expansionName).setPropertyInParent( IASTPreprocessorUndefStatement.MACRO_NAME ); expansionName.setPropertyInParent( IASTPreprocessorUndefStatement.MACRO_NAME );
((ScannerASTNode)expansionName).setOffsetAndLength( context_directive_start, name.length ); ((ASTNode)expansionName).setOffsetAndLength( context_directive_start, name.length );
} }
return expansionName; return expansionName;
} }
@ -618,72 +616,10 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
public static class ScannerASTNode extends ASTNode {
private IASTNode parent;
private ASTNodeProperty property;
public IASTNode getParent() {
return parent;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
*/
public ASTNodeProperty getPropertyInParent() {
return property;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void setParent(IASTNode parent) {
this.parent = parent;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.IASTNodeProperty)
*/
public void setPropertyInParent(ASTNodeProperty property) {
this.property = property;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() {
if (this instanceof IASTTranslationUnit)
return (IASTTranslationUnit) this;
IASTNode node = getParent();
while (!(node instanceof IASTTranslationUnit) && node != null) {
node = node.getParent();
}
return (IASTTranslationUnit) node;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#accept(org.eclipse.cdt.core.dom.ast.IASTVisitor.BaseVisitorAction)
*/
public boolean accept(ASTVisitor visitor) {
return true;
}
}
/** /**
* @author jcamelon * @author jcamelon
*/ */
public class ASTMacroName extends ScannerASTNode implements IASTName { public class ASTMacroName extends ASTNode implements IASTName {
private final char[] name; private final char[] name;
private IMacroBinding binding = null; private IMacroBinding binding = null;
@ -776,7 +712,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
/** /**
* @author jcamelon * @author jcamelon
*/ */
public static class ASTObjectMacro extends ScannerASTNode implements public static class ASTObjectMacro extends ASTNode implements
IASTPreprocessorObjectStyleMacroDefinition { IASTPreprocessorObjectStyleMacroDefinition {
private IASTName name; private IASTName name;
@ -867,7 +803,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
public static class ASTFunctionMacroParameter extends ScannerASTNode public static class ASTFunctionMacroParameter extends ASTNode
implements IASTFunctionStyleMacroParameter { implements IASTFunctionStyleMacroParameter {
private String value; private String value;
@ -1287,9 +1223,9 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
if( expansionName == null ) if( expansionName == null )
{ {
expansionName = new ASTMacroName( definition.getName() ); expansionName = new ASTMacroName( definition.getName() );
((ScannerASTNode)expansionName).setParent( rootNode ); expansionName.setParent( rootNode );
((ScannerASTNode)expansionName).setPropertyInParent( IASTTranslationUnit.EXPANSION_NAME ); expansionName.setPropertyInParent( IASTTranslationUnit.EXPANSION_NAME );
((ScannerASTNode)expansionName).setOffsetAndLength( context_directive_start, context_directive_end - context_directive_start + 1); ((ASTNode)expansionName).setOffsetAndLength( context_directive_start, context_directive_end - context_directive_start + 1);
} }
return expansionName; return expansionName;
} }
@ -1396,14 +1332,14 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTName name = new ASTMacroName(d.name); IASTName name = new ASTMacroName(d.name);
name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME); name.setPropertyInParent(IASTPreprocessorMacroDefinition.MACRO_NAME);
name.setParent(r); name.setParent(r);
((ScannerASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length); ((ASTNode) name).setOffsetAndLength(d.nameOffset, d.name.length);
r.setName(name); r.setName(name);
r.setExpansion(new String(d.expansion)); r.setExpansion(new String(d.expansion));
((ScannerASTNode) r).setOffsetAndLength(d.context_directive_start, ((ASTNode) r).setOffsetAndLength(d.context_directive_start,
d.context_directive_end - d.context_directive_start); d.context_directive_end - d.context_directive_start);
d.astNode = r; d.astNode = r;
((ScannerASTNode) r).setParent(rootNode); r.setParent(rootNode);
((ScannerASTNode) r).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); r.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return r; return r;
} }
@ -1433,15 +1369,15 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) { private IASTPreprocessorIncludeStatement createASTInclusion(_Inclusion inc) {
IASTPreprocessorIncludeStatement result = new ASTInclusionStatement( IASTPreprocessorIncludeStatement result = new ASTInclusionStatement(
inc.reader.filename); inc.reader.filename);
((ScannerASTNode) result).setOffsetAndLength( ((ASTNode) result).setOffsetAndLength(
inc.context_directive_start, inc.context_directive_end inc.context_directive_start, inc.context_directive_end
- inc.context_directive_start); - inc.context_directive_start);
((ASTInclusionStatement) result).startOffset = inc.context_directive_end; ((ASTInclusionStatement) result).startOffset = inc.context_directive_end;
((ASTInclusionStatement) result).endOffset = inc.context_ends; ((ASTInclusionStatement) result).endOffset = inc.context_ends;
((ASTInclusionStatement) result).setParent(rootNode); ((ASTInclusionStatement) result).setParent(rootNode);
((ASTInclusionStatement) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); ((ASTInclusionStatement) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1500,8 +1436,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorEndifStatement result = new ASTEndif(); IASTPreprocessorEndifStatement result = new ASTEndif();
((ASTNode) result).setOffsetAndLength(endif.context_directive_start, ((ASTNode) result).setOffsetAndLength(endif.context_directive_start,
endif.context_directive_end - endif.context_directive_start); endif.context_directive_end - endif.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1513,8 +1449,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorElifStatement result = new ASTElif(elif.taken); IASTPreprocessorElifStatement result = new ASTElif(elif.taken);
((ASTNode) result).setOffsetAndLength(elif.context_directive_start, ((ASTNode) result).setOffsetAndLength(elif.context_directive_start,
elif.context_directive_end - elif.context_directive_start); elif.context_directive_end - elif.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1526,8 +1462,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorElseStatement result = new ASTElse(e.taken); IASTPreprocessorElseStatement result = new ASTElse(e.taken);
((ASTNode) result).setOffsetAndLength(e.context_directive_start, ((ASTNode) result).setOffsetAndLength(e.context_directive_start,
e.context_directive_end - e.context_directive_start); e.context_directive_end - e.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1539,8 +1475,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken); IASTPreprocessorIfndefStatement result = new ASTIfndef(ifndef.taken);
((ASTNode) result).setOffsetAndLength(ifndef.context_directive_start, ((ASTNode) result).setOffsetAndLength(ifndef.context_directive_start,
ifndef.context_directive_end - ifndef.context_directive_start); ifndef.context_directive_end - ifndef.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1552,8 +1488,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken); IASTPreprocessorIfdefStatement result = new ASTIfdef(ifdef.taken);
((ASTNode) result).setOffsetAndLength(ifdef.context_directive_start, ((ASTNode) result).setOffsetAndLength(ifdef.context_directive_start,
ifdef.context_directive_end - ifdef.context_directive_start); ifdef.context_directive_end - ifdef.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1565,8 +1501,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorIfStatement result = new ASTIf(i.taken); IASTPreprocessorIfStatement result = new ASTIf(i.taken);
((ASTNode) result).setOffsetAndLength(i.context_directive_start, ((ASTNode) result).setOffsetAndLength(i.context_directive_start,
i.context_directive_end - i.context_directive_start); i.context_directive_end - i.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1578,8 +1514,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorErrorStatement result = new ASTError(); IASTPreprocessorErrorStatement result = new ASTError();
((ASTNode) result).setOffsetAndLength(error.context_directive_start, ((ASTNode) result).setOffsetAndLength(error.context_directive_start,
error.context_directive_end - error.context_directive_start); error.context_directive_end - error.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1591,8 +1527,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorPragmaStatement result = new ASTPragma(); IASTPreprocessorPragmaStatement result = new ASTPragma();
((ASTNode) result).setOffsetAndLength(pragma.context_directive_start, ((ASTNode) result).setOffsetAndLength(pragma.context_directive_start,
pragma.context_directive_end - pragma.context_directive_start); pragma.context_directive_end - pragma.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }
@ -1604,8 +1540,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
IASTPreprocessorUndefStatement result = new ASTUndef(undef.getName()); IASTPreprocessorUndefStatement result = new ASTUndef(undef.getName());
((ASTNode) result).setOffsetAndLength(undef.context_directive_start, ((ASTNode) result).setOffsetAndLength(undef.context_directive_start,
undef.context_directive_end - undef.context_directive_start); undef.context_directive_end - undef.context_directive_start);
((ScannerASTNode) result).setParent(rootNode); result.setParent(rootNode);
((ScannerASTNode) result).setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT); result.setPropertyInParent(IASTTranslationUnit.PREPROCESSOR_STATEMENT);
return result; return result;
} }

View file

@ -14,12 +14,8 @@ import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTProblem;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.parser.ParserMessages; import org.eclipse.cdt.internal.core.parser.ParserMessages;
@ -27,45 +23,6 @@ import org.eclipse.cdt.internal.core.parser.ParserMessages;
* @author jcamelon * @author jcamelon
*/ */
public class ScannerASTProblem extends ASTNode implements IASTProblem { public class ScannerASTProblem extends ASTNode implements IASTProblem {
private IASTNode parent;
private ASTNodeProperty property;
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getParent()
*/
public IASTNode getParent() {
return parent;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setParent(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
public void setParent(IASTNode node) {
this.parent = node;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getPropertyInParent()
*/
public ASTNodeProperty getPropertyInParent() {
return property;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#setPropertyInParent(org.eclipse.cdt.core.dom.ast.ASTNodeProperty)
*/
public void setPropertyInParent(ASTNodeProperty property) {
this.property = property;
}
private final char[] arg; private final char[] arg;
@ -84,29 +41,14 @@ public class ScannerASTProblem extends ASTNode implements IASTProblem {
this.isError = error; this.isError = error;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IASTProblem#getID()
*/
public int getID() { public int getID() {
return id; return id;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IASTProblem#isError()
*/
public boolean isError() { public boolean isError() {
return isError; return isError;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IASTProblem#isWarning()
*/
public boolean isWarning() { public boolean isWarning() {
return isWarning; return isWarning;
} }
@ -284,44 +226,12 @@ public class ScannerASTProblem extends ASTNode implements IASTProblem {
return message; return message;
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IASTProblem#checkCategory(int)
*/
public boolean checkCategory(int bitmask) { public boolean checkCategory(int bitmask) {
return ((id & bitmask) != 0); return ((id & bitmask) != 0);
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.parser.IASTProblem#getArguments()
*/
public String getArguments() { public String getArguments() {
return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$ return arg != null ? String.valueOf(arg) : ""; //$NON-NLS-1$
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.core.dom.ast.IASTNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() {
if (this instanceof IASTTranslationUnit)
return (IASTTranslationUnit) this;
IASTNode node = getParent();
while (!(node instanceof IASTTranslationUnit) && node != null) {
node = node.getParent();
}
return (IASTTranslationUnit) node;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTNode#accept(org.eclipse.cdt.core.dom.ast.IASTVisitor.BaseVisitorAction)
*/
public boolean accept( ASTVisitor visitor ) {
return true;
}
} }