{
var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s1"), new CCodeIdentifier ("s2"));
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("TRUE"));
+ ccode.add_return (get_boolean_cconstant (true));
ccode.close ();
}
// if (s1 == NULL || s2 == NULL) return FALSE;
{
var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s1"), new CCodeConstant ("NULL"));
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
ccode.close ();
cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s2"), new CCodeConstant ("NULL"));
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
ccode.close ();
}
}
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
ccode.close ();
}
var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("s1")), new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("s2")));
ccode.add_return (cexp);
} else {
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
}
} else {
- ccode.add_return (new CCodeConstant ("TRUE"));
+ ccode.add_return (get_boolean_cconstant (true));
}
pop_function ();
{
var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s1"), new CCodeIdentifier ("s2"));
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("TRUE"));
+ ccode.add_return (get_boolean_cconstant (true));
ccode.close ();
}
// if (s1 == NULL || s2 == NULL) return FALSE;
{
var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s1"), new CCodeConstant ("NULL"));
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
ccode.close ();
cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("s2"), new CCodeConstant ("NULL"));
ccode.open_if (cexp);
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
ccode.close ();
}
// return (*s1 == *s2);
}
public override void visit_boolean_literal (BooleanLiteral expr) {
- if (context.profile == Profile.GOBJECT) {
- set_cvalue (expr, new CCodeConstant (expr.value ? "TRUE" : "FALSE"));
- } else {
- cfile.add_include ("stdbool.h");
- set_cvalue (expr, new CCodeConstant (expr.value ? "true" : "false"));
- }
+ set_cvalue (expr, get_boolean_cconstant (expr.value));
}
public override void visit_character_literal (CharacterLiteral expr) {
ccall.add_argument (cleft);
ccall.add_argument (cright);
cleft = ccall;
- cright = new CCodeConstant ("TRUE");
+ cright = get_boolean_cconstant (true);
} else if ((left_type is IntegerType || left_type is FloatingType || left_type is BooleanType || left_type is EnumValueType) && left_type.nullable &&
(right_type is IntegerType || right_type is FloatingType || right_type is BooleanType || right_type is EnumValueType) && right_type.nullable) {
var equalfunc = generate_numeric_equal_function ((TypeSymbol) left_type.type_symbol);
ccall.add_argument (cleft);
ccall.add_argument (cright);
cleft = ccall;
- cright = new CCodeConstant ("TRUE");
+ cright = get_boolean_cconstant (true);
}
}
var ccall = new CCodeFunctionCall (new CCodeIdentifier (equalfunc));
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, celement));
ccall.add_argument (cneedle);
- cif_condition = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccall, new CCodeConstant ("TRUE"));
+ cif_condition = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, ccall, get_boolean_cconstant (true));
} else {
cif_condition = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cneedle, celement);
}
ccode.open_if (cif_condition);
- ccode.add_return (new CCodeConstant ("TRUE"));
+ ccode.add_return (get_boolean_cconstant (true));
ccode.close ();
ccode.close ();
- ccode.add_return (new CCodeConstant ("FALSE"));
+ ccode.add_return (get_boolean_cconstant (false));
pop_function ();
return "";
}
+ public CCodeExpression get_boolean_cconstant (bool b) {
+ if (context.profile == Profile.GOBJECT) {
+ return new CCodeConstant (b ? "TRUE" : "FALSE");
+ } else {
+ cfile.add_include ("stdbool.h");
+ return new CCodeConstant (b ? "true" : "false");
+ }
+ }
+
public CCodeExpression? get_cvalue (Expression expr) {
if (expr.target_value == null) {
return null;