Example #1
0
annotation annotation_groups_factory::create_annotation(const scope_types scope,
        const std::unordered_map<std::string, std::list<std::string>>&
        aggregated_scribble_entries) const {

    annotation r;
    r.scope(scope);

    value_factory f;
    std::unordered_map<std::string, boost::shared_ptr<value>> entries;
    std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
            all_kvps;
    for (auto kvp : aggregated_scribble_entries) {
        const auto& k(kvp.first);
        const auto t(obtain_type(k));

        validate_scope(t, r.scope());

        const auto& v(kvp.second);
        if (t.value_type() == value_types::key_value_pair) {
            BOOST_LOG_SEV(lg, debug) << "Adding kvp for key: " << k;
            if (v.size() != 1) {
                BOOST_LOG_SEV(lg, debug) << too_many_values << k;
                BOOST_THROW_EXCEPTION(building_error(too_many_values + k));
            }

            const auto qn(t.name().qualified());
            const auto new_key(boost::erase_first_copy(k, qn + "."));
            BOOST_LOG_SEV(lg, debug) << "Actual key: " << new_key;

            const auto pair(std::make_pair(new_key, v.front()));
            const auto inserted(all_kvps[qn].insert(pair).second);
            if (!inserted) {
                BOOST_LOG_SEV(lg, debug) << duplicate_key << new_key;
                BOOST_THROW_EXCEPTION(building_error(duplicate_key + new_key));
            }
        } else
            r.entries()[k] = f.make(t, v);
    }

    for (const auto& pair : all_kvps) {
        BOOST_LOG_SEV(lg, debug) << "Processing kvp:: " << pair;

        const auto k(pair.first);
        const auto kvps(pair.second);
        r.entries()[k] = f.make_kvp(kvps);
    }

    return r;
}
bundle_repository bundle_repository_factory::
make(const dynamic::repository& rp, const dynamic::object& root_object,
    const dogen::formatters::general_settings_factory& gsf,
    const opaque_settings_builder& osb, const sml::model& m) const {

    BOOST_LOG_SEV(lg, debug) << "Creating settings bundle repository.";

    const bundle_factory f(rp, root_object, gsf, osb);
    generator g(f);
    sml::all_model_items_traversal(m, g);
    auto r(g.result());

    // FIXME: hack to handle registars.
    sml::qname qn;
    qn.simple_name(registrar_name);
    qn.model_name(m.name().model_name());
    qn.external_module_path(m.name().external_module_path());

    const auto pair(std::make_pair(qn, f.make()));
    auto& deps(r.bundles_by_qname());
    const auto res(deps.insert(pair));
    if (!res.second) {
        const auto n(sml::string_converter::convert(qn));
        BOOST_LOG_SEV(lg, error) << duplicate_qname << n;
        BOOST_THROW_EXCEPTION(building_error(duplicate_qname + n));
    }

    BOOST_LOG_SEV(lg, debug) << "Finished creating settings bundle repository."
                             << r;
    return r;
}
std::unordered_map<std::string, path_derivatives>
path_derivatives_factory::make(const yarn::name& n) const {
    std::unordered_map<std::string, path_derivatives> r;

    for (const auto& pair : path_settings_) {
        if (pair.first.empty()) {
            BOOST_LOG_SEV(lg, error) << empty_formatter_name;
            BOOST_THROW_EXCEPTION(building_error(empty_formatter_name));
        }

        const auto& s(pair.second);
        const auto inclusion_path(make_inclusion_path(s, n));

        path_derivatives pd;
        const auto file_path(make_file_path(s, inclusion_path, n));
        pd.file_path(file_path);

        if (s.file_type() == formatters::file_types::cpp_header) {
            pd.inclusion_directive(to_inclusion_directive(inclusion_path));
            pd.header_guard(to_header_guard_name(inclusion_path));
        }

        r[pair.first] = pd;
    }
    return r;
}
boost::filesystem::path path_derivatives_factory::
make_file_path(const settings::path_settings& ps,
    const boost::filesystem::path& inclusion_path,
    const yarn::name& n) const {
    BOOST_LOG_SEV(lg, debug) << "Creating file path for: " << n.qualified();

    boost::filesystem::path r;

    const auto ft(ps.file_type());
    const auto& mmp(n.location().model_modules());
    switch (ft) {
    case formatters::file_types::cpp_header:
        r = options_.project_directory_path();
        r /= boost::algorithm::join(mmp, dot);
        r /= ps.include_directory_name();
        break;

    case formatters::file_types::cpp_implementation:
        r = options_.project_directory_path();
        r /= boost::algorithm::join(mmp, dot);
        r /= ps.source_directory_name();
        break;

    default:
        BOOST_LOG_SEV(lg, error) << unsupported_file_type << ft;
        BOOST_THROW_EXCEPTION(building_error(unsupported_file_type +
                boost::lexical_cast<std::string>(ft)));
    }

    r /= inclusion_path;

    BOOST_LOG_SEV(lg, debug) << "Done creating file path. Result: " << r;
    return r;
}
Example #5
0
type annotation_groups_factory::obtain_type(const std::string& n) const {
    /*
     * First try a full match; if it exists, return the type.
     */
    const auto i(type_repository_.types_by_name().find(n));
    if (i != type_repository_.types_by_name().end())
        return i->second;

    /*
     * Now try the partial matches. Note that we can be sure there
     * will only be one match due to the logic of partial matching, as
     * two types cannot have the same name.
     */
    for (const auto& pair : type_repository_.partially_matchable_types()) {
        const auto& qn(pair.first);
        const auto& t(pair.second);
        if (boost::starts_with(n, qn))
            return t;
    }

    /*
     * If nothing matches we need to throw.
     */
    BOOST_LOG_SEV(lg, error) << type_not_found << n;
    BOOST_THROW_EXCEPTION(building_error(type_not_found + n));
}
boost::optional<std::pair<std::string, std::string> >
inclusion_directives_factory::obtain_include_directive(
    const std::string& formatter_name,
    const std::string& type_name,
    const std::unordered_map<std::string,
    formattables::path_derivatives>& pd,
    const settings::inclusion_directive_settings& s) const {

    if (!s.inclusion_required()) {
        BOOST_LOG_SEV(lg, debug) << "Inclusion directive not required. "
                                 << "Type: " << type_name
                                 << " formatter: " << formatter_name;
        return boost::optional<std::pair<std::string, std::string> >();
    }

    if (s.inclusion_directive()) {
        const auto id(*s.inclusion_directive());
        validate_inclusion_directive(id, formatter_name, type_name);
        return std::make_pair(formatter_name, id);
    }

    const auto pdfn(path_derivatives_for_formatter_name(pd, formatter_name));
    const auto id(pdfn.inclusion_directive());
    if (!id) {
        BOOST_LOG_SEV(lg, error) << missing_include_directive
                                 << formatter_name;
        BOOST_THROW_EXCEPTION(
            building_error(missing_include_directive + formatter_name));
    }
    validate_inclusion_directive(*id, formatter_name, type_name);
    return std::make_pair(formatter_name, *id);
}
std::unordered_map<std::string, formattables::path_derivatives>
inclusion_directives_factory::path_derivatives_for_name(
    const tack::name& n) const {
    const auto i(path_repository_.path_derivatives_by_name().find(n));
    if (i == path_repository_.path_derivatives_by_name().end()) {
        const auto qn(n.qualified());
        BOOST_LOG_SEV(lg, error) << name_not_found << qn;
        BOOST_THROW_EXCEPTION(building_error(name_not_found + qn));
    }
    return i->second;
}
Example #8
0
void annotation_groups_factory::validate_scope(const type& t,
        const scope_types current_scope) const {
    if (t.scope() != scope_types::any &&
            t.scope() != scope_types::not_applicable &&
            t.scope() != current_scope) {

        std::stringstream s;
        s << field_used_in_invalid_scope << t.name().qualified()
          << expected_scope << t.scope()
          << actual_scope << current_scope;
        BOOST_LOG_SEV(lg, error) << s.str();
        BOOST_THROW_EXCEPTION(building_error(s.str()));
    }
}
formattables::path_derivatives
inclusion_directives_factory::path_derivatives_for_formatter_name(
    const std::unordered_map<std::string,
    formattables::path_derivatives>& pd,
    const std::string& formatter_name) const {

    const auto i(pd.find(formatter_name));
    if (i == pd.end()) {
        BOOST_LOG_SEV(lg, error) << formatter_name_not_found
                                 << formatter_name;
        BOOST_THROW_EXCEPTION(
            building_error(formatter_name_not_found + formatter_name));
    }
    return i->second;
}
void inclusion_directives_factory::validate_inclusion_directive(
    const std::string& id,
    const std::string& formatter_name,
    const std::string& type_name) const {

    if (!id.empty())
        return;

    std::ostringstream s;
    s << empty_include_directive << formatter_name
      << " for type: " << type_name;

    const auto msg(s.str());
    BOOST_LOG_SEV(lg, error) << msg;
    BOOST_THROW_EXCEPTION(building_error(msg));
}
Example #11
0
name name_factory::build_module_name(const name& model_name,
    const std::list<std::string>& internal_modules) const {

    if (internal_modules.empty()) {
        BOOST_LOG_SEV(lg, error) << empty_internal_modules;
        BOOST_THROW_EXCEPTION(building_error(empty_internal_modules));
    }

    yarn::name n;
    n.simple(internal_modules.back());

    const auto& l(model_name.location());
    n.location().model_modules(l.model_modules());
    n.location().external_modules(l.external_modules());

    auto ipp(internal_modules);
    ipp.pop_back();
    n.location().internal_modules(ipp);

    name_builder b(n);
    return b.build();
}
Example #12
0
std::unordered_map<std::string, bool>
enablement_factory::compute_enablement_value(
    const std::unordered_map<std::string, local_enablement_properties>&
    lep, const bool types_only) const {

    std::unordered_map<std::string, bool> r;
    for (const auto& pair : lep) {
        const auto& fn(pair.first);
        const auto i(global_enablement_properties_.find(fn));
        if (i == global_enablement_properties_.end()) {
            BOOST_LOG_SEV(lg, error) << global_properties_not_found << fn;
            BOOST_THROW_EXCEPTION(
                building_error(global_properties_not_found + fn));
        }

        const auto gep(i->second);
        if (!gep.model_enabled() || !gep.facet_enabled()) {
            // model or facet have been disabled, so formatter will be
            // disabled.
            r[fn] = false;
            continue;
        }

        if (types_only) {
            const auto is_types(boost::starts_with(fn, "cpp.types."));
            r[fn] = is_types;
            continue;
        }

        if (pair.second.enabled) {
            // formatter field has been set and so takes precedence.
            r[fn] = *pair.second.enabled;
            continue;
        }

        r[fn] = gep.formatter_enabled();
    }
    return r;
}
std::unordered_map<std::string, std::list<std::string> >
generate(const inclusion_dependencies_builder_factory& f,
    std::forward_list<
        boost::shared_ptr<
            inclusion_dependencies_provider_interface<SmlEntity>
            >
        > providers, const SmlEntity& e) {

    const auto n(sml::string_converter::convert(e.name()));
    BOOST_LOG_SEV(lg, debug) << "Creating inclusion dependencies for: " << n;

    std::unordered_map<std::string, std::list<std::string> > r;
    for (const auto p : providers) {
        BOOST_LOG_SEV(lg, debug) << "Providing for: " << p->formatter_name();
        auto id(p->provide(f, e));

        if (!id)
            continue;

        id->sort(include_directive_comparer);
        id->unique();
        const auto id_pair(std::make_pair(p->formatter_name(), *id));
        const bool inserted(r.insert(id_pair).second);
        if (!inserted) {
            BOOST_LOG_SEV(lg, error) << duplicate_formatter_name
                                     << p->formatter_name()
                                     << " for type: " << n;
            BOOST_THROW_EXCEPTION(building_error(duplicate_formatter_name +
                    p->formatter_name()));
        }
    }

    BOOST_LOG_SEV(lg, debug) << "Finished creating inclusion dependencies for: "
                             << n;

    return r;
}
Example #14
0
annotation annotation_groups_factory::
handle_profiles(const type_group& tg, const std::unordered_map<std::string,
                annotation>& profiles, const std::vector<std::string>& candidate_labels,
                const annotation& original) const {

    BOOST_LOG_SEV(lg, debug) << "Started handling profiles. Original: "
                             << original;

    /*
     * If a profile name was specified via the meta-data, it must
     * exist on our profile collection. Locate it, merge it with the
     * original annotation and return that.
     */
    const auto profn(obtain_profile_name(tg, original));
    if (!profn.empty()) {
        BOOST_LOG_SEV(lg, debug) << "Configured profile: " << profn;
        const auto i(profiles.find(profn));
        if (i == profiles.end()) {
            BOOST_LOG_SEV(lg, error) << missing_profile << profn;
            BOOST_THROW_EXCEPTION(building_error(missing_profile + profn));
        }

        merger mg;
        const auto annotation_profile(i->second);
        const annotation r(mg.merge(original, annotation_profile));
        BOOST_LOG_SEV(lg, debug) << "Merged profile: " << r;
        return r;
    } else
        BOOST_LOG_SEV(lg, debug) << "Profile not set in meta-data.";

    /*
     * Lets try each of the candidate labels instead and see if any of
     * them bind to a profile.
     */
    const auto bound_labels(get_bound_labels(profiles, candidate_labels));
    if (bound_labels.size() > 1) {
        BOOST_LOG_SEV(lg, error) << too_many_binds << bound_labels;
        BOOST_THROW_EXCEPTION(building_error(too_many_binds));
    }

    for (const auto& bl : bound_labels) {
        BOOST_LOG_SEV(lg, debug) << "Bound label: " << bl;
        const auto i(profiles.find(bl));
        if (i == profiles.end()) {
            BOOST_LOG_SEV(lg, error) << missing_profile << bl;
            BOOST_THROW_EXCEPTION(building_error(missing_profile + bl));
        }

        merger mg;
        const auto annotation_profile(i->second);
        const annotation r(mg.merge(original, annotation_profile));
        BOOST_LOG_SEV(lg, debug) << "Merged profile: " << r;
        return r;
    }

    /*
     * If no profile name was found by now, we need to try looking for
     * the well-known default profiles, based on the scope of the
     * annotation. Not all scope types have a mapping, and the default
     * profiles do not necessarily exist.
     */
    const auto def_profn(get_default_profile_name_for_scope(original.scope()));
    if (!def_profn.empty()) {
        BOOST_LOG_SEV(lg, debug) << "Looking for default profile; " << def_profn;

        const auto i(profiles.find(def_profn));
        if (i != profiles.end()) {
            merger mg;
            const auto annotation_profile(i->second);
            const annotation r(mg.merge(original, annotation_profile));
            BOOST_LOG_SEV(lg, debug) << "Merged profile: " << r;
            return r;
        }
    } else
        BOOST_LOG_SEV(lg, debug) << "Scope does not have a default profile.";

    /*
     * If we could find nothing suitable, just return the original.
     */
    BOOST_LOG_SEV(lg, debug) << "No profiles found, using original.";
    return original;
}