mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
API to set offsets for AST-nodes, bug 268983.
This commit is contained in:
parent
a63af80942
commit
45cd6c2948
4 changed files with 78 additions and 5 deletions
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom.ast;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -166,4 +167,39 @@ public interface INodeFactory {
|
|||
|
||||
public IASTCompositeTypeSpecifier newCompositeTypeSpecifier(int key, IASTName name);
|
||||
|
||||
/**
|
||||
* Provides the offsets for a node. The offsets are artificial numbers that identify the
|
||||
* position of a node in the translation unit. They are not file-offsets. You can obtain
|
||||
* valid offsets via {@link IToken#getOffset()} or {@link IToken#getEndOffset()} from tokens
|
||||
* provided by the scanner for this translation unit.
|
||||
* <par> May throw an exception when the node provided was not created by this factory.
|
||||
* @param node a node created by this factory
|
||||
* @offset the offset (inclusive) for the node
|
||||
* @param endOffset the end offset (exclusive) for the node
|
||||
* @see #newTranslationUnit(IScanner)
|
||||
* @since 5.2
|
||||
*/
|
||||
public void setOffsets(IASTNode node, int offset, int endOffset);
|
||||
|
||||
/**
|
||||
* Provides the end offset for a node. The offset is an artificial numbers that identifies the
|
||||
* position of a node in the translation unit. It is not a file-offset. You can obtain a
|
||||
* valid offset via {@link IToken#getEndOffset()} from a token provided by the scanner for
|
||||
* this translation unit.
|
||||
* <par> May throw an exception when the node provided was not created by this factory.
|
||||
* @param node a node created by this factory
|
||||
* @param endOffset the end offset (exclusive) for the node
|
||||
* @see #newTranslationUnit(IScanner)
|
||||
* @since 5.2
|
||||
*/
|
||||
void setEndOffset(IASTNode node, int endOffset);
|
||||
|
||||
/**
|
||||
* Adjusts the end-offset of a node to be the same as the end-offset of a given node.
|
||||
* <par> May throw an exception when either one of the nodes provided was not created by this factory.
|
||||
* @param node a node created by this factory
|
||||
* @param endNode a node created by this factory defining the end for the other node.
|
||||
* @since 5.2
|
||||
*/
|
||||
void setEndOffset(IASTNode node, IASTNode endNode);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. 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:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||
|
||||
/**
|
||||
* Abstract base class for node factories.
|
||||
*/
|
||||
public abstract class NodeFactory implements INodeFactory {
|
||||
|
||||
public final void setOffsets(IASTNode node, int offset, int endOffset) {
|
||||
((ASTNode) node).setOffsetAndLength(offset, endOffset-offset);
|
||||
}
|
||||
|
||||
public final void setEndOffset(IASTNode node, int endOffset) {
|
||||
ASTNode a= (ASTNode) node;
|
||||
a.setLength(endOffset - a.getOffset());
|
||||
}
|
||||
|
||||
public final void setEndOffset(IASTNode node, IASTNode endNode) {
|
||||
ASTNode a= (ASTNode) node;
|
||||
ASTNode e= (ASTNode) endNode;
|
||||
a.setLength(e.getOffset() + e.getLength() - a.getOffset());
|
||||
}
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Mike Kucera (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
|
@ -78,15 +79,14 @@ import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.NodeFactory;
|
||||
|
||||
/**
|
||||
* Abstract factory implementation that creates AST nodes for C99.
|
||||
* These can be overridden in subclasses to change the
|
||||
* implementations of the nodes.
|
||||
*
|
||||
* @author Mike Kucera
|
||||
*/
|
||||
public class CNodeFactory implements ICNodeFactory {
|
||||
public class CNodeFactory extends NodeFactory implements ICNodeFactory {
|
||||
|
||||
private static final CNodeFactory DEFAULT_INSTANCE = new CNodeFactory();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Mike Kucera (IBM) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -104,12 +105,13 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointer;
|
|||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTPointerToMember;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.NodeFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract factory implementation that creates C++ AST nodes.
|
||||
*/
|
||||
public class CPPNodeFactory implements ICPPNodeFactory {
|
||||
public class CPPNodeFactory extends NodeFactory implements ICPPNodeFactory {
|
||||
|
||||
private static final CPPNodeFactory DEFAULT_INSTANCE = new CPPNodeFactory();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue