projects
/
cparser
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More work on cparser:
[cparser]
/
write_fluffy.c
diff --git
a/write_fluffy.c
b/write_fluffy.c
index
ee1793b
..
e9db530
100644
(file)
--- a/
write_fluffy.c
+++ b/
write_fluffy.c
@@
-5,6
+5,7
@@
#include "ast_t.h"
#include "type_t.h"
#include "ast_t.h"
#include "type_t.h"
+#include "type.h"
#include "adt/error.h"
static const context_t *global_context;
#include "adt/error.h"
static const context_t *global_context;
@@
-51,7
+52,7
@@
static declaration_t *find_typedef(const type_t *type)
/* first: search for a matching typedef in the global type... */
declaration_t *declaration = global_context->declarations;
while(declaration != NULL) {
/* first: search for a matching typedef in the global type... */
declaration_t *declaration = global_context->declarations;
while(declaration != NULL) {
- if(! (declaration->storage_class
&
STORAGE_CLASS_TYPEDEF)) {
+ if(! (declaration->storage_class
==
STORAGE_CLASS_TYPEDEF)) {
declaration = declaration->next;
continue;
}
declaration = declaration->next;
continue;
}
@@
-103,8
+104,8
@@
static void write_method_type(const method_type_t *type)
{
fprintf(out, "(func(");
{
fprintf(out, "(func(");
-
declaration
_t *parameter = type->parameters;
- int first = 1;
+
method_parameter
_t *parameter = type->parameters;
+ int
first = 1;
while(parameter != NULL) {
if(!first) {
fprintf(out, ", ");
while(parameter != NULL) {
if(!first) {
fprintf(out, ", ");
@@
-112,12
+113,15
@@
static void write_method_type(const method_type_t *type)
first = 0;
}
first = 0;
}
+#if 0
if(parameter->symbol != NULL) {
fprintf(out, "%s : ", parameter->symbol->string);
} else {
/* TODO make up some unused names (or allow _ in fluffy?) */
fprintf(out, "_ : ");
}
if(parameter->symbol != NULL) {
fprintf(out, "%s : ", parameter->symbol->string);
} else {
/* TODO make up some unused names (or allow _ in fluffy?) */
fprintf(out, "_ : ");
}
+#endif
+ fputs("_ : ", out);
write_type(parameter->type);
parameter = parameter->next;
write_type(parameter->type);
parameter = parameter->next;
@@
-213,7
+217,11
@@
static void write_expression(const expression_t *expression)
switch(expression->type) {
case EXPR_CONST:
constant = (const const_t*) expression;
switch(expression->type) {
case EXPR_CONST:
constant = (const const_t*) expression;
- fprintf(out, "%d", constant->value);
+ if(is_type_integer(expression->datatype)) {
+ fprintf(out, "%d", constant->v.int_value);
+ } else {
+ fprintf(out, "%Lf", constant->v.float_value);
+ }
break;
case EXPR_UNARY:
write_unary_expression((const unary_expression_t*) expression);
break;
case EXPR_UNARY:
write_unary_expression((const unary_expression_t*) expression);
@@
-227,12
+235,12
@@
static void write_enum(const symbol_t *symbol, const enum_type_t *type)
{
fprintf(out, "enum %s:\n", symbol->string);
{
fprintf(out, "enum %s:\n", symbol->string);
-
const enum_entry_t *entry = type->entries
;
- for ( ; entry !=
NULL
; entry = entry->next) {
+
declaration_t *entry = type->entries_begin
;
+ for ( ; entry !=
type->entries_end->next
; entry = entry->next) {
fprintf(out, "\t%s", entry->symbol->string);
fprintf(out, "\t%s", entry->symbol->string);
- if(entry->
value
!= NULL) {
+ if(entry->
initializer
!= NULL) {
fprintf(out, " <- ");
fprintf(out, " <- ");
- write_expression(entry->
value
);
+ write_expression(entry->
initializer
);
}
fputc('\n', out);
}
}
fputc('\n', out);
}
@@
-260,7
+268,7
@@
static void write_function(const declaration_t *declaration)
const method_type_t *method_type = (const method_type_t*) declaration->type;
const method_type_t *method_type = (const method_type_t*) declaration->type;
- declaration_t *parameter =
method_type->parameter
s;
+ declaration_t *parameter =
declaration->context.declaration
s;
int first = 1;
for( ; parameter != NULL; parameter = parameter->next) {
if(!first) {
int first = 1;
for( ; parameter != NULL; parameter = parameter->next) {
if(!first) {
@@
-310,10
+318,9
@@
void write_fluffy_decls(const translation_unit_t *unit)
/* write structs,unions + enums */
declaration_t *declaration = unit->context.declarations;
/* write structs,unions + enums */
declaration_t *declaration = unit->context.declarations;
-
while(declaration != NULL
) {
+
for( ; declaration != NULL; declaration = declaration->next
) {
//fprintf(out, "// Decl: %s\n", declaration->symbol->string);
//fprintf(out, "// Decl: %s\n", declaration->symbol->string);
- if(! (declaration->storage_class & STORAGE_CLASS_TYPEDEF)) {
- declaration = declaration->next;
+ if(! (declaration->storage_class == STORAGE_CLASS_TYPEDEF)) {
continue;
}
type_t *type = declaration->type;
continue;
}
type_t *type = declaration->type;
@@
-324,14
+331,13
@@
void write_fluffy_decls(const translation_unit_t *unit)
} else if(type->type == TYPE_ENUM) {
write_enum(declaration->symbol, (enum_type_t*) type);
}
} else if(type->type == TYPE_ENUM) {
write_enum(declaration->symbol, (enum_type_t*) type);
}
-
- declaration = declaration->next;
}
/* 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->storage_class & STORAGE_CLASS_TYPEDEF)
+ if(declaration->storage_class == STORAGE_CLASS_TYPEDEF
+ || declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
continue;
type_t *type = declaration->type;
continue;
type_t *type = declaration->type;
@@
-344,7
+350,8
@@
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->storage_class & STORAGE_CLASS_TYPEDEF)
+ if(declaration->storage_class == STORAGE_CLASS_TYPEDEF
+ || declaration->storage_class == STORAGE_CLASS_ENUM_ENTRY)
continue;
type_t *type = declaration->type;
continue;
type_t *type = declaration->type;