summaryrefslogtreecommitdiff
path: root/tmpl
diff options
context:
space:
mode:
authorJosh Blum2013-07-27 19:20:35 -0700
committerJosh Blum2013-07-27 19:20:35 -0700
commita3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42 (patch)
tree533568f9a549aeae63930b9767a582b4975629f2 /tmpl
parent9ee559e8be429e6ca18858de668289cf66e19a0f (diff)
downloadsandhi-a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42.tar.gz
sandhi-a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42.tar.bz2
sandhi-a3b5a07cf7c64f1a038839d3ef2f7b1d9fbf6c42.zip
gras: added arg check with nice warning to callable and factory
Diffstat (limited to 'tmpl')
-rw-r--r--tmpl/callable_detail.tmpl.hpp5
-rw-r--r--tmpl/factory_detail.tmpl.hpp3
2 files changed, 5 insertions, 3 deletions
diff --git a/tmpl/callable_detail.tmpl.hpp b/tmpl/callable_detail.tmpl.hpp
index 65750e7..656b695 100644
--- a/tmpl/callable_detail.tmpl.hpp
+++ b/tmpl/callable_detail.tmpl.hpp
@@ -16,6 +16,7 @@ struct GRAS_API CallableRegistryEntry
CallableRegistryEntry(void);
virtual ~CallableRegistryEntry(void);
virtual PMCC call(const PMCC &args) = 0;
+ void arg_check(const PMCList &args, const size_t nargs);
};
#for $NARGS in range($MAX_ARGS)
@@ -31,7 +32,7 @@ struct CallableRegistryEntryImpl$(NARGS) : CallableRegistryEntry
PMCC call(const PMCC &args)
{
const PMCList &a = args.as<PMCList>();
- if (a.size() < $NARGS) throw a;
+ this->arg_check(a, $NARGS);
return PMC_M((_obj->*_fcn)($expand('a[%d].safe_as<A%d>()', $NARGS)));
}
ClassType *_obj; Fcn _fcn;
@@ -54,7 +55,7 @@ struct CallableRegistryEntryImplVoid$(NARGS) : CallableRegistryEntry
PMCC call(const PMCC &args)
{
const PMCList &a = args.as<PMCList>();
- if (a.size() < $NARGS) throw a;
+ this->arg_check(a, $NARGS);
(_obj->*_fcn)($expand('a[%d].safe_as<A%d>()', $NARGS)); return PMCC();
}
ClassType *_obj; Fcn _fcn;
diff --git a/tmpl/factory_detail.tmpl.hpp b/tmpl/factory_detail.tmpl.hpp
index 87a0756..ea30235 100644
--- a/tmpl/factory_detail.tmpl.hpp
+++ b/tmpl/factory_detail.tmpl.hpp
@@ -16,6 +16,7 @@ struct GRAS_API FactoryRegistryEntry
FactoryRegistryEntry(void);
virtual ~FactoryRegistryEntry(void);
virtual Element *make(const PMCC &args) = 0;
+ void arg_check(const PMCList &args, const size_t nargs);
};
#for $NARGS in range($MAX_ARGS)
@@ -30,7 +31,7 @@ struct FactoryRegistryEntryImpl$(NARGS) : FactoryRegistryEntry
Element *make(const PMCC &args)
{
const PMCList &a = args.as<PMCList>();
- if (a.size() < $NARGS) throw a;
+ this->arg_check(a, $NARGS);
return _fcn($expand('a[%d].safe_as<A%d>()', $NARGS));
}
Fcn _fcn;