Ignore:
Timestamp:
Dec 22, 2016, 2:35:46 PM (2 years ago)
Author:
nmedfort
Message:

Modified memory alignment mechanism for GetPropertyValueGrepString? + misc. changes.

File:
1 edited

Legend:

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

    r5233 r5234  
    88#include "PropertyObjects.h"
    99#include "PropertyObjectTable.h"
    10 #include <sstream>
     10#include <llvm/Support/Casting.h>
    1111#include <algorithm>
    1212#include <assert.h>
    13 #include <llvm/Support/Casting.h>
     13#include <sstream>
    1414
    1515using namespace llvm;
     
    1717namespace UCD {
    1818
     19using PropertyStringStream =
     20    std::basic_stringstream<char, std::char_traits<char>, PropertyStringAllocator>;
     21
    1922std::string canonicalize_value_name(const std::string & prop_or_val) {
    2023    std::locale loc;
    2124    std::stringstream s;
     25
    2226    for (char c : prop_or_val) {
    2327        if ((c != '_') && (c != ' ') && (c != '-')) {
     
    3135    throw std::runtime_error("Property " + value_spec + " unsupported.");
    3236}
    33 const std::string& PropertyObject::GetPropertyValueGrepString() {
     37const PropertyString & PropertyObject::GetPropertyValueGrepString() {
    3438    throw std::runtime_error("Property Value Grep String unsupported.");
    3539}
     
    4448
    4549const UnicodeSet & EnumeratedPropertyObject::GetCodepointSet(const std::string & value_spec) {
    46     int property_enum_val = GetPropertyValueEnumCode(value_spec);
    47     if (property_enum_val == -1) {
    48         throw std::runtime_error("Enumerated Property " + UCD::property_full_name[the_property] +  ": unknown value: " + value_spec);
     50    const int property_enum_val = GetPropertyValueEnumCode(value_spec);
     51    if (property_enum_val < 0) {
     52        throw std::runtime_error("Enumerated Property " + UCD::property_full_name[the_property] + ": unknown value: " + value_spec);
    4953    }
    5054    return GetCodepointSet(property_enum_val);
     
    6367        // has bit i set, i.e., (e >> i) & 1 == 1.
    6468        unsigned basis_count = 1;
    65         while ((1 << basis_count) < independent_enum_count) basis_count++;
     69        while ((1UL << basis_count) < independent_enum_count) {
     70            basis_count++;
     71        }
    6672        for (unsigned i = 0; i < basis_count; i++) {
    6773            enumeration_basis_sets.push_back(UnicodeSet());
    6874            for (unsigned e = 0; e < independent_enum_count; e++) {
    69                 if (((e >> i) & 1) == 0) {
     75                if (((e >> i) & 1UL) == 0) {
    7076                    enumeration_basis_sets[i] = enumeration_basis_sets[i] + *property_value_sets[e];
    7177                }
     
    7682};
    7783
    78 const std::string& EnumeratedPropertyObject::GetPropertyValueGrepString() {
    79     if (!property_value_grep_string.size()) {
     84const PropertyString &EnumeratedPropertyObject::GetPropertyValueGrepString() {
     85    if (LLVM_LIKELY(property_value_grep_string.empty())) {
     86        PropertyStringStream buffer;
    8087        for (unsigned i = 0; i != property_value_full_names.size(); i++) {
    81             property_value_grep_string += canonicalize_value_name(property_value_full_names[i]) + "\n";
     88            buffer << canonicalize_value_name(property_value_full_names[i]) + "\n";
    8289        }
    8390        for (unsigned i = 0; i != property_value_enum_names.size(); i++) {
    84             property_value_grep_string += canonicalize_value_name(property_value_enum_names[i]) + "\n";
     91            buffer << canonicalize_value_name(property_value_enum_names[i]) + "\n";
    8592        }
     93        property_value_grep_string.assign(buffer.str());
    8694    }
    8795    return property_value_grep_string;
     
    137145}
    138146
    139 const std::string& ExtensionPropertyObject::GetPropertyValueGrepString() {
     147const PropertyString & ExtensionPropertyObject::GetPropertyValueGrepString() {
    140148    return property_object_table[base_property]->GetPropertyValueGrepString();
    141149}
     
    164172}
    165173
    166 const std::string& BinaryPropertyObject::GetPropertyValueGrepString() {
    167     if (!property_value_grep_string.size()) {
    168         for (auto iter = Binary_ns::aliases_only_map.begin(), end = Binary_ns::aliases_only_map.end(); iter != end; ++iter) {
    169             property_value_grep_string += iter->first + "\n";
     174const PropertyString & BinaryPropertyObject::GetPropertyValueGrepString() {
     175    if (property_value_grep_string.empty()) {
     176        PropertyStringStream buffer;
     177        for (const auto & prop : Binary_ns::aliases_only_map) {
     178            buffer << std::get<0>(prop) + "\n";
    170179        }
     180        property_value_grep_string.assign(buffer.str());
    171181    }
    172182    return property_value_grep_string;
Note: See TracChangeset for help on using the changeset viewer.