Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiegley committed Jun 13, 2010
2 parents 40f5532 + cf0147f commit 0c699e4
Show file tree
Hide file tree
Showing 36 changed files with 1,090 additions and 970 deletions.
2 changes: 1 addition & 1 deletion acprep
Expand Up @@ -1679,7 +1679,7 @@ your options. Here are some real-world examples:
./acprep
./acprep opt -- make -j3
./acprep -- --enable-doxygen"""
./acprep --enable-doxygen"""
sys.exit(0)

PrepareBuild().run()
79 changes: 52 additions & 27 deletions src/account.cc
Expand Up @@ -34,7 +34,6 @@
#include "account.h"
#include "post.h"
#include "xact.h"
#include "interactive.h"

namespace ledger {

Expand Down Expand Up @@ -122,6 +121,20 @@ account_t * account_t::find_account_re(const string& regexp)
return find_account_re_(this, mask_t(regexp));
}

void account_t::add_post(post_t * post)
{
posts.push_back(post);

// Adding a new post changes the possible totals that may have been
// computed before.
if (xdata_) {
xdata_->self_details.gathered = false;
xdata_->self_details.calculated = false;
xdata_->family_details.gathered = false;
xdata_->family_details.calculated = false;
}
}

bool account_t::remove_post(post_t * post)
{
assert(! posts.empty());
Expand Down Expand Up @@ -175,15 +188,31 @@ std::ostream& operator<<(std::ostream& out, const account_t& account)
}

