Skip to content
This repository
Browse code

- Clean up

  • Loading branch information...
commit da576ef22620332a1d331fd645f97e321f5ef381 1 parent 6232955
Felipe Pena authored
9  compiler/clever.h
@@ -57,8 +57,13 @@ extern jmp_buf fatal_error;
57 57
  */
58 58
 #define CLEVER_ADDREF(x) (x)->addRef()
59 59
 #define CLEVER_DELREF(x) (x)->delRef()
60  
-#define CLEVER_SAFE_ADDREF(x) if (x) { (x)->addRef(); }
61  
-#define CLEVER_SAFE_DELREF(x) if (x) { (x)->delRef(); }
  60
+#define CLEVER_SAFE_ADDREF(x) do { if (x) { (x)->addRef(); } } while (0);
  61
+#define CLEVER_SAFE_DELREF(x) do { if (x) { (x)->delRef(); } } while (0);
  62
+
  63
+/**
  64
+ * Macro to delete pointer after checking for not null
  65
+ */
  66
+#define CLEVER_SAFE_DELETE(x) do { if (x) { delete x; } } while (0);
62 67
 
63 68
 /**
64 69
  * Macro to access the an specific DataValue
45  compiler/typechecker.cc
@@ -219,6 +219,8 @@ static void _check_function_arg_types(const Function* func,
219 219
 
220 220
 		if (t1 != t2) {
221 221
 			if (!_check_compatible_types(t1, t2)) {
  222
+				CLEVER_SAFE_DELETE(arg_values);
  223
+
222 224
 				Compiler::errorf(loc,
223 225
 					"Wrong param type #%N: expected `%S', but `%S' supplied",
224 226
 						i, t1->getName(), t2->getName());
@@ -779,21 +781,20 @@ AST_VISITOR(TypeChecker, AssignExpr) {
779 781
 	expr->setValue(lhs);
780 782
 }
781 783
 
782  
-/**
783  
- * Function call visitor
784  
- */
785  
-
786  
-static inline std::string _find_fcall_rname(const Type* c) {
787  
-	if( c == CLEVER_INT) 		return "i";
788  
-	if( c == CLEVER_DOUBLE) 	return "d";
789  
-	if( c == CLEVER_STR) 		return "s";
790  
-	if( c == CLEVER_BOOL) 		return "b";
791  
-	if( c == CLEVER_BYTE)		return "c";
792  
-	if( c == CLEVER_VOID)		return "v";
793  
-	if( c == NULL)			return "v";
  784
+static inline const char* _find_fcall_rname(const Type* c) {
  785
+	if (c == CLEVER_INT)    return "i";
  786
+	if (c == CLEVER_DOUBLE) return "d";
  787
+	if (c == CLEVER_STR)    return "s";
  788
+	if (c == CLEVER_BOOL)   return "b";
  789
+	if (c == CLEVER_BYTE)   return "c";
  790
+	if (c == CLEVER_VOID)   return "v";
  791
+	if (c == NULL)          return "v";
794 792
 	return "p";
795 793
 }
796 794
 
  795
+/**
  796
+ * Function call visitor
  797
+ */
797 798
 AST_VISITOR(TypeChecker, FunctionCall) {
798 799
 	const CString* const name = expr->getFuncName();
799 800
 
@@ -801,7 +802,6 @@ AST_VISITOR(TypeChecker, FunctionCall) {
801 802
 
802 803
 	Value* fvalue = m_scope->getValue(name);
803 804
 
804  
-
805 805
 	if (UNEXPECTED(fvalue == NULL || !fvalue->isCallable())) {
806 806
 		Compiler::errorf(expr->getLocation(), "Function `%S' does not exists!",
807 807
 			name);
@@ -809,7 +809,6 @@ AST_VISITOR(TypeChecker, FunctionCall) {
809 809
 
810 810
 	const Function* func = static_cast<CallableValue*>(fvalue)->getFunction();
811 811
 
812  
-
813 812
 	int num_args = expr->getArgs() ? int(expr->getArgs()->getNodes().size()) : 0;
814 813
 
815 814
 	clever_assert_not_null(func);
@@ -818,26 +817,22 @@ AST_VISITOR(TypeChecker, FunctionCall) {
818 817
 
819 818
 	Value* result = new Value;
820 819
 
821  
-	if(func->isExternal()){
  820
+	if (func->isExternal()) {
822 821
 		ArgumentList* args = expr->getArgs();
823 822
 
824  
-		std::string fname = name->c_str();
825  
-		std::string libname = func->getLibName();
826  
-		std::string rt = _find_fcall_rname(func->getReturnType());
827  
-
828  
-		if(args == NULL ){
  823
+		if (args == NULL) {
829 824
 			args = new ArgumentList;
830 825
 			expr->setArgs(args);
831 826
 			args->addRef();
832 827
 		}
833 828
 
834  
-		args->add(new StringLiteral(CSTRING(libname)));
835  
-		args->add(new StringLiteral(CSTRING(rt)));
836  
-		args->add(new StringLiteral(CSTRING(fname)));
837  
-
838  
-		num_args+=3;
  829
+		std::string rt = _find_fcall_rname(func->getReturnType());
839 830
 
  831
+		args->add(new StringLiteral(CSTRING(func->getLibName())));
  832
+		args->add(new StringLiteral(CSTRING(rt)));
  833
+		args->add(new StringLiteral(name));
840 834
 
  835
+		num_args += 3;
841 836
 	}
842 837
 
843 838
 	// Set the return type

0 notes on commit da576ef

Please sign in to comment.
Something went wrong with that request. Please try again.