Search in sources :

Example 1 with IBodyContainer

use of mrmathami.cia.cpp.ast.IBodyContainer in project Cpp4CIA by thanhminhmr.

the class AstBuilder method mergeDuplicate.

private void mergeDuplicate(@Nonnull CppNode.Matcher matcher, @Nonnull CppNode node) {
    final Map<CppNode.Wrapper, CppNode> nodeMap = new HashMap<>();
    for (final CppNode childNode : List.copyOf(node.getChildren())) {
        final CppNode.Wrapper wrapper = new CppNode.Wrapper(childNode, CppNode.MatchLevel.SIMILAR, matcher);
        final CppNode existingNode = nodeMap.putIfAbsent(wrapper, childNode);
        if (existingNode == null)
            continue;
        if (existingNode instanceof IBodyContainer) {
            if (((IBodyContainer) existingNode).getBody() == null) {
                existingNode.transfer(childNode);
                nodeMap.put(wrapper, childNode);
            } else {
                childNode.transfer(existingNode);
            }
        } else {
            childNode.transfer(existingNode);
            if (childNode instanceof IntegralNode) {
                integralNodeMap.remove(childNode.getName());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) CppNode(mrmathami.cia.cpp.ast.CppNode) IBodyContainer(mrmathami.cia.cpp.ast.IBodyContainer) IntegralNode(mrmathami.cia.cpp.ast.IntegralNode)

Aggregations

HashMap (java.util.HashMap)1 CppNode (mrmathami.cia.cpp.ast.CppNode)1 IBodyContainer (mrmathami.cia.cpp.ast.IBodyContainer)1 IntegralNode (mrmathami.cia.cpp.ast.IntegralNode)1