use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class Type method duplicateBound.
/**
* Duplicate a lower or an upper bound between two different XcodeML units.
*
* @param baseBound Base bound to be duplicated.
* @param xcodemlSrc Source XcodeML unit. Contains base bound.
* @param xcodemlDst Destination XcodeML unit. Duplicate will be created here.
* @return The newly duplicated bound element.
* @throws IllegalTransformationException If bound cannot be duplicated.
*/
private static Xnode duplicateBound(Xnode baseBound, XcodeML xcodemlSrc, XcodeML xcodemlDst) throws IllegalTransformationException {
if (!Xnode.isOfCode(baseBound, Xcode.LOWER_BOUND) && !Xnode.isOfCode(baseBound, Xcode.UPPER_BOUND)) {
throw new IllegalTransformationException("Cannot duplicate bound");
}
if (xcodemlSrc == xcodemlDst) {
return baseBound.cloneNode();
}
Xnode boundChild = baseBound.child(0);
if (boundChild == null) {
throw new IllegalTransformationException("Cannot duplicate bound as it " + "has no children element");
}
Xnode bound = xcodemlDst.createNode(baseBound.opcode());
bound.append(xcodemlDst.importElement(boundChild, xcodemlSrc));
return bound;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class FbasicType method addDimension.
/**
* Add a dimension to the basic type.
*
* @param index Index element to add as the new dimension.
* @param position Position compared to already existing element. If -1,
* dimension is added at the end.
*/
public void addDimension(Xnode index, int position) {
if (_dimensions.isEmpty() || position == APPEND) {
append(index);
_dimensions.add(index);
_isArray = true;
} else {
Xnode crtPos = _dimensions.get(position);
crtPos.insertBefore(index);
_dimensions.add(position, index);
}
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class FbasicType method resetDimension.
/**
* Remove all dimension from the type
*/
public void resetDimension() {
for (Xnode idx : _dimensions) {
idx.delete();
}
_dimensions.clear();
_isArray = false;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class FortranModule method getInterfaceImplementation.
/**
* Gather all the function type hash that implement the interface.
*
* @param interfaceName Interface name.
* @return Set of all type hashes.
*/
private Set<String> getInterfaceImplementation(String interfaceName) {
Set<String> fctTypes = new HashSet<>();
List<Xnode> interfaceDecls = matchAll(Xcode.F_INTERFACE_DECL);
for (Xnode interfaceDecl : interfaceDecls) {
if (interfaceDecl.getAttribute(Xattr.NAME) != null && interfaceDecl.getAttribute(Xattr.NAME).equalsIgnoreCase(interfaceName)) {
List<Xnode> moduleProcDecls = interfaceDecl.matchAll(Xcode.F_MODULE_PROCEDURE_DECL);
for (Xnode moduleProcDecl : moduleProcDecls) {
for (Xnode name : moduleProcDecl.matchAll(Xcode.NAME)) {
fctTypes.add(name.getAttribute(Xattr.TYPE));
}
}
}
}
return fctTypes;
}
use of claw.tatsu.xcodeml.xnode.common.Xnode in project claw-compiler by C2SM-RCM.
the class XnodeUtil method getFromXpath.
/**
* Get a list of T elements from an xpath query executed from the given element.
*
* @param from Element to start from.
* @param query XPath query to be executed.
* @return List of all array references found. List is empty if nothing is
* found.
*/
private static List<Xnode> getFromXpath(Xnode from, String query) {
List<Xnode> elements = new ArrayList<>();
try {
XPathExpression ex = XPathFactory.newInstance().newXPath().compile(query);
NodeList output = (NodeList) ex.evaluate(from.element(), XPathConstants.NODESET);
for (int i = 0; i < output.getLength(); i++) {
Element element = (Element) output.item(i);
elements.add(new Xnode(element));
}
} catch (XPathExpressionException ignored) {
}
return elements;
}
Aggregations