00001
00002
00003 #include "config.h"
00004
00005 #include <string.h>
00006
00007 #include "bif_arg.h"
00008
00009 static struct {
00010 const char* bif_type;
00011 const char* bro_type;
00012 const char* c_type;
00013 const char* accessor;
00014 } builtin_func_arg_type[] = {
00015 #define DEFINE_BIF_TYPE(id, bif_type, bro_type, c_type, accessor) {bif_type, bro_type, c_type, accessor},
00016 #include "bif_type.def"
00017 #undef DEFINE_BIF_TYPE
00018 };
00019
00020 extern const char* arg_list_name;
00021
00022 BuiltinFuncArg::BuiltinFuncArg(const char* arg_name, int arg_type)
00023 {
00024 name = arg_name;
00025 type = arg_type;
00026 type_str = "";
00027 }
00028
00029 BuiltinFuncArg::BuiltinFuncArg(const char* arg_name, const char* arg_type_str)
00030 {
00031 name = arg_name;
00032 type = TYPE_OTHER;
00033 type_str = arg_type_str;
00034
00035 for ( int i = 0; builtin_func_arg_type[i].bif_type[0] != '\0'; ++i )
00036 if ( ! strcmp(builtin_func_arg_type[i].bif_type, arg_type_str) )
00037 {
00038 type = i;
00039 type_str = "";
00040 }
00041 }
00042
00043 void BuiltinFuncArg::PrintBro(FILE* fp)
00044 {
00045 fprintf(fp, "%s: %s%s", name, builtin_func_arg_type[type].bro_type, type_str);
00046 }
00047
00048 void BuiltinFuncArg::PrintCDef(FILE* fp, int n)
00049 {
00050 fprintf(fp,
00051 "\t%s %s = (%s) ((*%s)[%d]%s);\n",
00052 builtin_func_arg_type[type].c_type,
00053 name,
00054 builtin_func_arg_type[type].c_type,
00055 arg_list_name,
00056 n,
00057 builtin_func_arg_type[type].accessor);
00058 }