mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
API to access node factories, bug 268972.
This commit is contained in:
parent
88c5aa9a43
commit
a63af80942
8 changed files with 81 additions and 16 deletions
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.dom.ast;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICNodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNodeFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CNodeFactory;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNodeFactory;
|
||||
|
||||
/**
|
||||
* Provides access to the node factories.
|
||||
*
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
* @since 5.2
|
||||
*/
|
||||
public class ASTNodeFactoryFactory {
|
||||
|
||||
ASTNodeFactoryFactory() {}
|
||||
|
||||
public static ICNodeFactory getDefaultCNodeFactory() {
|
||||
return CNodeFactory.getDefault();
|
||||
}
|
||||
|
||||
public static ICPPNodeFactory getDefaultCPPNodeFactory() {
|
||||
return CPPNodeFactory.getDefault();
|
||||
}
|
||||
}
|
|
@ -271,9 +271,7 @@ public interface IASTTranslationUnit extends IASTNode, IASTDeclarationListOwner,
|
|||
|
||||
/**
|
||||
* Returns the node factory that was used to build the AST.
|
||||
*
|
||||
* @noreference This method is not intended to be referenced by clients.
|
||||
* @since 5.1
|
||||
* @since 5.2
|
||||
*/
|
||||
public INodeFactory getASTNodeFactory();
|
||||
|
||||
|
|
|
@ -12,6 +12,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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -46,11 +47,18 @@ public interface INodeFactory {
|
|||
public IASTName newName(char[] name);
|
||||
|
||||
/**
|
||||
* Calling the method getASTNodeFactory() on the translation unit returned by this
|
||||
* method will return the node factory that was used to create the IASTTranslationUnit.
|
||||
* @deprecated use {@link #newTranslationUnit(IScanner)}, instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public IASTTranslationUnit newTranslationUnit();
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new translation unit that cooperates with the given scanner in order
|
||||
* to track macro-expansions and location information.
|
||||
* @scanner the preprocessor the translation unit interacts with.
|
||||
* @since 5.2
|
||||
*/
|
||||
public IASTTranslationUnit newTranslationUnit(IScanner scanner);
|
||||
|
||||
public IASTLiteralExpression newLiteralExpression(int kind, String rep);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation
|
|||
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;
|
||||
|
||||
/**
|
||||
* Factory for AST nodes for the C++ programming language.
|
||||
|
@ -37,7 +38,19 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTSimpleDeclSpecifier;
|
|||
*/
|
||||
public interface ICPPNodeFactory extends INodeFactory {
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #newTranslationUnit(IScanner)}, instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public ICPPASTTranslationUnit newTranslationUnit();
|
||||
|
||||
/**
|
||||
* Creates a new translation unit that cooperates with the given scanner in order
|
||||
* to track macro-expansions and location information.
|
||||
* @scanner the preprocessor the translation unit interacts with.
|
||||
* @since 5.2
|
||||
*/
|
||||
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner);
|
||||
|
||||
public ICPPASTLiteralExpression newLiteralExpression(int kind, String rep);
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
|||
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;
|
||||
|
||||
/**
|
||||
* Abstract factory implementation that creates AST nodes for C99.
|
||||
|
@ -93,9 +94,16 @@ public class CNodeFactory implements ICNodeFactory {
|
|||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public IASTTranslationUnit newTranslationUnit() {
|
||||
return newTranslationUnit(null);
|
||||
}
|
||||
|
||||
public IASTTranslationUnit newTranslationUnit(IScanner scanner) {
|
||||
CASTTranslationUnit tu = new CASTTranslationUnit();
|
||||
|
||||
if (scanner != null) {
|
||||
tu.setLocationResolver(scanner.getLocationResolver());
|
||||
}
|
||||
tu.setASTNodeFactory(this);
|
||||
return tu;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.DeclarationOptions;
|
||||
|
@ -466,7 +465,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
@Override
|
||||
protected void setupTranslationUnit() throws DOMException {
|
||||
translationUnit = nodeFactory.newTranslationUnit();
|
||||
translationUnit = nodeFactory.newTranslationUnit(scanner);
|
||||
translationUnit.setIndex(index);
|
||||
|
||||
// add built-in names to the scope
|
||||
|
@ -478,8 +477,6 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
ASTInternal.addBinding(tuScope, binding);
|
||||
}
|
||||
}
|
||||
if(translationUnit instanceof ASTTranslationUnit)
|
||||
((ASTTranslationUnit)translationUnit).setLocationResolver(scanner.getLocationResolver());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation
|
|||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -116,9 +117,16 @@ public class CPPNodeFactory implements ICPPNodeFactory {
|
|||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
public ICPPASTTranslationUnit newTranslationUnit() {
|
||||
return newTranslationUnit(null);
|
||||
}
|
||||
|
||||
public ICPPASTTranslationUnit newTranslationUnit(IScanner scanner) {
|
||||
CPPASTTranslationUnit tu = new CPPASTTranslationUnit();
|
||||
|
||||
if (scanner != null) {
|
||||
tu.setLocationResolver(scanner.getLocationResolver());
|
||||
}
|
||||
tu.setASTNodeFactory(this);
|
||||
return tu;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,6 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.BacktrackException;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.DeclarationOptions;
|
||||
|
@ -3390,7 +3389,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
@Override
|
||||
protected void setupTranslationUnit() throws DOMException {
|
||||
translationUnit = nodeFactory.newTranslationUnit();
|
||||
translationUnit = nodeFactory.newTranslationUnit(scanner);
|
||||
translationUnit.setIndex(index);
|
||||
|
||||
// add built-in names to the scope
|
||||
|
@ -3403,8 +3402,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
ASTInternal.addBinding(tuScope, binding);
|
||||
}
|
||||
}
|
||||
if(translationUnit instanceof ASTTranslationUnit)
|
||||
((ASTTranslationUnit)translationUnit).setLocationResolver(scanner.getLocationResolver());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue