Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for bool type #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading