Commit ca792bad authored by Michael Beck's avatar Michael Beck
Browse files

added tpop flags

fixed some typos
added const where possible

[r4758]
parent 4930f991
......@@ -30,7 +30,7 @@ tp_op *tpop_none; tp_op *get_tpop_none (void) { return tpop_none;
tp_op *tpop_unknown; tp_op *get_tpop_unknown (void) { return tpop_unknown; }
tp_op *
new_tpop (tp_opcode code, ident *name, size_t attr_size)
new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size)
{
tp_op *res;
......@@ -42,27 +42,31 @@ new_tpop (tp_opcode code, ident *name, size_t attr_size)
}
INLINE void
free_tpop(tp_op* tpop) {
free_tpop(tp_op *tpop) {
free(tpop);
}
#define C TP_OP_FLAG_COMPOUND
#define ID(s) new_id_from_chars(s, sizeof(s) - 1)
void
init_tpop(void)
{
type_class = new_tpop (tpo_class , new_id_from_chars("class" , 5), sizeof (cls_attr));
type_struct = new_tpop (tpo_struct , new_id_from_chars("struct" , 6), sizeof (stc_attr));
type_method = new_tpop (tpo_method , new_id_from_chars("method" , 6), sizeof (mtd_attr));
type_union = new_tpop (tpo_union , new_id_from_chars("union" , 5), sizeof (uni_attr));
type_array = new_tpop (tpo_array , new_id_from_chars("array" , 5), sizeof (arr_attr));
type_enumeration = new_tpop (tpo_enumeration, new_id_from_chars("enumeration" ,11), sizeof (enm_attr));
type_pointer = new_tpop (tpo_pointer , new_id_from_chars("pointer" , 7), sizeof (ptr_attr));
type_primitive = new_tpop (tpo_primitive , new_id_from_chars("primitive" , 9), /* sizeof (pri_attr) */ 0);
type_id = new_tpop (tpo_id , new_id_from_chars("type_id" , 7), /* sizeof (id_attr) */ 0);
tpop_none = new_tpop (tpo_none , new_id_from_chars("tpop_none" , 9), /* sizeof (non_attr) */ 0);
tpop_unknown = new_tpop (tpo_unknown , new_id_from_chars("tpop_unknown",12), /* sizeof (ukn_attr) */ 0);
type_class = new_tpop(tpo_class , ID("class"), C, sizeof (cls_attr));
type_struct = new_tpop(tpo_struct , ID("struct"), C, sizeof (stc_attr));
type_method = new_tpop(tpo_method , ID("method"), 0, sizeof (mtd_attr));
type_union = new_tpop(tpo_union , ID("union"), C, sizeof (uni_attr));
type_array = new_tpop(tpo_array , ID("array"), C, sizeof (arr_attr));
type_enumeration = new_tpop(tpo_enumeration, ID("enumeration"), 0, sizeof (enm_attr));
type_pointer = new_tpop(tpo_pointer , ID("pointer"), 0, sizeof (ptr_attr));
type_primitive = new_tpop(tpo_primitive , ID("primitive"), 0, /* sizeof (pri_attr) */ 0);
type_id = new_tpop(tpo_id , ID("type_id"), 0, /* sizeof (id_attr) */ 0);
tpop_none = new_tpop(tpo_none , ID("tpop_none"), 0, /* sizeof (non_attr) */ 0);
tpop_unknown = new_tpop(tpo_unknown , ID("tpop_unknown"),0, /* sizeof (ukn_attr) */ 0);
}
#undef ID
#undef C
/* Finalize the topo module.
/* Finalize the tpop module.
* Frees all type opcodes. */
void finish_tpop(void) {
free_tpop(type_class ); type_class = NULL;
......@@ -79,19 +83,19 @@ void finish_tpop(void) {
}
/* Returns the string for the tp_opcode. */
const char *get_tpop_name (tp_op *op) {
const char *get_tpop_name(const tp_op *op) {
return get_id_str(op->name);
}
tp_opcode (get_tpop_code)(tp_op *op){
tp_opcode (get_tpop_code)(const tp_op *op){
return __get_tpop_code(op);
}
ident *(get_tpop_ident)(tp_op *op){
ident *(get_tpop_ident)(const tp_op *op){
return __get_tpop_ident(op);
}
/* returns the attribute size of the operator. */
int (get_tpop_attr_size)(tp_op *op) {
int (get_tpop_attr_size)(const tp_op *op) {
return __get_tpop_attr_size(op);
}
......@@ -64,7 +64,7 @@ typedef struct tp_op tp_op;
* @param op The type opcode to get the string from.
* @return a string. (@todo Null terminated???)
*/
const char *get_tpop_name (tp_op *op);
const char *get_tpop_name (const tp_op *op);
/**
* Returns an enum for the type opcode.
......@@ -72,7 +72,7 @@ const char *get_tpop_name (tp_op *op);
* @param op The type opcode to get the enum from.
* @return the enum.
*/
tp_opcode get_tpop_code (tp_op *op);
tp_opcode get_tpop_code (const tp_op *op);
/**
* Returns the ident for the type opcode.
......@@ -80,7 +80,7 @@ tp_opcode get_tpop_code (tp_op *op);
* @param op The type opcode to get the ident from.
* @return The ident.
*/
ident *get_tpop_ident (tp_op *op);
ident *get_tpop_ident (const tp_op *op);
/**
* This type opcode marks that the corresponding type is a class type.
......@@ -141,7 +141,7 @@ tp_op *get_tpop_array(void);
* This type opcode marks that the corresponding type is an enumeration type.
*
* Consequently it contains a list of idents for the enumeration identifiers
* and a list of tarbet values that are the constants used to implement
* and a list of target values that are the constants used to implement
* the enumerators.
* This struct is dynamically allocated but constant for the lifetime
* of the library.
......
......@@ -25,11 +25,17 @@
* @see tpop.h
*/
/** possible flags for a type opcode */
enum tp_op_flags_t {
TP_OP_FLAG_COMPOUND = 1 /**< is a compound type */
};
/** The type opcode */
struct tp_op {
tp_opcode code;
ident *name;
size_t attr_size;
tp_opcode code; /**< the tpop code */
ident *name; /**< the name of the type opcode */
size_t attr_size; /**< the attribute size for a type of this opcode */
unsigned flags; /**< flags for this opcode */
};
/**
......@@ -41,12 +47,12 @@ struct tp_op {
*
* @param code the enum for this type opcode.
* @param name an ident for the name of the type opcode.
* @param flags additional flags
* @param attr_size the size of the attributes necessary for a type with
* this opcode
* @return A new type opcode.
*
*/
tp_op *new_tpop (tp_opcode code, ident *name, size_t attr_size);
tp_op *new_tpop (tp_opcode code, ident *name, unsigned flags, size_t attr_size);
/**
* Free a tpop datastructure.
......@@ -56,7 +62,7 @@ void free_tpop(tp_op* tpop);
/**
* Initialize the tpop module.
*
* Must be called during the initizlization of the library. Allocates
* Must be called during the initialization of the library. Allocates
* opcodes and sets the globals that are external visible as specified
* in tpop.h.
* Allocates opcodes for classes, struct, method, union, array,
......@@ -65,7 +71,7 @@ void free_tpop(tp_op* tpop);
void init_tpop (void);
/**
* Finalize the topo module.
* Finalize the tpop module.
*
* Frees all type opcodes.
*/
......@@ -81,7 +87,7 @@ void finish_tpop(void);
* @return The size of the attribute of types with this opcode.
*
*/
int get_tpop_attr_size (tp_op *op);
int get_tpop_attr_size (const tp_op *op);
/* ---------------- *
......@@ -89,17 +95,17 @@ int get_tpop_attr_size (tp_op *op);
* -----------------*/
static INLINE tp_opcode
__get_tpop_code(tp_op *op) {
__get_tpop_code(const tp_op *op) {
return op->code;
}
static INLINE ident *
__get_tpop_ident(tp_op *op){
__get_tpop_ident(const tp_op *op){
return op->name;
}
static INLINE int
__get_tpop_attr_size(tp_op *op) {
__get_tpop_attr_size(const tp_op *op) {
return op->attr_size;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment