Permalink
Browse files

- Clean up

  • Loading branch information...
1 parent 6232955 commit da576ef22620332a1d331fd645f97e321f5ef381 @felipensp felipensp committed Feb 28, 2012
Showing with 27 additions and 27 deletions.
  1. +7 −2 compiler/clever.h
  2. +20 −25 compiler/typechecker.cc
View
@@ -57,8 +57,13 @@ extern jmp_buf fatal_error;
*/
#define CLEVER_ADDREF(x) (x)->addRef()
#define CLEVER_DELREF(x) (x)->delRef()
-#define CLEVER_SAFE_ADDREF(x) if (x) { (x)->addRef(); }
-#define CLEVER_SAFE_DELREF(x) if (x) { (x)->delRef(); }
+#define CLEVER_SAFE_ADDREF(x) do { if (x) { (x)->addRef(); } } while (0);
+#define CLEVER_SAFE_DELREF(x) do { if (x) { (x)->delRef(); } } while (0);
+
+/**
+ * Macro to delete pointer after checking for not null
+ */
+#define CLEVER_SAFE_DELETE(x) do { if (x) { delete x; } } while (0);
/**
* Macro to access the an specific DataValue
View
@@ -219,6 +219,8 @@ static void _check_function_arg_types(const Function* func,
if (t1 != t2) {
if (!_check_compatible_types(t1, t2)) {
+ CLEVER_SAFE_DELETE(arg_values);
+
Compiler::errorf(loc,
"Wrong param type #%N: expected `%S', but `%S' supplied",
i, t1->getName(), t2->getName());
@@ -779,37 +781,34 @@ AST_VISITOR(TypeChecker, AssignExpr) {
expr->setValue(lhs);
}
-/**
- * Function call visitor
- */
-
-static inline std::string _find_fcall_rname(const Type* c) {
- if( c == CLEVER_INT) return "i";
- if( c == CLEVER_DOUBLE) return "d";
- if( c == CLEVER_STR) return "s";
- if( c == CLEVER_BOOL) return "b";
- if( c == CLEVER_BYTE) return "c";
- if( c == CLEVER_VOID) return "v";
- if( c == NULL) return "v";
+static inline const char* _find_fcall_rname(const Type* c) {
+ if (c == CLEVER_INT) return "i";
+ if (c == CLEVER_DOUBLE) return "d";
+ if (c == CLEVER_STR) return "s";
+ if (c == CLEVER_BOOL) return "b";
+ if (c == CLEVER_BYTE) return "c";
+ if (c == CLEVER_VOID) return "v";
+ if (c == NULL) return "v";
return "p";
}
+/**
+ * Function call visitor
+ */
AST_VISITOR(TypeChecker, FunctionCall) {
const CString* const name = expr->getFuncName();
clever_assert_not_null(name);
Value* fvalue = m_scope->getValue(name);
-
if (UNEXPECTED(fvalue == NULL || !fvalue->isCallable())) {
Compiler::errorf(expr->getLocation(), "Function `%S' does not exists!",
name);
}
const Function* func = static_cast<CallableValue*>(fvalue)->getFunction();
-
int num_args = expr->getArgs() ? int(expr->getArgs()->getNodes().size()) : 0;
clever_assert_not_null(func);
@@ -818,26 +817,22 @@ AST_VISITOR(TypeChecker, FunctionCall) {
Value* result = new Value;
- if(func->isExternal()){
+ if (func->isExternal()) {
ArgumentList* args = expr->getArgs();
- std::string fname = name->c_str();
- std::string libname = func->getLibName();
- std::string rt = _find_fcall_rname(func->getReturnType());
-
- if(args == NULL ){
+ if (args == NULL) {
args = new ArgumentList;
expr->setArgs(args);
args->addRef();
}
- args->add(new StringLiteral(CSTRING(libname)));
- args->add(new StringLiteral(CSTRING(rt)));
- args->add(new StringLiteral(CSTRING(fname)));
-
- num_args+=3;
+ std::string rt = _find_fcall_rname(func->getReturnType());
+ args->add(new StringLiteral(CSTRING(func->getLibName())));
+ args->add(new StringLiteral(CSTRING(rt)));
+ args->add(new StringLiteral(name));
+ num_args += 3;
}
// Set the return type

0 comments on commit da576ef

Please sign in to comment.