From: Surendra S. <efu...@us...> - 2005-07-23 05:34:20
|
Update of /cvsroot/swig/SWIG/Source/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14017 Modified Files: clisp.cxx Log Message: Added support for pointer to functions. Added support for typedefs and a option which will allow to generate "def-c-type" for typedefs. Joerg Hoehle suggested that while declaring arrays "c-ptr" should be used. Changed the name of generate-all option to extern-all. Now declaring pointers to integers, short, float and double as c-ptr instead of c-pointer. Index: clisp.cxx =================================================================== RCS file: /cvsroot/swig/SWIG/Source/Modules/clisp.cxx,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** clisp.cxx 18 Jul 2005 06:17:49 -0000 1.4 --- clisp.cxx 23 Jul 2005 05:34:11 -0000 1.5 *************** *** 24,27 **** --- 24,28 ---- virtual int constantWrapper(Node *n); virtual int classDeclaration(Node *n); + virtual int typedefHandler(Node *n); List *entries; private: *************** *** 29,33 **** String* convert_literal(String *num_param, String *type); String* strip_parens(String *string); ! int generate_all_flag; }; --- 30,36 ---- String* convert_literal(String *num_param, String *type); String* strip_parens(String *string); ! int extern_all_flag; ! int generate_typedef_flag; ! int is_function; }; *************** *** 37,41 **** SWIG_library_directory("clisp"); SWIG_config_file("clisp.swg"); ! generate_all_flag = 0; for(i=1; i<argc; i++) { --- 40,45 ---- SWIG_library_directory("clisp"); SWIG_config_file("clisp.swg"); ! generate_typedef_flag = 0; ! extern_all_flag=0; for(i=1; i<argc; i++) { *************** *** 43,59 **** Printf(stdout, "clisp Options (available with -clisp)\n"); Printf(stdout, ! " -generate-all\n" "\t If this option is given then clisp definitions for all the functions\n" "and global variables will be created otherwise only definitions for \n" ! "externed functions and variables is created."); } ! else if ( (Strcmp(argv[i],"-generate-all") == 0)) { ! generate_all_flag = 1; ! Swig_mark_arg(i); } } } - int CLISP :: top(Node *n) { --- 47,70 ---- Printf(stdout, "clisp Options (available with -clisp)\n"); Printf(stdout, ! " -extern-all\n" "\t If this option is given then clisp definitions for all the functions\n" "and global variables will be created otherwise only definitions for \n" ! "externed functions and variables are created." ! " -generate-typedef\n" ! "\t If this option is given then def-c-type will be used to generate shortcuts\n" ! "according to the typedefs in the input.\n" ! ); } ! else if ( (Strcmp(argv[i],"-extern-all") == 0)) { ! extern_all_flag = 1; ! Swig_mark_arg(i); ! } ! else if ( (Strcmp(argv[i],"-generate-typedef") == 0)) { ! generate_typedef_flag = 1; ! Swig_mark_arg(i); } } } int CLISP :: top(Node *n) { *************** *** 82,87 **** Swig_register_filebyname("runtime",f_null); Swig_register_filebyname("wrapper", f_null); ! ! String *header=NewStringf(";; This is an automatically generated file. \n;;Make changes as you feel are necessary (but remember if you try to regenerate this file, your changes will be lost). \n\n(defpackage \"%s\"\n (:use :common-lisp :ffi)", module); --- 93,97 ---- Swig_register_filebyname("runtime",f_null); Swig_register_filebyname("wrapper", f_null); ! String *header=NewStringf(";; This is an automatically generated file. \n;;Make changes as you feel are necessary (but remember if you try to regenerate this file, your changes will be lost). \n\n(defpackage \"%s\"\n (:use :common-lisp :ffi)", module); *************** *** 93,97 **** } Printf(header, ")\n",NULL); - Printf(header,"\n(in-package :%s)\n",module); --- 103,106 ---- *************** *** 121,127 **** int CLISP :: functionWrapper(Node *n) { ! String *storage=Getattr(n,"storage"); ! if(!generate_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))) return SWIG_OK; --- 130,136 ---- int CLISP :: functionWrapper(Node *n) { ! is_function=1; String *storage=Getattr(n,"storage"); ! if(!extern_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))) return SWIG_OK; *************** *** 135,140 **** Append(entries,func_name); ! /* Special cases */ ! if (ParmList_len(pl) != 0) { Printf(f_cl, "\t(:arguments "); --- 144,148 ---- Append(entries,func_name); ! if (ParmList_len(pl) != 0) { Printf(f_cl, "\t(:arguments "); *************** *** 149,167 **** int tempargname=0; ! if (!argname) { ! argname=NewStringf("arg%d", argnum); ! tempargname=1; ! } ! if (!first) { ! Printf(f_cl, "\n\t\t"); ! } ! Printf(f_cl, "(%s %s)", argname, ffitype); ! first=0; ! Delete(ffitype); ! if (tempargname) ! Delete(argname); } if (ParmList_len(pl) != 0) { --- 157,175 ---- int tempargname=0; ! if (!argname) { ! argname=NewStringf("arg%d", argnum); ! tempargname=1; ! } ! if (!first) { ! Printf(f_cl, "\n\t\t"); ! } ! Printf(f_cl, "(%s %s)", argname, ffitype); ! first=0; ! Delete(ffitype); ! if (tempargname) ! Delete(argname); } if (ParmList_len(pl) != 0) { *************** *** 176,191 **** int CLISP :: constantWrapper(Node *n) { String *type=Getattr(n, "type"); String *converted_value=convert_literal(Getattr(n, "value"), type); String *name=Getattr(n, "sym:name"); ! #if 0 ! Printf(stdout, "constant %s is of type %s. value: %s\n", ! name, type, converted_value); ! #endif ! ! Printf(f_cl, "\n(defconstant %s %s)\n", ! name, converted_value); ! Delete(converted_value); --- 184,193 ---- int CLISP :: constantWrapper(Node *n) { + is_function=0; String *type=Getattr(n, "type"); String *converted_value=convert_literal(Getattr(n, "value"), type); String *name=Getattr(n, "sym:name"); ! Printf(f_cl, "\n(defconstant %s %s)\n", name, converted_value); Delete(converted_value); *************** *** 194,202 **** int CLISP :: variableWrapper(Node *n) { String *storage=Getattr(n,"storage"); ! if(!generate_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))) return SWIG_OK; - String *type=Getattr(n, "type"); String *var_name=Getattr(n, "sym:name"); String *lisp_type=get_ffi_type(type); --- 196,206 ---- int CLISP :: variableWrapper(Node *n) { + is_function=0; + SwigType *type=Getattr(n, "type"); String *storage=Getattr(n,"storage"); ! ! if(!extern_all_flag && (!storage || (Strcmp(storage,"extern") && Strcmp(storage,"externc")))) return SWIG_OK; String *var_name=Getattr(n, "sym:name"); String *lisp_type=get_ffi_type(type); *************** *** 206,212 **** --- 210,226 ---- } + int CLISP :: typedefHandler(Node *n) { + if(generate_typedef_flag) { + is_function=0; + Printf(f_cl,"\n(def-c-type %s (:type %s)\n",Getattr(n,"name"),get_ffi_type(Getattr(n,"type"))); + } + + return Language::typedefHandler(n); + } + // Includes structs int CLISP :: classDeclaration(Node *n) { + is_function=0; String *name=Getattr(n, "sym:name"); String *kind = Getattr(n,"kind"); *************** *** 336,340 **** SwigType_del_pointer(cp); String *inner_type=get_ffi_type(cp); ! String *str = NewStringf("(ffi:c-pointer %s)",inner_type); Delete(cp); Delete(inner_type); --- 350,372 ---- SwigType_del_pointer(cp); String *inner_type=get_ffi_type(cp); ! ! if(SwigType_isfunction(cp)) { ! return inner_type; ! } ! ! SwigType *base=SwigType_base(ty); ! String *base_name=SwigType_str(base,0); ! ! String *str; ! if(!Strcmp(base_name,"int") || !Strcmp(base_name,"float") || !Strcmp(base_name,"short") ! || !Strcmp(base_name,"double") || !Strcmp(base_name,"long")) { ! ! str = NewStringf("(ffi:c-ptr %s)",inner_type); ! } ! else { ! str = NewStringf("(ffi:c-pointer %s)",inner_type); ! } ! Delete(base_name); ! Delete(base); Delete(cp); Delete(inner_type); *************** *** 375,379 **** Delete(temp); } ! String *str=NewStringf("(ffi:c-array %s %s)",inner_type,dimension); Delete(inner_type); Delete(dimension); --- 407,416 ---- Delete(temp); } ! String *str; ! if(is_function) ! str=NewStringf("(ffi:c-ptr (ffi:c-array %s %s))",inner_type,dimension); ! else ! str=NewStringf("(ffi:c-array %s %s)",inner_type,dimension); ! Delete(inner_type); Delete(dimension); *************** *** 381,384 **** --- 418,461 ---- } } + else if(SwigType_isfunction(ty)) { + SwigType *cp = Copy(ty); + SwigType *fn=SwigType_pop_function(cp); + String *args=NewString(""); + ParmList *pl= SwigType_function_parms(fn); + if (ParmList_len(pl) != 0) { + Printf(args, "(:arguments "); + } + int argnum=0, first=1; + for (Parm *p=pl; p; p=nextSibling(p), argnum++) { + String *argname=Getattr(p, "name"); + SwigType *argtype=Getattr(p, "type"); + String *ffitype=get_ffi_type(argtype); + + int tempargname=0; + + if (!argname) { + argname=NewStringf("arg%d", argnum); + tempargname=1; + } + if (!first) { + Printf(args, "\n\t\t"); + } + Printf(args, "(%s %s)", argname, ffitype); + first=0; + Delete(ffitype); + if (tempargname) + Delete(argname); + } + if (ParmList_len(pl) != 0) { + Printf(args, ")\n"); /* finish arg list */ + } + String *ffitype = get_ffi_type(cp); + String *str=NewStringf("(ffi:c-function %s \t\t\t\t(:return-type %s))",args,ffitype); + Delete(fn); + Delete(args); + Delete(cp); + Delete(ffitype); + return str; + } String *str=SwigType_str(ty,0); if(str) { |