Search in sources :

Example 76 with Xnode

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;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException)

Example 77 with Xnode

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);
    }
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 78 with Xnode

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;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode)

Example 79 with Xnode

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;
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) HashSet(java.util.HashSet)

Example 80 with Xnode

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;
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Aggregations

Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)124 Context (claw.tatsu.common.Context)29 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)24 Test (org.junit.Test)24 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)20 TestContext (helper.Utils.TestContext)20 ArrayList (java.util.ArrayList)18 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)17 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)9 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)8 Xid (claw.tatsu.xcodeml.xnode.common.Xid)8 FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)8 HashSet (java.util.HashSet)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)6 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)6 NestedDoStatement (claw.tatsu.xcodeml.abstraction.NestedDoStatement)5 ClawPragma (claw.wani.language.ClawPragma)5 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)5 NodeList (org.w3c.dom.NodeList)5 DirectiveGenerator (claw.tatsu.directive.generator.DirectiveGenerator)4