source: icGREP/icgrep-devel/icgrep/re/re_range.cpp @ 5787

Last change on this file since 5787 was 5787, checked in by cameron, 7 months ago

RE parser restructuring; parsing symbolic ranges, collation and equivalence exprs

File size: 1.0 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <re/re_range.h>
8#include <re/re_cc.h>
9#include <re/re_name.h>
10#include <llvm/Support/Casting.h>
11
12using namespace llvm;
13
14namespace re {
15
16RE * makeRange(RE * lo, RE * hi) {
17    if (isa<CC>(lo) && isa<CC>(hi)) {
18        assert(dyn_cast<CC>(lo)->count() == 1);
19        assert(dyn_cast<CC>(hi)->count() == 1);
20        return makeCC(dyn_cast<CC>(lo)->front().first, dyn_cast<CC>(hi)->front().first);
21    }
22    else if (isa<Name>(lo) && (cast<Name>(lo)->getDefinition() != nullptr)) {
23        return makeRange(cast<Name>(lo)->getDefinition(), hi);
24    }
25    else if (isa<Name>(hi) && (cast<Name>(hi)->getDefinition() != nullptr)) {
26        return makeRange(lo, cast<Name>(hi)->getDefinition());
27    }
28    else if (lo == hi) { // TODO: general check for equality, not just instance equality
29        return lo;
30    }
31    return new Range(lo, hi);
32}
33   
34}
Note: See TracBrowser for help on using the repository browser.