projects
/
cparser
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed some warnings
[cparser]
/
write_fluffy.c
diff --git
a/write_fluffy.c
b/write_fluffy.c
index
c33b546
..
4ad6fc0
100644
(file)
--- a/
write_fluffy.c
+++ b/
write_fluffy.c
@@
-3,6
+3,7
@@
#include <errno.h>
#include <string.h>
#include <errno.h>
#include <string.h>
+#include "write_fluffy.h"
#include "ast_t.h"
#include "type_t.h"
#include "type.h"
#include "ast_t.h"
#include "type_t.h"
#include "type.h"
@@
-73,9
+74,10
@@
static void write_compound_type(const compound_type_t *type)
}
/* does the struct have a name? */
}
/* does the struct have a name? */
- if(type->symbol != NULL) {
+ symbol_t *symbol = type->declaration->symbol;
+ if(symbol != NULL) {
/* TODO: make sure we create a struct for it... */
/* TODO: make sure we create a struct for it... */
- fprintf(out, "%s",
type->
symbol->string);
+ fprintf(out, "%s", symbol->string);
return;
}
/* TODO: create a struct and use its name here... */
return;
}
/* TODO: create a struct and use its name here... */
@@
-91,21
+93,22
@@
static void write_enum_type(const enum_type_t *type)
}
/* does the enum have a name? */
}
/* does the enum have a name? */
- if(type->symbol != NULL) {
+ symbol_t *symbol = type->declaration->symbol;
+ if(symbol != NULL) {
/* TODO: make sure we create an enum for it... */
/* TODO: make sure we create an enum for it... */
- fprintf(out, "%s",
type->
symbol->string);
+ fprintf(out, "%s", symbol->string);
return;
}
/* TODO: create a struct and use its name here... */
fprintf(out, "/* TODO anonymous enum */byte");
}
return;
}
/* TODO: create a struct and use its name here... */
fprintf(out, "/* TODO anonymous enum */byte");
}
-static void write_
method_type(const method
_type_t *type)
+static void write_
function_type(const function
_type_t *type)
{
fprintf(out, "(func(");
{
fprintf(out, "(func(");
-
method
_parameter_t *parameter = type->parameters;
- int first = 1;
+
function
_parameter_t *parameter = type->parameters;
+ int
first = 1;
while(parameter != NULL) {
if(!first) {
fprintf(out, ", ");
while(parameter != NULL) {
if(!first) {
fprintf(out, ", ");
@@
-148,8
+151,8
@@
static void write_type(const type_t *type)
case TYPE_ENUM:
write_enum_type((const enum_type_t*) type);
return;
case TYPE_ENUM:
write_enum_type((const enum_type_t*) type);
return;
- case TYPE_
METHOD
:
- write_
method_type((const method
_type_t*) type);
+ case TYPE_
FUNCTION
:
+ write_
function_type((const function
_type_t*) type);
return;
case TYPE_INVALID:
panic("invalid type found");
return;
case TYPE_INVALID:
panic("invalid type found");
@@
-171,7
+174,7
@@
static void write_struct(const symbol_t *symbol, const compound_type_t *type)
{
fprintf(out, "struct %s:\n", symbol->string);
{
fprintf(out, "struct %s:\n", symbol->string);
- const declaration_t *declaration = type->context.declarations;
+ const declaration_t *declaration = type->
declaration->
context.declarations;
while(declaration != NULL) {
write_struct_entry(declaration);
declaration = declaration->next;
while(declaration != NULL) {
write_struct_entry(declaration);
declaration = declaration->next;
@@
-184,7
+187,7
@@
static void write_union(const symbol_t *symbol, const compound_type_t *type)
{
fprintf(out, "union %s:\n", symbol->string);
{
fprintf(out, "union %s:\n", symbol->string);
- const declaration_t *declaration = type->context.declarations;
+ const declaration_t *declaration = type->
declaration->
context.declarations;
while(declaration != NULL) {
write_struct_entry(declaration);
declaration = declaration->next;
while(declaration != NULL) {
write_struct_entry(declaration);
declaration = declaration->next;
@@
-218,7
+221,7
@@
static void write_expression(const expression_t *expression)
case EXPR_CONST:
constant = (const const_t*) expression;
if(is_type_integer(expression->datatype)) {
case EXPR_CONST:
constant = (const const_t*) expression;
if(is_type_integer(expression->datatype)) {
- fprintf(out, "%d", constant->v.int_value);
+ fprintf(out, "%
ll
d", constant->v.int_value);
} else {
fprintf(out, "%Lf", constant->v.float_value);
}
} else {
fprintf(out, "%Lf", constant->v.float_value);
}
@@
-231,25
+234,17
@@
static void write_expression(const expression_t *expression)
}
}
}
}
-static void write_initializer(const initializer_t *initializer)
-{
- if(initializer->type != INITIALIZER_VALUE) {
- panic("list initializers not supported yet");
- }
-
- write_expression(initializer->v.value);
-}
-
static void write_enum(const symbol_t *symbol, const enum_type_t *type)
{
fprintf(out, "enum %s:\n", symbol->string);
static void write_enum(const symbol_t *symbol, const enum_type_t *type)
{
fprintf(out, "enum %s:\n", symbol->string);
- declaration_t *entry = type->entries_begin;
- for ( ; entry != type->entries_end->next; entry = entry->next) {
+ declaration_t *entry = type->declaration->next;
+ for ( ; entry != NULL && entry->storage_class == STORAGE_CLASS_ENUM_ENTRY;
+ entry = entry->next) {
fprintf(out, "\t%s", entry->symbol->string);
fprintf(out, "\t%s", entry->symbol->string);
- if(entry->initializer != NULL) {
+ if(entry->init
.init
ializer != NULL) {
fprintf(out, " <- ");
fprintf(out, " <- ");
- write_
initializer(entry->initializer
);
+ write_
expression(entry->init.enum_value
);
}
fputc('\n', out);
}
}
fputc('\n', out);
}
@@
-267,7
+262,7
@@
static void write_variable(const declaration_t *declaration)
static void write_function(const declaration_t *declaration)
{
static void write_function(const declaration_t *declaration)
{
- if(declaration->statement != NULL) {
+ if(declaration->
init.
statement != NULL) {
fprintf(stderr, "Warning: can't convert function bodies (at %s)\n",
declaration->symbol->string);
}
fprintf(stderr, "Warning: can't convert function bodies (at %s)\n",
declaration->symbol->string);
}
@@
-275,7
+270,8
@@
static void write_function(const declaration_t *declaration)
fprintf(out, "func extern %s(",
declaration->symbol->string);
fprintf(out, "func extern %s(",
declaration->symbol->string);
- const method_type_t *method_type = (const method_type_t*) declaration->type;
+ const function_type_t *function_type
+ = (const function_type_t*) declaration->type;
declaration_t *parameter = declaration->context.declarations;
int first = 1;
declaration_t *parameter = declaration->context.declarations;
int first = 1;
@@
-292,7
+288,7
@@
static void write_function(const declaration_t *declaration)
}
write_type(parameter->type);
}
}
write_type(parameter->type);
}
- if(
method
_type->variadic) {
+ if(
function
_type->variadic) {
if(!first) {
fprintf(out, ", ");
} else {
if(!first) {
fprintf(out, ", ");
} else {
@@
-302,7
+298,7
@@
static void write_function(const declaration_t *declaration)
}
fprintf(out, ")");
}
fprintf(out, ")");
- const type_t
*result_type = method
_type->result_type;
+ const type_t
*result_type = function
_type->result_type;
if(result_type->type != TYPE_ATOMIC ||
((const atomic_type_t*) result_type)->atype != ATOMIC_TYPE_VOID) {
fprintf(out, " : ");
if(result_type->type != TYPE_ATOMIC ||
((const atomic_type_t*) result_type)->atype != ATOMIC_TYPE_VOID) {
fprintf(out, " : ");
@@
-345,12
+341,14
@@
void write_fluffy_decls(const translation_unit_t *unit)
/* write global variables */
declaration = unit->context.declarations;
for( ; declaration != NULL; declaration = declaration->next) {
/* write global variables */
declaration = unit->context.declarations;
for( ; declaration != NULL; declaration = declaration->next) {
+ if(declaration->namespc != NAMESPACE_NORMAL)
+ continue;
if(declaration->storage_class == STORAGE_CLASS_TYPEDEF
|| declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
continue;
type_t *type = declaration->type;
if(declaration->storage_class == STORAGE_CLASS_TYPEDEF
|| declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
continue;
type_t *type = declaration->type;
- if(type->type == TYPE_
METHOD
)
+ if(type->type == TYPE_
FUNCTION
)
continue;
write_variable(declaration);
continue;
write_variable(declaration);
@@
-359,12
+357,14
@@
void write_fluffy_decls(const translation_unit_t *unit)
/* write functions */
declaration = unit->context.declarations;
for( ; declaration != NULL; declaration = declaration->next) {
/* write functions */
declaration = unit->context.declarations;
for( ; declaration != NULL; declaration = declaration->next) {
+ if(declaration->namespc != NAMESPACE_NORMAL)
+ continue;
if(declaration->storage_class == STORAGE_CLASS_TYPEDEF
|| declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
continue;
type_t *type = declaration->type;
if(declaration->storage_class == STORAGE_CLASS_TYPEDEF
|| declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
continue;
type_t *type = declaration->type;
- if(type->type != TYPE_
METHOD
)
+ if(type->type != TYPE_
FUNCTION
)
continue;
write_function(declaration);
continue;
write_function(declaration);