void transform_load(int reg,int now)//转化为ok expr { char op[expr_size],fuc1[expr_size],fuc2[expr_size],temp[expr_size]; sscanf(inst[reg],"%s %s %s",op,fuc1,fuc2); if(strcmp(op,"global")==0) { sprintf(inst[now],"ok %s ",fuc1); } else if(strcmp(op,"array")==0) { int t=0; sscanf(inst[reg],"%s %s %s %s %s %d",op,op,fuc1,temp,fuc2,&t); if(strcmp(fuc2,"reg")==0) { get_expr(t,fuc2); sprintf(inst[now],"ok %s[(%s)] ",fuc1,fuc2); } else { sprintf(inst[now],"ok %s ",op); } } else if(strcmp(op,"array2")==0) { sprintf(inst[now],"ok %s",fuc1); sscanf(inst[reg-1],"%s %s",op,fuc1); if(strcmp(op,"ok")!=0) { int t=0; sscanf(fuc1,"%d",&t); get_expr(t,fuc1); } sscanf(inst[reg-2],"%s %s",op,fuc2); if(strcmp(op,"ok")!=0) { int t=0; sscanf(fuc2,"%d",&t); get_expr(t,fuc2); } sprintf(inst[now],"%s[%s][%s]",inst[now],fuc2,fuc1); } else if(strcmp(op,"struct")==0) { sprintf(inst[now],"ok %s ",fuc1); } else if(strcmp(op,"ok")==0) { sprintf(inst[now],"ok %s ",fuc1); } else { cout <<"inst: "<<inst[reg]<<endl; printf("not realize!\n"); } }
grn_query * grn_query_open(grn_ctx *ctx, const char *str, unsigned int str_len, grn_operator default_op, int max_exprs) { grn_query *q; int max_cells = max_exprs * 4; if (!(q = GRN_MALLOC(sizeof(grn_query) + max_cells * sizeof(grn_cell) + str_len + 1))) { GRN_LOG(ctx, GRN_LOG_ALERT, "grn_query_open malloc fail"); return NULL; } q->header.type = GRN_QUERY; q->str = (char *)&q->cell_pool[max_cells]; memcpy(q->str, str, str_len); q->str[str_len] = '\0'; q->cur = q->str; q->str_end = q->str + str_len; q->default_op = default_op; q->encoding = ctx->encoding; q->max_exprs = max_exprs; q->max_cells = max_cells; q->cur_cell = 0; q->cur_expr = 0; q->escalation_threshold = GRN_DEFAULT_MATCH_ESCALATION_THRESHOLD; q->escalation_decaystep = DEFAULT_DECAYSTEP; q->weight_offset = 0; q->opt.weight_vector = NULL; q->weight_set = NULL; get_pragma(ctx, q); q->expr = get_expr(ctx, q); q->opt.vector_size = DEFAULT_WEIGHT_VECTOR_SIZE; q->opt.func = q->weight_set ? section_weight_cb : NULL; q->opt.func_arg = q->weight_set; q->snip_conds = NULL; return q; }
format unification_app_mismatch_exception::pp(formatter const & fmt, options const & opts) const { unsigned indent = get_pp_indent(opts); auto const & ctx = get_context(); expr const & app = get_expr(); auto args_it = get_args().begin(); auto args_end = get_args().end(); auto types_it = get_types().begin(); format app_fmt = fmt(ctx, app, false, opts); format r = format{format(what()), nest(indent, compose(line(), app_fmt))}; format fun_type_fmt = fmt(ctx, *types_it, false, opts); r += compose(line(), format("Function type:")); r += nest(indent, compose(line(), fun_type_fmt)); ++args_it; ++types_it; if (get_args().size() > 2) r += compose(line(), format("Arguments types:")); else r += compose(line(), format("Argument type:")); for (; args_it != args_end; ++args_it, ++types_it) { format arg_fmt = fmt(ctx, *args_it, false, opts); format type_fmt = fmt(ctx, *types_it, false, opts); r += nest(indent, compose(line(), group(format{arg_fmt, space(), colon(), nest(indent, format{line(), type_fmt})}))); } r += pp_elaborator_state(fmt, get_elaborator(), opts); return r; }
int main(int ac, char **av) { char *expr; if ((ac != 4) || (av[1][0] == EOS) || (av[2][0] == EOS ) || (av[3][0] == EOS)) { my_putstr(USAGE_MSG); return (1); } if (my_strlen(av[2]) != 7) { my_putstr(OPERATORS_MSG); return (1); } if (my_strlen(av[1]) != 10) { my_putstr(PLS_MSG); return (1); } expr = get_expr(my_getnbr(av[3])); if (is_expr_valid(ac, av, expr) != expr) return (1); else //my_putstr(eval_expr(expr, av[2])); return (0); }
void Elaborate_expressions::on_return_statement(Return_value_stmt& s) { s.expr_ = &get_expr(s.expression()); // TODO: Returning a value is initialization. We need to ensure that // that the returned value is moved (consumed) into the declared value. }
void get_expr(const char* filename, vector<vector <float> >& expr, vector<string>& nameset){ ifstream exprfile(filename); if(! exprfile){ cerr << "No such file '" << filename << "'\n"; exit(0); } return get_expr(exprfile, expr, nameset); }
format elaborator_exception::pp(formatter const & fmt, options const & opts) const { unsigned indent = get_pp_indent(opts); format expr_fmt = fmt(get_context(), get_expr(), false, opts); format r; r += format{format(what()), space(), format("at term")}; r += nest(indent, compose(line(), expr_fmt)); r += pp_elaborator_state(fmt, get_elaborator(), opts); return r; }
//if和while的检测 void cmp_inst(char op[],char fuc1[],char fuc2[],char op1[],char op2[],int &i) { char temp[expr_size]; char v1[expr_size],v2[expr_size]; int t1=0,t2=0,reg2=0,reg1=0;//flag用于指示是否为常数 if(get_op(fuc1,v1,reg1)==2) get_expr(reg1,v1); if(get_op(fuc2,v2,reg2)==2) get_expr(reg2,v2);//获取判断语言的两个变量,或者是常数。如果是变量需要加到变量表中。 sscanf(inst[i+1],"%s %s %s",op,fuc1,fuc2); int jump=0; sscanf(fuc2,"[%d]",&jump); bool flag_while=judge_while(i,jump);//判断是否可能为while循环 if(strcmp(op,"blbc")==0)//正常的等于 { if(flag_while) sprintf(temp,"while(%s%s%s) \n",v1,op1,v2); else sprintf(temp,"if(%s%s%s) \n",v1,op1,v2); } else if(strcmp(op,"blbs")==0)//等于的相反情况 { if(flag_while) sprintf(temp,"while(%s%s%s) \n",v1,op2,v2); else sprintf(temp,"if(%s%s%s) \n",v1,op2,v2); } else { fprintf(fw,"cmpeq is wrong struct! \n"); } extra[jump]++;//跳转的目的指令需要补全 } i++;//增加一条指令 add_tab();//添加tab键 fprintf(fw,"%s",temp);//放入缓存区 add_tab(); fprintf(fw,"{\n"); num_big++;//{的个数增加一个 }
/* * matching_tlvar-- * * RETURNS: var node in a target list which is var_equal to 'var', * if one exists. * REQUIRES: "test" operates on lispval unions, * */ Expr * matching_tlvar(Var *var, List *targetlist) { TargetEntry *tlentry; tlentry = tlistentry_member(var,targetlist); if (tlentry) return((Expr*)get_expr (tlentry) ); return((Expr*) NULL); }
node_t *build_parse_tree(const char *input, GError **err) { token_stack_t *stack; node_t *tree; stack = lexer(input); tree = get_expr(stack, err); free_token_stack(stack); return tree; }
/* * tlistentry-member-- * * RETURNS: the leftmost member of sequence "targetlist" that satisfies * the predicate "var_equal" * MODIFIES: nothing * REQUIRES: test = function which can operate on a lispval union * var = valid var-node * targetlist = valid sequence */ TargetEntry * tlistentry_member(Var *var, List *targetlist) { if (var) { List *temp = NIL; foreach (temp,targetlist) { if (var_equal(var, get_expr(lfirst(temp)))) return((TargetEntry*)lfirst(temp)); } } return (NULL); }
static struct predicate * scan_rest (struct predicate **input, struct predicate *head, short int prev_prec) { struct predicate *tree; /* The new tree we are building. */ if ((*input == NULL) || ((*input)->p_type == CLOSE_PAREN)) return (NULL); tree = head; while ((*input != NULL) && ((int) (*input)->p_prec > (int) prev_prec)) { switch ((*input)->p_type) { case NO_TYPE: case PRIMARY_TYPE: case UNI_OP: case OPEN_PAREN: /* I'm not sure how we get here, so it is not obvious what * sort of mistakes might give rise to this condition. */ error (EXIT_FAILURE, 0, _("invalid expression")); break; case BI_OP: { struct predicate *prev = (*input); (*input)->pred_left = tree; tree = *input; *input = (*input)->pred_next; tree->pred_right = get_expr (input, tree->p_prec, prev); break; } case CLOSE_PAREN: return tree; default: error (EXIT_FAILURE, 0, _("oops -- invalid expression type (%d)!"), (int)(*input)->p_type); break; } } return tree; }
int main(int ac, char **av) { char *expr; unsigned int size; char *final; if (ac != 4) { my_putstr("Usage : "); my_putstr(av[0]); my_putstr(" base ops\"()+-*/%\" exp_len\n"); exit(1); } check_base(av[1]); check_ops(av[2]); size = my_atoi(av[3]); expr = get_expr(size); final = eval_expr(av[1], av[2], expr, size);
void translate_fuc(int &now)//函数调用解析 { char op[expr_size],fuc1[expr_size],fuc2[expr_size]; int i=0,end=0; for(i=now+1;i<num_inst;i++)//找到参数定义结束后的call指令 { sscanf(inst[i],"%s %s %s",op,fuc1,fuc2); if(strcmp(op,"call")==0) { end=i; int reg=0; sscanf(fuc1,"[%d]",®); add_tab(); fprintf(fw,"fuction_%d(",reg); break; } else if(strcmp(op,"load")==0) { int reg=0; sscanf(fuc1,"(%d)",®); transform_load(reg,i);//load指令的转化,转化为一个简单的表达式,用于之后的使用 } } char v1[expr_size]; int reg=0; int t=0; for(i=now;i<end;i++)//添加调用参数 { sscanf(inst[i],"%s %s %s",op,fuc1,fuc2); if(strcmp(op,"param")==0) { t=get_op(fuc1,v1,reg); if(t==2) get_expr(reg,v1); fprintf(fw,"%s",v1); if(i==end-1) fprintf(fw,");\n"); else fprintf(fw,","); } } now=end; }
void map_proc::reconstruct(app* a) { m_args.reset(); bool is_new = false; for (unsigned i = 0; i < a->get_num_args(); ++i) { expr* e1 = a->get_arg(i); expr* e2 = get_expr(e1); m_args.push_back(e2); if (e1 != e2) { is_new = true; } } if (is_new) { expr* b = m.mk_app(a->get_decl(), m_args.size(), m_args.c_ptr()); m_map.insert(a, b, 0); } else { m_map.insert(a, a, 0); } }
static node_t *get_parentised_expr(token_stack_t *stack, GError **err) { token_t *token; GError *tmp_err = NULL; node_t *node; // '(' token = token_pop(stack); if (!token || token->type != TOK_LPAREN) { set_error(err, "Expected '('", token); g_free(token); return NULL; } // expr node = get_expr(stack, &tmp_err); if (tmp_err) { g_propagate_error(err, tmp_err); free_parsetree(node); return NULL; } if (!node) { // Re-use the RPAREN token for this error message. token->position++; set_error(err, "Expected expression", token); } g_free(token); // ')' token = token_pop(stack); if (!token || token->type != TOK_RPAREN) { free_parsetree(node); set_error(err, "Expected ')'", token); g_free(token); return NULL; } g_free(token); return node; }
format unification_type_mismatch_exception::pp(formatter const & fmt, options const & opts) const { unsigned indent = get_pp_indent(opts); auto const & ctx = get_context(); expr const & e = get_expr(); expr const & p = get_processed_expr(); expr const & exp = get_expected_type(); expr const & given = get_given_type(); format r = format{format(what()), nest(indent, compose(line(), fmt(ctx, e, false, opts)))}; if (p != e) { r += compose(line(), format("Term after elaboration:")); r += nest(indent, compose(line(), fmt(ctx, p, false, opts))); } r += compose(line(), format("Expected type:")); r += nest(indent, compose(line(), fmt(ctx, exp, false, opts))); if (given) { r += compose(line(), format("Got:")); r += nest(indent, compose(line(), fmt(ctx, given, false, opts))); } r += pp_elaborator_state(fmt, get_elaborator(), opts); return r; }
bool substitution::occurs_expr_core(name const & m, expr const & e, name_set & visited) const { bool found = false; for_each(e, [&](expr const & e, unsigned) { if (found || !has_expr_metavar(e)) return false; if (is_metavar(e)) { name const & n = mlocal_name(e); if (n == m) found = true; auto s = get_expr(e); if (!s || visited.contains(n)) return false; // do not visit type visited.insert(n); if (s && occurs_expr_core(m, *s, visited)) found = true; return false; // do not visit type } if (is_local(e)) return false; // do not visit type return true; }); return found; }
/* * tlist-member-- * Determines whether a var node is already contained within a * target list. * * 'var' is the var node * 'tlist' is the target list * 'dots' is t if we must match dotfields to determine uniqueness * * Returns the resdom entry of the matching var node. * */ Resdom * tlist_member(Var *var, List *tlist) { List *i = NIL; TargetEntry *temp_tle = (TargetEntry *)NULL; TargetEntry *tl_elt = (TargetEntry *)NULL; if (var) { foreach (i,tlist) { temp_tle = (TargetEntry *)lfirst(i); if (var_equal(var, get_expr(temp_tle))) { tl_elt = temp_tle; break; } } if (tl_elt != NULL) return(tl_elt->resdom); else return((Resdom*)NULL); }
/* ** Main function. Given by the subject. ** When you use this program to compute very large numbers, use the -p ** parramater to enable progress bar display. ** Ex : ./calc "01" "()+-x/%" 999999999 -p */ int main(int ac, char **av) { unsigned int size; char *expr; int p; p = 0; if (ac != 4 && ac != 5) { my_putstr("Usage : "); my_putstr(av[0]); my_putstr(" base (\"0123456789\") ops (\"()+-*/%\") exp_len\n"); exit(1); } else if (ac == 5 && strcmp(av[4], "-p") == 0) p = 1; check_base(av[1]); check_ops(av[2]); size = my_atoi(av[3]); expr = get_expr(size); eval_expr(av[1], av[2], expr, size, p); free(expr); exit(0); }
int main(int ac, char **av) { char *expr; unsigned int size; if (ac != 4) { my_putstr("Usage : "); my_putstr(av[0]); my_putstr(" base ops\"()+-*/%\" exp_len\n"); return (0); } if (check_base(av[1]) == 1) return (0); if (check_ops(av[2]) == 1) return (0); size = my_atoi(av[3]); expr = get_expr(size); if (expr == NULL) return (0); my_putstr(eval_expr(av[1], av[2], expr, size)); my_putstr("\n"); return (0); }
RowSetPtr Executor::executeResultPlan(const Planner::Result* result_plan, const bool hoist_literals, const ExecutorDeviceType device_type, const ExecutorOptLevel opt_level, const Catalog_Namespace::Catalog& cat, size_t& max_groups_buffer_entry_guess, int32_t* error_code, const Planner::Sort* sort_plan, const bool allow_multifrag, const bool just_explain, const bool allow_loop_joins) { const auto agg_plan = dynamic_cast<const Planner::AggPlan*>(result_plan->get_child_plan()); if (!agg_plan) { // TODO(alex) throw std::runtime_error("Query not supported yet, child plan needs to be an aggregate plan."); } row_set_mem_owner_ = std::make_shared<RowSetMemoryOwner>(); lit_str_dict_proxy_ = nullptr; const auto scan_plan = dynamic_cast<const Planner::Scan*>(agg_plan->get_child_plan()); auto simple_quals = scan_plan ? scan_plan->get_simple_quals() : std::list<std::shared_ptr<Analyzer::Expr>>{}; auto quals = scan_plan ? scan_plan->get_quals() : std::list<std::shared_ptr<Analyzer::Expr>>{}; std::vector<InputDescriptor> input_descs; std::list<std::shared_ptr<const InputColDescriptor>> input_col_descs; collect_input_descs(input_descs, input_col_descs, agg_plan, cat); const auto join_plan = get_join_child(agg_plan); if (join_plan) { collect_quals_from_join(simple_quals, quals, join_plan); } const auto join_quals = join_plan ? join_plan->get_quals() : std::list<std::shared_ptr<Analyzer::Expr>>{}; CHECK(check_plan_sanity(agg_plan)); const auto query_infos = get_table_infos(input_descs, this); const auto ra_exe_unit_in = RelAlgExecutionUnit{input_descs, {}, input_col_descs, simple_quals, quals, JoinType::INVALID, {}, join_quals, {}, agg_plan->get_groupby_list(), get_agg_target_exprs(agg_plan), {}, nullptr, {{}, SortAlgorithm::Default, 0, 0}, 0}; QueryRewriter query_rewriter(ra_exe_unit_in, query_infos, this, result_plan); const auto ra_exe_unit = query_rewriter.rewrite(); auto result = executeWorkUnit(error_code, max_groups_buffer_entry_guess, true, query_infos, ra_exe_unit, {device_type, hoist_literals, opt_level, g_enable_dynamic_watchdog}, {false, allow_multifrag, just_explain, allow_loop_joins, g_enable_watchdog, false, false, g_enable_dynamic_watchdog, g_dynamic_watchdog_time_limit}, cat, row_set_mem_owner_, nullptr, true); auto& rows = boost::get<RowSetPtr>(result); CHECK(rows); if (just_explain) { return std::move(rows); } const int in_col_count{static_cast<int>(agg_plan->get_targetlist().size())}; std::list<std::shared_ptr<const InputColDescriptor>> pseudo_input_col_descs; for (int pseudo_col = 1; pseudo_col <= in_col_count; ++pseudo_col) { pseudo_input_col_descs.push_back(std::make_shared<const InputColDescriptor>(pseudo_col, 0, -1)); } const auto order_entries = sort_plan ? sort_plan->get_order_entries() : std::list<Analyzer::OrderEntry>{}; const RelAlgExecutionUnit res_ra_unit{{}, {}, pseudo_input_col_descs, result_plan->get_constquals(), result_plan->get_quals(), JoinType::INVALID, {}, {}, {}, {nullptr}, get_agg_target_exprs(result_plan), {}, nullptr, { order_entries, SortAlgorithm::Default, 0, 0, }, 0}; if (*error_code) { return std::make_shared<ResultSet>( std::vector<TargetInfo>{}, ExecutorDeviceType::CPU, QueryMemoryDescriptor{}, nullptr, this); } const auto& targets = result_plan->get_targetlist(); CHECK(!targets.empty()); std::vector<AggInfo> agg_infos; for (size_t target_idx = 0; target_idx < targets.size(); ++target_idx) { const auto target_entry = targets[target_idx]; const auto target_type = target_entry->get_expr()->get_type_info().get_type(); agg_infos.emplace_back((target_type == kFLOAT || target_type == kDOUBLE) ? "agg_id_double" : "agg_id", target_entry->get_expr(), 0, target_idx); } std::vector<SQLTypeInfo> target_types; for (auto in_col : agg_plan->get_targetlist()) { target_types.push_back(in_col->get_expr()->get_type_info()); } CHECK(rows); ColumnarResults result_columns(row_set_mem_owner_, *rows, in_col_count, target_types); std::vector<llvm::Value*> col_heads; // Nested query, let the compiler know ResetIsNested reset_is_nested(this); is_nested_ = true; std::vector<Analyzer::Expr*> target_exprs; for (auto target_entry : targets) { target_exprs.emplace_back(target_entry->get_expr()); } const auto row_count = rows->rowCount(); if (!row_count) { return std::make_shared<ResultSet>( std::vector<TargetInfo>{}, ExecutorDeviceType::CPU, QueryMemoryDescriptor{}, nullptr, this); } std::vector<ColWidths> agg_col_widths; for (auto wid : get_col_byte_widths(target_exprs, {})) { agg_col_widths.push_back( {wid, int8_t(compact_byte_width(wid, pick_target_compact_width(res_ra_unit, {}, get_min_byte_width())))}); } QueryMemoryDescriptor query_mem_desc{this, allow_multifrag, GroupByColRangeType::Projection, false, false, -1, 0, {sizeof(int64_t)}, #ifdef ENABLE_KEY_COMPACTION 0, #endif agg_col_widths, {}, row_count, small_groups_buffer_entry_count_, 0, 0, 0, false, GroupByMemSharing::Shared, CountDistinctDescriptors{}, false, true, false, false, {}, {}, false}; auto compilation_result = compileWorkUnit(false, {}, res_ra_unit, {ExecutorDeviceType::CPU, hoist_literals, opt_level, g_enable_dynamic_watchdog}, {false, allow_multifrag, just_explain, allow_loop_joins, g_enable_watchdog, false, false, g_enable_dynamic_watchdog, g_dynamic_watchdog_time_limit}, nullptr, false, row_set_mem_owner_, row_count, small_groups_buffer_entry_count_, get_min_byte_width(), JoinInfo(JoinImplType::Invalid, std::vector<std::shared_ptr<Analyzer::BinOper>>{}, {}, ""), false); auto column_buffers = result_columns.getColumnBuffers(); CHECK_EQ(column_buffers.size(), static_cast<size_t>(in_col_count)); std::vector<int64_t> init_agg_vals(query_mem_desc.agg_col_widths.size()); auto query_exe_context = query_mem_desc.getQueryExecutionContext(res_ra_unit, init_agg_vals, this, ExecutorDeviceType::CPU, 0, {}, {}, {}, row_set_mem_owner_, false, false, nullptr); const auto hoist_buf = serializeLiterals(compilation_result.literal_values, 0); *error_code = 0; std::vector<std::vector<const int8_t*>> multi_frag_col_buffers{column_buffers}; query_exe_context->launchCpuCode(res_ra_unit, compilation_result.native_functions, hoist_literals, hoist_buf, multi_frag_col_buffers, {{static_cast<int64_t>(result_columns.size())}}, {{0}}, 1u, 0, init_agg_vals, error_code, 1, {}); CHECK_GE(*error_code, 0); return query_exe_context->groupBufferToResults(0, target_exprs, false); }
return arg_dominates_expr(s, t, depth) ? GREATER : NOT_GTEQ; else { result r = lex_compare(s, t, depth); if (r == GREATER) { if (dominates_args(s, t, depth)) return GREATER; } else if (r == EQUAL) return EQUAL; return to_app(s.get_expr())->get_num_args() > 1 && arg_dominates_expr(s, t, depth) ? GREATER : NOT_GTEQ; } } } order::result lpo::compare(expr_offset s, expr_offset t, unsigned depth) { TRACE("lpo", tout << "comparing:\n" << mk_pp(s.get_expr(), m_manager) << "\n" << mk_pp(t.get_expr(), m_manager) << "\n";); result r = compare_core(s, t, depth); TRACE("lpo", tout << "result of comparing:\n" << mk_pp(s.get_expr(), m_manager) << "\n" << mk_pp(t.get_expr(), m_manager) << "\nresult: " << r << "\n";); return r; } bool lpo::greater(expr_offset const & t1, expr_offset const & t2, substitution * s) { m_subst = s; return greater(t1, t2, static_cast<unsigned>(0)); } order::result lpo::compare(expr_offset const & t1, expr_offset const & t2, substitution * s) { m_subst = s; result r = compare(t1, t2, static_cast<unsigned>(0)); if (r != NOT_GTEQ) return r;
exprt dereference_rec( const exprt &src, const ssa_value_domaint &ssa_value_domain, const std::string &nondet_prefix, const namespacet &ns) { if(src.id()==ID_dereference) { const exprt &pointer=dereference_rec( to_dereference_expr(src).pointer(), ssa_value_domain, nondet_prefix, ns); const typet &pointed_type=ns.follow(pointer.type().subtype()); const ssa_value_domaint::valuest values=ssa_value_domain(pointer, ns); exprt result; if(values.value_set.empty()) { result=pointed_object(pointer, ns); } else { auto it=values.value_set.begin(); if(values.null || values.unknown || (values.value_set.size()>1 && it->type().get_bool("#dynamic"))) { std::string dyn_type_name=pointed_type.id_string(); if(pointed_type.id()==ID_struct) dyn_type_name+="_"+id2string(to_struct_type(pointed_type).get_tag()); irep_idt identifier="ssa::"+dyn_type_name+"_obj$unknown"; result=symbol_exprt(identifier, src.type()); result.set("#unknown_obj", true); } else { result=ssa_alias_value(src, (it++)->get_expr(), ns); result.set("#heap_access", result.type().get_bool("#dynamic")); } for(; it!=values.value_set.end(); ++it) { exprt guard=ssa_alias_guard(src, it->get_expr(), ns); exprt value=ssa_alias_value(src, it->get_expr(), ns); result=if_exprt(guard, value, result); result.set( "#heap_access", result.get_bool("#heap_access") || value.type().get_bool("#dynamic")); } } return result; } else if(src.id()==ID_member) { member_exprt tmp=to_member_expr(src); tmp.struct_op()= dereference_rec(tmp.struct_op(), ssa_value_domain, nondet_prefix, ns); tmp.set("#heap_access", tmp.struct_op().get_bool("#heap_access")); #ifdef DEBUG std::cout << "dereference_rec tmp: " << from_expr(ns, "", tmp) << '\n'; #endif if(tmp.struct_op().is_nil()) return nil_exprt(); return lift_if(tmp); } else if(src.id()==ID_address_of) { address_of_exprt tmp=to_address_of_expr(src); tmp.object()= dereference_rec(tmp.object(), ssa_value_domain, nondet_prefix, ns); tmp.set("#heap_access", tmp.object().get_bool("#heap_access")); if(tmp.object().is_nil()) return nil_exprt(); return lift_if(tmp); } else { exprt tmp=src; Forall_operands(it, tmp) { *it=dereference_rec(*it, ssa_value_domain, nondet_prefix, ns); if(it->get_bool("#heap_access")) tmp.set("#heap_access", true); } return tmp; }
void map_proc::visit(quantifier* e) { expr_ref q(m); q = m.update_quantifier(e, get_expr(e->get_expr())); m_map.insert(e, q, 0); }
void apply(expr_ref& e) { for_each_expr(*this, e); e = get_expr(e); }
void operator()(app* a) { if (!get_expr(a)) { reconstruct(a); } }
inline static grn_cell * get_token(grn_ctx *ctx, grn_query *q) { grn_cell *token = NIL; grn_operator op = q->default_op; { int weight = DEFAULT_WEIGHT, prefixp = 0, mode = -1, option = 0; skip_space(ctx, q); if (q->cur_expr >= q->max_exprs || q->cur_cell >= q->max_cells || q->cur >= q->str_end) { return NIL; } switch (*q->cur) { case '\0' : return NIL; case GRN_QUERY_PARENR : q->cur++; return NIL; case GRN_QUERY_QUOTEL : q->cur++; if ((token = get_phrase(ctx, q)) == NULL) { return NIL; } break; case GRN_QUERY_PREFIX : q->cur++; token = get_op(q, op, weight); break; case GRN_QUERY_AND : q->cur++; token = op_new(q, GRN_OP_AND, weight, mode, option); break; case GRN_QUERY_BUT : q->cur++; token = op_new(q, GRN_OP_BUT, weight, mode, option); break; case GRN_QUERY_ADJ_INC : q->cur++; if (weight < 127) { weight++; } token = op_new(q, GRN_OP_ADJUST, weight, mode, option); break; case GRN_QUERY_ADJ_DEC : q->cur++; if (weight > -128) { weight--; } token = op_new(q, GRN_OP_ADJUST, weight, mode, option); break; case GRN_QUERY_ADJ_NEG : q->cur++; token = op_new(q, GRN_OP_ADJUST, -1, mode, option); break; case GRN_QUERY_PARENL : q->cur++; token = get_expr(ctx, q); break; default : if ((token = get_word(ctx, q, &prefixp)) && token->u.b.value[0] == 'O' && token->u.b.value[1] == 'R' && token->u.b.size == 2) { cell_del(q); q->cur_expr--; token = op_new(q, GRN_OP_OR, weight, mode, option); } break; } } return cons(q, token, NIL); }
struct predicate* build_expression_tree (int argc, char *argv[], int end_of_leading_options) { const struct parser_table *parse_entry; /* Pointer to the parsing table entry for this expression. */ char *predicate_name; /* Name of predicate being parsed. */ struct predicate *cur_pred; const struct parser_table *entry_close, *entry_print, *entry_open; int i, oldi; predicates = NULL; /* Find where in ARGV the predicates begin by skipping the list of * start points. As a side effect, also figure out which is the * first and last start point. */ start_points = argv + end_of_leading_options; for (i = end_of_leading_options; i < argc && !looks_like_expression(argv[i], true); i++) { ++num_start_points; } /* Enclose the expression in `( ... )' so a default -print will apply to the whole expression. */ entry_open = find_parser ("("); entry_close = find_parser (")"); entry_print = find_parser ("print"); assert (entry_open != NULL); assert (entry_close != NULL); assert (entry_print != NULL); parse_openparen (entry_open, argv, &argc); last_pred->p_name = "("; predicates->artificial = true; parse_begin_user_args (argv, argc, last_pred, predicates); pred_sanity_check (last_pred); /* Build the input order list. */ while (i < argc ) { state.already_issued_stat_error_msg = false; if (!looks_like_expression (argv[i], false)) { error (0, 0, _("paths must precede expression: %s"), argv[i]); usage (stderr, 1, NULL); } predicate_name = argv[i]; parse_entry = find_parser (predicate_name); if (parse_entry == NULL) { /* Command line option not recognized */ error (EXIT_FAILURE, 0, _("unknown predicate `%s'"), predicate_name); } /* We have recognised a test of the form -foo. Eat that, * unless it is a predicate like -newerXY. */ if (parse_entry->type != ARG_SPECIAL_PARSE) { i++; } oldi = i; if (!(*(parse_entry->parser_func)) (parse_entry, argv, &i)) { if (argv[i]) { if ( (ARG_SPECIAL_PARSE == parse_entry->type) && (i == oldi) ) { /* The special parse function spat out the * predicate. It must be invalid, or not tasty. */ error (EXIT_FAILURE, 0, _("invalid predicate `%s'"), predicate_name); } else { error (EXIT_FAILURE, 0, _("invalid argument `%s' to `%s'"), argv[i], predicate_name); } } else { /* Command line option requires an argument */ error (EXIT_FAILURE, 0, _("missing argument to `%s'"), predicate_name); } } else { last_pred->p_name = predicate_name; /* If the parser consumed an argument, save it. */ if (i != oldi) last_pred->arg_text = argv[oldi]; else last_pred->arg_text = NULL; } pred_sanity_check(last_pred); pred_sanity_check(predicates); /* XXX: expensive */ } parse_end_user_args (argv, argc, last_pred, predicates); if (predicates->pred_next == NULL) { /* No predicates that do something other than set a global variable were given; remove the unneeded initial `(' and add `-print'. */ cur_pred = predicates; predicates = last_pred = predicates->pred_next; free (cur_pred); parse_print (entry_print, argv, &argc); last_pred->p_name = "-print"; pred_sanity_check(last_pred); pred_sanity_check(predicates); /* XXX: expensive */ } else if (!default_prints (predicates->pred_next)) { /* One or more predicates that produce output were given; remove the unneeded initial `('. */ cur_pred = predicates; predicates = predicates->pred_next; pred_sanity_check (predicates); /* XXX: expensive */ free (cur_pred); } else { /* `( user-supplied-expression ) -print'. */ parse_closeparen (entry_close, argv, &argc); last_pred->p_name = ")"; last_pred->artificial = true; pred_sanity_check (last_pred); parse_print (entry_print, argv, &argc); last_pred->p_name = "-print"; last_pred->artificial = true; pred_sanity_check (last_pred); pred_sanity_check (predicates); /* XXX: expensive */ } if (options.debug_options & (DebugExpressionTree|DebugTreeOpt)) { fprintf (stderr, "Predicate List:\n"); print_list (stderr, predicates); } /* do a sanity check */ check_option_combinations (predicates); pred_sanity_check (predicates); /* Done parsing the predicates. Build the evaluation tree. */ cur_pred = predicates; eval_tree = get_expr (&cur_pred, NO_PREC, NULL); calculate_derived_rates (eval_tree); /* Check if we have any left-over predicates (this fixes * Debian bug #185202). */ if (cur_pred != NULL) { /* cur_pred->p_name is often NULL here */ if (pred_is (cur_pred, pred_closeparen)) { /* e.g. "find \( -true \) \)" */ error (EXIT_FAILURE, 0, _("you have too many ')'")); } else { if (cur_pred->p_name) error (EXIT_FAILURE, 0, _("unexpected extra predicate '%s'"), cur_pred->p_name); else error (EXIT_FAILURE, 0, _("unexpected extra predicate")); } } if (options.debug_options & (DebugExpressionTree|DebugTreeOpt)) { fprintf (stderr, "Eval Tree:\n"); print_tree (stderr, eval_tree, 0); } estimate_costs (eval_tree); /* Rearrange the eval tree in optimal-predicate order. */ opt_expr (&eval_tree); /* Check that the tree is in normalised order (opt_expr does this) */ check_normalization (eval_tree, true); do_arm_swaps (eval_tree); /* Check that the tree is still in normalised order */ check_normalization (eval_tree, true); if (options.debug_options & (DebugExpressionTree|DebugTreeOpt)) { fprintf (stderr, "Optimized Eval Tree:\n"); print_tree (stderr, eval_tree, 0); fprintf (stderr, "Optimized command line:\n"); print_optlist (stderr, eval_tree); fprintf (stderr, "\n"); } return eval_tree; }
static struct predicate * get_expr (struct predicate **input, short int prev_prec, const struct predicate* prev_pred) { struct predicate *next = NULL; struct predicate *this_pred = (*input); if (*input == NULL) error (EXIT_FAILURE, 0, _("invalid expression")); switch ((*input)->p_type) { case NO_TYPE: error (EXIT_FAILURE, 0, _("invalid expression")); break; case BI_OP: /* e.g. "find . -a" */ error (EXIT_FAILURE, 0, _("invalid expression; you have used a binary operator '%s' with nothing before it."), this_pred->p_name); break; case CLOSE_PAREN: if ((UNI_OP == prev_pred->p_type || BI_OP == prev_pred->p_type) && !this_pred->artificial) { /* e.g. "find \( -not \)" or "find \( -true -a \" */ error (EXIT_FAILURE, 0, _("expected an expression between '%s' and ')'"), prev_pred->p_name); } else if ( (*input)->artificial ) { /* We have reached the end of the user-supplied predicates * unexpectedly. */ /* e.g. "find . -true -a" */ error (EXIT_FAILURE, 0, _("expected an expression after '%s'"), prev_pred->p_name); } else { error (EXIT_FAILURE, 0, _("invalid expression; you have too many ')'")); } break; case PRIMARY_TYPE: next = *input; *input = (*input)->pred_next; break; case UNI_OP: next = *input; *input = (*input)->pred_next; next->pred_right = get_expr (input, NEGATE_PREC, next); break; case OPEN_PAREN: if ( (NULL == (*input)->pred_next) || (*input)->pred_next->artificial ) { /* user typed something like "find . (", and so the ) we are * looking at is from the artificial "( ) -print" that we * add. */ error (EXIT_FAILURE, 0, _("invalid expression; expected to find a ')' but didn't see one. Perhaps you need an extra predicate after '%s'"), this_pred->p_name); } prev_pred = (*input); *input = (*input)->pred_next; if ( (*input)->p_type == CLOSE_PAREN ) { error (EXIT_FAILURE, 0, _("invalid expression; empty parentheses are not allowed.")); } next = get_expr (input, NO_PREC, prev_pred); if ((*input == NULL) || ((*input)->p_type != CLOSE_PAREN)) error (EXIT_FAILURE, 0, _("invalid expression; I was expecting to find a ')' somewhere but did not see one.")); *input = (*input)->pred_next; /* move over close */ break; default: error (EXIT_FAILURE, 0, _("oops -- invalid expression type!")); break; } /* We now have the first expression and are positioned to check out the next operator. If NULL, all done. Otherwise, if PREV_PREC < the current node precedence, we must continue; the expression we just nabbed is more tightly bound to the following expression than to the previous one. */ if (*input == NULL) return (next); if ((int) (*input)->p_prec > (int) prev_prec) { next = scan_rest (input, next, prev_prec); if (next == NULL) error (EXIT_FAILURE, 0, _("invalid expression")); } return (next); }