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

Last change on this file since 5792 was 5792, checked in by cameron, 18 months ago

\N{...} expressions now anchored; name expresions in ranges functional

File size: 1.2 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#include <llvm/Support/ErrorHandling.h>
12
13using namespace llvm;
14
15namespace re {
16
17RE * makeRange(RE * lo, RE * hi) {
18    if (isa<CC>(lo) && isa<CC>(hi)) {
19        if (!((dyn_cast<CC>(lo)->count() == 1) && (dyn_cast<CC>(hi)->count() == 1)))
20            llvm::report_fatal_error("invalid range operand");
21        auto lo_val = dyn_cast<CC>(lo)->front().first;
22        auto hi_val = dyn_cast<CC>(hi)->front().first;
23        if (hi_val < lo_val) llvm::report_fatal_error("illegal range");
24        return makeCC(lo_val, hi_val);
25    }
26    else if (isa<Name>(lo) && (cast<Name>(lo)->getDefinition() != nullptr)) {
27        return makeRange(cast<Name>(lo)->getDefinition(), hi);
28    }
29    else if (isa<Name>(hi) && (cast<Name>(hi)->getDefinition() != nullptr)) {
30        return makeRange(lo, cast<Name>(hi)->getDefinition());
31    }
32    else if (lo == hi) { // TODO: general check for equality, not just instance equality
33        return lo;
34    }
35    return new Range(lo, hi);
36}
37   
38}
Note: See TracBrowser for help on using the repository browser.