Skip to content

Commit

Permalink
Merge pull request #79 from AjayBrahmakshatriya/master
Browse files Browse the repository at this point in the history
Added support for bool type
  • Loading branch information
AjayBrahmakshatriya authored Sep 6, 2024
2 parents c363631 + fb9e0c6 commit 7347252
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/blocks/var.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class scalar_type : public type {
UNSIGNED_CHAR_TYPE,
VOID_TYPE,
FLOAT_TYPE,
DOUBLE_TYPE
DOUBLE_TYPE,
BOOL_TYPE
} scalar_type_id;
virtual void accept(block_visitor *a) override {
a->visit(self<scalar_type>());
Expand Down
9 changes: 9 additions & 0 deletions include/builder/block_type_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ class type_extractor<double> {
}
};

template <>
class type_extractor<bool> {
public:
static block::type::Ptr extract_type(void) {
block::scalar_type::Ptr type = std::make_shared<block::scalar_type>();
type->scalar_type_id = block::scalar_type::BOOL_TYPE;
return type;
}
};
// Type specialization for pointer type
template <typename T>
class type_extractor<T *> {
Expand Down
9 changes: 7 additions & 2 deletions samples/outputs.var_names/sample30
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ STMT_BLOCK
SCALAR_TYPE (CHAR)
VAR (o_14)
STRING_CONST ("Hello world")
DECL_STMT
SCALAR_TYPE (BOOL)
VAR (p_15)
INT_CONST (1)
DECL_STMT
SCALAR_TYPE (INT)
VAR (x_15)
VAR (x_16)
INT_CONST (0)
{
short int a_0;
Expand All @@ -89,5 +93,6 @@ STMT_BLOCK
char n_13[] = "Hello world";
n_13 = "new string";
char const* const volatile o_14 = "Hello world";
int x_15 = 0;
bool p_15 = 1;
int x_16 = 0;
}
9 changes: 7 additions & 2 deletions samples/outputs/sample30
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ STMT_BLOCK
VAR (var14)
STRING_CONST ("Hello world")
DECL_STMT
SCALAR_TYPE (INT)
SCALAR_TYPE (BOOL)
VAR (var15)
INT_CONST (1)
DECL_STMT
SCALAR_TYPE (INT)
VAR (var16)
INT_CONST (0)
{
short int var0;
Expand All @@ -89,5 +93,6 @@ STMT_BLOCK
char var13[] = "Hello world";
var13 = "new string";
char const* const volatile var14 = "Hello world";
int var15 = 0;
bool var15 = 1;
int var16 = 0;
}
2 changes: 2 additions & 0 deletions samples/sample30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ static void foo(void) {

dyn_var<const char* const volatile> o = "Hello world";

dyn_var<bool> p = true;

// bool test, fixes a bug
// that causes false as an init value creates a variable
// without context
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/c_code_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ void c_code_generator::visit(scalar_type::Ptr type) {
case scalar_type::DOUBLE_TYPE:
oss << "double";
break;
case scalar_type::BOOL_TYPE:
oss << "bool";
break;
default:
assert(false && "Invalid scalar type");
}
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void scalar_type::dump(std::ostream &oss, int indent) {
oss << "FLOAT";
else if (scalar_type_id == DOUBLE_TYPE)
oss << "DOUBLE";
else if (scalar_type_id == BOOL_TYPE)
oss << "BOOL";
oss << ")" << std::endl;
}
void pointer_type::dump(std::ostream &oss, int indent) {
Expand Down

0 comments on commit 7347252

Please sign in to comment.