Ignore:
Timestamp:
Jun 30, 2015, 3:12:47 PM (4 years ago)
Author:
nmedfort
Message:

Temporary check-in for dynamic unicode class compilation.

Location:
icGREP/icgrep-devel/icgrep/UCD
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/PropertyObjects.cpp

    r4618 r4626  
    1111namespace UCD {
    1212
    13 std::string canonicalize_value_name(const std::string prop_or_val) {
     13std::string canonicalize_value_name(const std::string & prop_or_val) {
    1414    std::locale loc;
    1515    std::stringstream s;
     
    2222}
    2323
    24 
    25 UnicodeSet UnsupportedPropertyObject::GetCodepointSet(const std::string value_spec) {
     24UnicodeSet UnsupportedPropertyObject::GetCodepointSet(const std::string &) {
    2625    throw std::runtime_error("Property " + UCD::property_full_name[the_property] + " unsupported.");
    2726}
    2827
    29 UnicodeSet EnumeratedPropertyObject::GetCodepointSet(const std::string value_spec) {
     28UnicodeSet UnsupportedPropertyObject::GetCodepointSet(const int) {
     29    throw std::runtime_error("Property " + UCD::property_full_name[the_property] + " unsupported.");
     30}
     31
     32UnicodeSet EnumeratedPropertyObject::GetCodepointSet(const std::string & value_spec) {
    3033    int property_enum_val = GetPropertyValueEnumCode(value_spec);
    3134    if (property_enum_val == -1) {
    32             throw std::runtime_error("Enumerated Property " + UCD::property_full_name[the_property] +  ": unknown value: " + value_spec);
     35        throw std::runtime_error("Enumerated Property " + UCD::property_full_name[the_property] +  ": unknown value: " + value_spec);
    3336    }
    34     else {
    35         return property_value_sets[property_enum_val];
    36     }
     37    return GetCodepointSet(property_enum_val);
    3738}
    3839
    39 int EnumeratedPropertyObject::GetPropertyValueEnumCode(const std::string s) {
     40UnicodeSet EnumeratedPropertyObject::GetCodepointSet(const int property_enum_val) const {
     41    assert (property_enum_val >= 0);
     42    return property_value_sets[property_enum_val];
     43}
     44
     45int EnumeratedPropertyObject::GetPropertyValueEnumCode(const std::string & value_spec) {
    4046    // The canonical full names are not stored in the precomputed alias map,
    4147    // to save space in the executable.   Add them if the property is used.
    4248    if (!aliases_initialized) {
    43         for (auto v = 0; v < property_value_full_names.size(); v++) {
    44             property_value_aliases.insert({canonicalize_value_name(property_value_full_names[v]), v});
     49        for (unsigned i = 0; i != property_value_full_names.size(); i++) {
     50            property_value_aliases.insert({canonicalize_value_name(property_value_full_names[i]), i});
    4551        }
    46         for (auto v = 0; v < property_value_enum_names.size(); v++) {
    47             property_value_aliases.insert({canonicalize_value_name(property_value_enum_names[v]), v});
     52        for (unsigned i = 0; i != property_value_enum_names.size(); i++) {
     53            property_value_aliases.insert({canonicalize_value_name(property_value_enum_names[i]), i});
    4854        }
    4955        aliases_initialized = true;
    5056    }
    51     auto valit = property_value_aliases.find(s);
    52     if (valit == property_value_aliases.end()) return -1;
    53     else return valit->second;
     57    const auto valit = property_value_aliases.find(value_spec);
     58    if (valit == property_value_aliases.end())
     59        return -1;
     60    return valit->second;
    5461}
    5562
    56 UnicodeSet BinaryPropertyObject::GetCodepointSet(const std::string value_spec) {
    57     int property_enum_val = Binary_ns::Y; // default value
    58     if (value_spec != "") {
     63UnicodeSet BinaryPropertyObject::GetCodepointSet(const std::string & value_spec) const {
     64    if (value_spec.length() != 0) {
    5965        auto valit = Binary_ns::aliases_only_map.find(value_spec);
    6066        if (valit == Binary_ns::aliases_only_map.end()) {
    61                     throw std::runtime_error("Binary Property " + UCD::property_full_name[the_property] +  ": bad value: " + value_spec);
     67            throw std::runtime_error("Binary Property " + UCD::property_full_name[the_property] +  ": bad value: " + value_spec);
    6268        }
    63         else property_enum_val = valit->second;
    64         if (property_enum_val == Binary_ns::Y) return the_codepoint_set;
    65         else return uset_complement(the_codepoint_set);
     69        if (valit->second == Binary_ns::Y)
     70            return the_codepoint_set;
     71        return ~the_codepoint_set;
    6672    }
    67     else return the_codepoint_set;
     73    return the_codepoint_set;
    6874}
    6975
     76UnicodeSet BinaryPropertyObject::GetCodepointSet(const int property_enum_val) const {
     77    if (property_enum_val == Binary_ns::Y)
     78        return the_codepoint_set;
     79    return ~the_codepoint_set;
     80}
    7081
    7182}
  • icGREP/icgrep-devel/icgrep/UCD/PropertyObjects.h

    r4618 r4626  
    1717namespace UCD {
    1818
    19     std::string canonicalize_value_name(const std::string prop_or_val);
     19    std::string canonicalize_value_name(const std::string & prop_or_val);
    2020
    2121        class PropertyObject {
     
    3131                property_t the_property;
    3232                ClassTypeId the_kind;
    33                
    34         virtual UnicodeSet GetCodepointSet(const std::string value_spec) = 0;
    3533        };
    3634       
     
    4543       
    4644                UnsupportedPropertyObject(property_t p, ClassTypeId k) : PropertyObject(p, k) {}
    47         UnicodeSet GetCodepointSet(const std::string value_spec);
     45        UnicodeSet GetCodepointSet(const std::string &);
     46        UnicodeSet GetCodepointSet(const int);
    4847        };
    4948       
     
    6362                                         const std::vector<UnicodeSet> sets) :
    6463                PropertyObject(p, ClassTypeId::EnumeratedProperty), property_value_enum_names(enum_names), property_value_full_names(names), property_value_aliases(aliases), aliases_initialized(false), property_value_sets(sets) {}
    65         int GetPropertyValueEnumCode(const std::string s);
    66         UnicodeSet GetCodepointSet(const std::string value_spec);
     64        int GetPropertyValueEnumCode(const std::string & value_spec);
     65        UnicodeSet GetCodepointSet(const std::string & value_spec);
     66        UnicodeSet GetCodepointSet(const int property_enum_val) const;
    6767               
    6868        private:
     
    8484               
    8585                BinaryPropertyObject(UCD::property_t p, UnicodeSet s) : PropertyObject(p, ClassTypeId::BinaryProperty), the_codepoint_set(s) {}
    86         UnicodeSet GetCodepointSet(const std::string value_spec);
     86        UnicodeSet GetCodepointSet(const std::string & value_spec) const;
     87        UnicodeSet GetCodepointSet(const int property_enum_val) const;
    8788    private:
    8889                UnicodeSet the_codepoint_set;       
  • icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.cpp

    r4625 r4626  
    33#include <UCD/unicode_set.h>
    44#include <utf8_encoder.h>
     5#include <iostream>
    56
    67using namespace cc;
  • icGREP/icgrep-devel/icgrep/UCD/unicode_set.cpp

    r4622 r4626  
    385385    assert (n == 1);   
    386386
     387    if (LLVM_UNLIKELY(mBaseCodePoint >= CC::UNICODE_MAX)) {
     388        mRunIterator = mRunEnd;
     389        mQuadIterator = mQuadEnd;
     390        mMixedRunIndex = 0;
     391        mQuadOffset = 0;
     392        return;
     393    }
     394
    387395    // Find the start of our interval
    388396    for ( ; mBaseCodePoint < CC::UNICODE_MAX; ++mRunIterator) {
     
    399407            }
    400408        }
    401         else { // if (leftypeOf(t) == Mixed)
     409        else { // if (typeOf(t) == Mixed)
    402410            bool found = false;
    403411            while (mMixedRunIndex != lengthOf(*mRunIterator)) {
     
    439447            continue;
    440448        }
    441         else { // if (leftypeOf(t) == Mixed)
     449        else { // if (typeOf(t) == Mixed)
    442450            bool found = false;
    443451            while (mMixedRunIndex != lengthOf(*mRunIterator)) {
     
    463471    }
    464472
    465 
    466473}
    467474
  • icGREP/icgrep-devel/icgrep/UCD/unicode_set.h

    r4622 r4626  
    5555        friend class boost::iterator_core_access;
    5656    protected:
    57         iterator(RunVector::const_iterator runIterator, QuadVector::const_iterator quadIterator)
     57        iterator(RunVector::const_iterator runIterator, QuadVector::const_iterator quadIterator,
     58                 RunVector::const_iterator runEnd, QuadVector::const_iterator quadEnd)
    5859        : mRunIterator(runIterator), mQuadIterator(quadIterator)
    5960        , mMixedRunIndex(0), mQuadOffset(0), mBaseCodePoint(0), mMinCodePoint(0), mMaxCodePoint(0)
     61        , mRunEnd(runEnd), mQuadEnd(quadEnd)
    6062        {
    6163
     
    7779        }
    7880    private:
    79         RunVector::const_iterator   mRunIterator;
    80         QuadVector::const_iterator  mQuadIterator;
    81         unsigned                    mMixedRunIndex;
    82         bitquad_t                   mQuadOffset;       
    83         codepoint_t                 mBaseCodePoint;
    84         codepoint_t                 mMinCodePoint;
    85         codepoint_t                 mMaxCodePoint;
     81        RunVector::const_iterator           mRunIterator;
     82        QuadVector::const_iterator          mQuadIterator;
     83        unsigned                            mMixedRunIndex;
     84        bitquad_t                           mQuadOffset;
     85        codepoint_t                         mBaseCodePoint;
     86        codepoint_t                         mMinCodePoint;
     87        codepoint_t                         mMaxCodePoint;
     88        const RunVector::const_iterator     mRunEnd;
     89        const QuadVector::const_iterator    mQuadEnd;
    8690    };
    8791
    8892    inline iterator begin() const {
    8993        // note: pre-increment is intentional to move the iterator onto the first non-Empty interval.
    90         return ++iterator(mRuns.cbegin(), mQuads.cbegin());
     94        return ++iterator(mRuns.cbegin(), mQuads.cbegin(), mRuns.cend(), mQuads.cend());
    9195    }
    9296
    9397    inline iterator end() const {
    94         return iterator(mRuns.cend(), mQuads.cend());
     98        return iterator(mRuns.cend(), mQuads.cend(), mRuns.cend(), mQuads.cend());
    9599    }
    96100
     
    113117
    114118        inline run_t run() const {
    115             const auto & t = *mRunIterator;
    116             return std::make_pair(std::get<0>(t), std::get<1>(t) - mOffset);
     119            return std::make_pair(std::get<0>(*mRunIterator), std::get<1>(*mRunIterator) - mOffset);
    117120        }
    118121
Note: See TracChangeset for help on using the changeset viewer.