namespace {
value_t get_partial_name(call_scope_t& scope)
value_t get_partial_name(call_scope_t& args)
{
in_context_t<account_t> env(scope, "&b");
return string_value(env->partial_name(env.has(0) ?
env.get<bool>(0) : false));
}

value_t get_account(account_t& account) { // this gets the name
return string_value(account.fullname());
return string_value(args.context<account_t>()
.partial_name(args.has<bool>(0) &&
args.get<bool>(0)));
}

value_t get_account(call_scope_t& args) { // this gets the name
account_t& account(args.context<account_t>());
if (args.has<string>(0)) {
account_t * acct = account.parent;
for (; acct && acct->parent; acct = acct->parent) ;
if (args[0].is_string())
return scope_value(acct->find_account(args.get<string>(0), false));
else if (args[0].is_mask())
return scope_value(acct->find_account_re(args.get<mask_t>(0).str()));
else
return NULL_VALUE;
}
else if (args.type_context() == value_t::SCOPE) {
return scope_value(&account);
}
else {
return string_value(account.fullname());
}
}

value_t get_account_base(account_t& account) {
Expand Down Expand Up @@ -251,39 +280,35 @@ namespace {
}

template <value_t (*Func)(account_t&)>
value_t get_wrapper(call_scope_t& scope) {
return (*Func)(find_scope<account_t>(scope));
value_t get_wrapper(call_scope_t& args) {
return (*Func)(args.context<account_t>());
}

value_t get_parent(account_t& account) {
return value_t(static_cast<scope_t *>(account.parent));
return scope_value(account.parent);
}

value_t fn_any(call_scope_t& scope)
value_t fn_any(call_scope_t& args)
{
interactive_t args(scope, "X&X");

account_t& account(find_scope<account_t>(scope));
expr_t& expr(args.get<expr_t&>(0));
account_t& account(args.context<account_t>());
expr_t::ptr_op_t expr(args.get<expr_t::ptr_op_t>(0));

foreach (post_t * p, account.posts) {
bind_scope_t bound_scope(scope, *p);
if (expr.calc(bound_scope).to_boolean())
bind_scope_t bound_scope(args, *p);
if (expr->calc(bound_scope).to_boolean())
return true;
}
return false;
}

value_t fn_all(call_scope_t& scope)
value_t fn_all(call_scope_t& args)
{
interactive_t args(scope, "X&X");

account_t& account(find_scope<account_t>(scope));
expr_t& expr(args.get<expr_t&>(0));
account_t& account(args.context<account_t>());
expr_t::ptr_op_t expr(args.get<expr_t::ptr_op_t>(0));

foreach (post_t * p, account.posts) {
bind_scope_t bound_scope(scope, *p);
if (! expr.calc(bound_scope).to_boolean())
bind_scope_t bound_scope(args, *p);
if (! expr->calc(bound_scope).to_boolean())
return false;
}
return true;
Expand All @@ -301,7 +326,7 @@ expr_t::ptr_op_t account_t::lookup(const symbol_t::kind_t kind,
if (name[1] == '\0' || name == "amount")
return WRAP_FUNCTOR(get_wrapper<&get_amount>);
else if (name == "account")
return WRAP_FUNCTOR(get_wrapper<&get_account>);
return WRAP_FUNCTOR(&get_account);
else if (name == "account_base")
return WRAP_FUNCTOR(get_wrapper<&get_account_base>);
else if (name == "addr")
Expand Down
4 changes: 1 addition & 3 deletions src/account.h
Expand Up @@ -119,9 +119,7 @@ class account_t : public supports_flags<>, public scope_t
(accounts.end(), bind(&accounts_map::value_type::second, _1));
}

void add_post(post_t * post) {
posts.push_back(post);
}
void add_post(post_t * post);
bool remove_post(post_t * post);

posts_list::iterator posts_begin() {
Expand Down
8 changes: 3 additions & 5 deletions src/convert.cc
Expand Up @@ -34,7 +34,6 @@
#include "convert.h"
#include "csv.h"
#include "scope.h"
#include "interactive.h"
#include "iterators.h"
#include "report.h"
#include "xact.h"
Expand All @@ -43,11 +42,10 @@

namespace ledger {

value_t convert_command(call_scope_t& scope)
value_t convert_command(call_scope_t& args)
{
interactive_t args(scope, "s");
report_t& report(find_scope<report_t>(scope));
journal_t& journal(*report.session.journal.get());
report_t& report(args.context<report_t>());
journal_t& journal(*report.session.journal.get());

string bucket_name;
if (report.HANDLED(account_))
Expand Down
20 changes: 19 additions & 1 deletion src/expr.h
Expand Up @@ -58,7 +58,6 @@ class expr_t : public expr_base_t<value_t>
class op_t;
typedef intrusive_ptr<op_t> ptr_op_t;
typedef intrusive_ptr<const op_t> const_ptr_op_t;

protected:
ptr_op_t ptr;

Expand Down Expand Up @@ -142,6 +141,25 @@ class expr_t : public expr_base_t<value_t>
#endif // HAVE_BOOST_SERIALIZATION
};

/**
* Dealing with expr pointers tucked into value objects.
*/
inline bool is_expr(const value_t& val) {
return val.is_any() && val.as_any().type() == typeid(expr_t::ptr_op_t);
}
inline expr_t::ptr_op_t as_expr(const value_t& val) {
VERIFY(val.is_any());
return val.as_any<expr_t::ptr_op_t>();
}
inline void set_expr(value_t& val, expr_t::ptr_op_t op) {
val.set_any(op);
}
inline value_t expr_value(expr_t::ptr_op_t op) {
value_t temp;
temp.set_any(op);
return temp;
}

} // namespace ledger

#endif // _EXPR_H
5 changes: 5 additions & 0 deletions src/format.cc
Expand Up @@ -362,8 +362,13 @@ string format_t::real_calc(scope_t& scope)
out << value.to_string();
}
catch (const calc_error&) {
string current_context = error_context();

add_error_context(_("While calculating format expression:"));
add_error_context(expr.context_to_str());

if (! current_context.empty())
add_error_context(current_context);
throw;
}
break;
Expand Down
1 change: 0 additions & 1 deletion src/global.h
Expand Up @@ -38,7 +38,6 @@
#ifndef _GLOBAL_H
#define _GLOBAL_H

#include "interactive.h"
#include "option.h"
#include "report.h"

Expand Down

0 comments on commit 0c699e4

Please sign in to comment.