environment find_cmd(parser & p) { expr e; level_param_names ls; { bool save_options = true; parser::local_scope scope(p, save_options); p.set_option(get_elaborator_ignore_instances_name(), true); std::tie(e, ls) = parse_local_expr(p); } buffer<std::string> pos_names, neg_names; parse_filters(p, pos_names, neg_names); environment env = p.env(); auto tc = mk_opaque_type_checker(env, p.mk_ngen()); flycheck_information info(p.regular_stream()); if (info.enabled()) { p.display_information_pos(p.cmd_pos()); } p.regular_stream() << "find_decl result:\n"; unsigned max_steps = get_find_max_steps(p.get_options()); bool cheap = !get_find_expensive(p.get_options()); bool found = false; env.for_each_declaration([&](declaration const & d) { if (std::all_of(pos_names.begin(), pos_names.end(), [&](std::string const & pos) { return is_part_of(pos, d.get_name()); }) && std::all_of(neg_names.begin(), neg_names.end(), [&](std::string const & neg) { return !is_part_of(neg, d.get_name()); }) && match_pattern(*tc.get(), e, d, max_steps, cheap)) { found = true; p.regular_stream() << " " << get_decl_short_name(d.get_name(), env) << " : " << d.get_type() << endl; } }); if (!found) p.regular_stream() << "no matches\n"; return env; }
/* A helper function intended to be called only from set_column_type */ void GncTxImport::update_pre_trans_props (uint32_t row, uint32_t col, GncTransPropType prop_type) { if ((prop_type == GncTransPropType::NONE) || (prop_type > GncTransPropType::TRANS_PROPS)) return; /* Only deal with transaction related properties. */ /* Deliberately make a copy of the GncPreTrans. It may be the original one was shared * with a previous line and should no longer be after the transprop is changed. */ auto trans_props = std::make_shared<GncPreTrans> (*(std::get<PL_PRETRANS>(m_parsed_lines[row])).get()); auto value = std::string(); if (col < std::get<PL_INPUT>(m_parsed_lines[row]).size()) value = std::get<PL_INPUT>(m_parsed_lines[row]).at(col); if (value.empty()) trans_props->reset (prop_type); else { try { trans_props->set(prop_type, value); } catch (const std::exception& e) { /* Do nothing, just prevent the exception from escalating up * However log the error if it happens on a row that's not skipped */ if (!std::get<PL_SKIP>(m_parsed_lines[row])) PINFO("User warning: %s", e.what()); } } /* Store the result */ std::get<PL_PRETRANS>(m_parsed_lines[row]) = trans_props; /* For multi-split input data, we need to check whether this line is part of * a transaction that has already been started by a previous line. */ if (m_settings.m_multi_split) { if (trans_props->is_part_of(m_parent)) { /* This line is part of an already started transaction * continue with that one instead to make sure the split from this line * gets added to the proper transaction */ std::get<PL_PRETRANS>(m_parsed_lines[row]) = m_parent; } else { /* This line starts a new transaction, set it as parent for * subsequent lines. */ m_parent = trans_props; } } }