pike.git / src / post_modules / GTK2 / build_pgtk.pike

version» Context lines:

pike.git/src/post_modules/GTK2/build_pgtk.pike:1:   #!/usr/bin/env pike    -  +    string destination_dir = "";      /* Start of relevant parts of program_id.h */   #define PROG_IMAGE_IMAGE_ID 100   #define PROG_IMAGE_COLORTABLE_ID 101   #define PROG_IMAGE_LAYER_ID 102   #define PROG_IMAGE_FONT_ID 103   #define PROG_IMAGE_COLOR_COLOR_ID 200   #define PROG_STDIO_FD_ID 1   
pike.git/src/post_modules/GTK2/build_pgtk.pike:66:    string line = "\"";    string res = "";    int c;    for( int i=0; i<sizeof( from ); i++ )    {    switch( (c=from[i]) )    {    case '.':    case 'a'..'z':    case 'A'..'Z': -  case 0300..0376: // 377 breaks some versions of gcc. +     case '_': case ' ':    line += from[i..i];    break;    default:    line += sprintf("\\%o", c );    break;    }    if( sizeof( line ) > 75 )    {    res += line+"\"\n";
pike.git/src/post_modules/GTK2/build_pgtk.pike:139:    what = what[1..];    }    foreach(what[1..]/"", string q)    if(lower_case(q)==q)    res += q;    else    res += "_"+lower_case(q);    return res;   }    - class Function(Class parent, + class GtkFunction(Class parent,    string name,    Type return_type,    array(Type) arg_types,    array(string) arg_names,    mixed body,    array require,    string doc,    string file,    int line)   {    protected string _sprintf(int fmt)    { -  return fmt=='O' && sprintf("Function( %O, %O )",name, return_type ); +  return fmt=='O' && sprintf("GtkFunction( %O, %O )",name, return_type );    }       string pike_type( )    {    if(!return_type)    return 0;    string rt = return_type->pike_type( 1 ); -  if( parent->name != "_global" && has_prefix(rt, "void" ) ) +  if( parent->name != "_global" && has_prefix(rt, "void" ) ) { +  if ((name != "create") && (name != "_destruct")) {    rt = parent->pike_type( 1 ); -  +  } +  }    array res = ({ });    foreach( arg_types, Type t )    {    if( t->name != "null" )    res += ({ t->pike_type( 0 ) });    }    return "function("+ res*"," +":"+rt+")";    }       string pike_name()
pike.git/src/post_modules/GTK2/build_pgtk.pike:225:    case "intersect": names += ({ "`&" }); break;    case "equal": names += ({ "`==" }); break;    case "lt": names += ({ "`<" }); break;    case "gt": names += ({ "`>" }); break;    case "xor": names += ({ "`^" }); break;    case "not": names += ({ "`~" }); break;    case "_add": names += ({ "`+" }); break;    case "_index": names += ({ "`[]", "`->" }); break;    }    -  +     foreach( names, string n ) low_do_emit( n );    return res;    }       protected string prefix( Class c )    {    if( c->c_name() == "" )    return "pgtk";    return "p"+c->c_name(); -  +     }       string c_name( )    {    string res;    string base = parent->c_name();    if( parent->c_name() == "" )    res="gtk_"+name;    else if( name == "create" )    res=base+"_new";
pike.git/src/post_modules/GTK2/build_pgtk.pike:354:    emit( (name=="create"?"":", ")+(args*", ") );    emit( " );\n");    if( return_type->name != "void" )    {    emit(" my_pop_n_elems(args);\n");    emit(" "+return_type->push( "a"+rv )+"\n");    emit(" }\n");    }    else    { -  if( name != "create" ) +  if( (name != "create" ) && (name != "_destruct") )    emit(" RETURN_THIS();\n");    else    {    emit( " my_pop_n_elems( args );\n" );    emit( " push_int( 0 );\n" );    }    }    a = 0;    foreach( arg_types, Type t )    {
pike.git/src/post_modules/GTK2/build_pgtk.pike:400:    }       protected string _sprintf(int fmt)    {    return fmt=='O' && sprintf("Signal( %O )",name );    }   }      string function_type( string what )   { -  return __parse_pike_type( String.trim_all_whites( what ) ); +  return __parse_pike_type( String.trim( what ) );   }      class Member( string name, Type type, int set,    string file, int line, Class parent )   {    string doc = "";       int is_protected(){ return 0; }       string pike_type( )
pike.git/src/post_modules/GTK2/build_pgtk.pike:546:    string doc_type( )    {    if( subtypes )    return subtypes->doc_type()*"|";    string optp = "";    if( opt )    optp = "|void";    switch( name )    {    case "uint": -  return "int"+optp; +  return "int(0..)"+optp; +  case "bool": +  return "int(0..1)"+optp;    case "array":    if( array_type )    return "array("+array_type->doc_type()+")"+optp;    return name+optp;       case "double": /* int can be used for better precision */    return "int|float"+optp;       case "callback":    return "callback"+optp;
pike.git/src/post_modules/GTK2/build_pgtk.pike:587:       string pike_type( int is, int|void nc )    {    if( subtypes )    return subtypes->pike_type(is,1)*"|"+(opt?"|void":"");    string optp = "";    if( opt )    optp = "|void";    switch( name )    { +  case "Stdio.Buffer": +  return "object";    case "uint": -  return "int"+optp; +  return "int(0..)"+optp; +  case "bool": +  return "int(0..1)";    case "array":    if( !nc && !c_inited )    catch(c_init());    if( array_type )    return "array("+array_type->pike_type(is,1)+")"+optp;    /* fall-through */    case "int":    case "string":    case "string...":    case "mixed":
pike.git/src/post_modules/GTK2/build_pgtk.pike:643:    name = "GTK.CTreeNode";   */       default:    if( classes[ name ] )    if( nc || opt )    return classes[ name ]->pike_type(is) + optp;    else    return (is ? classes[ name ]->pike_type(1) :    (classes[ name ]->pike_type(0)+ "|zero")); -  throw(sprintf("Unknown type %O", this_object())); +  throw(sprintf("Unknown type %O", this));    return "mixed"+optp;    }    }       void create( string n )    {    array q = n/"|";    if( sizeof(q) != 1 )    {    subtypes = map( q, Type );
pike.git/src/post_modules/GTK2/build_pgtk.pike:734:    {    if(!c_inited) c_init();    if( amp ) vv = "&("+vv+")";    if( star ) vv = "*("+vv+")";       switch( name )    {    case "array":    if( !array_size )    throw(sprintf("Cannot push array of unknown size (%O)", -  this_object())); +  this));    if( !array_type ) throw("Cannot push array(mixed)");    return    " {\n"    " int i;\n"    " for( i = 0; i<"+array_size+"; i++ )\n"    " "+array_type->direct_push( "("+vv+"[i])" )+"\n"    " f_aggregate( i );\n"    " }\n";       default:
pike.git/src/post_modules/GTK2/build_pgtk.pike:790:    switch( name )    {    case "string":    _push = " PGTK_PUSH_GCHAR( %s );";    if( has_value( get_modifiers(), "free" ) )    _push += "\n g_free( %[0]s );";    return sprintf( _push, vv );       case "int":    case "uint": +  case "bool":    return sprintf( (_push = " PGTK_PUSH_INT( %s );"), vv );       case "float":    case "double":    return sprintf( (_push=" push_float( (FLOAT_TYPE)%s );"), vv );       default:    if( plus )    return sprintf( (_push=" push_gobject( %s );"), vv );    if( classes[name] )    return classes[name]->push( vv ); -  throw(sprintf("Cannot push %O, %s is not a class", this_object(), +  throw(sprintf("Cannot push %O, %s is not a class", this,    name));    }    }    -  +     protected void c_init()    {    c_inited = 1;    if( subtypes )    {    throw(sprintf("Complex types cannot be handled automatically (%O)\n", -  this_object())); +  this));    }    if( Class c = classes[ name ] )    {    declare = classes[name]->c_declare( -1 );    fetch = classes[name]->c_fetch_from_stack( -1 );    pass = classes[name]->c_pass_to_function( -1 );    }    else switch( name )    {    case "null":    declare = 0;    fetch = 0;    pass = "NULL";    consumed = 0;    break;       case "function":    if( modifiers != "callback" )    {    throw(sprintf("Complex types cannot be handled automatically (%O)\n", -  this_object())); +  this));    }       /* Fallthrough */    case "callback": /* actually 2 args */    consumed = 2;    declare = (" struct signal_data *cb%[0]d = 0;\n");    fetch =(" cb%[0]d = (void*)xalloc( sizeof( struct signal_data ) );\n"    " assign_svalue_no_free(&cb%[0]d->cb, Pike_sp+%[0]d-args);\n"    " assign_svalue_no_free(&cb%[0]d->args,Pike_sp+%[0]d+1-args);\n");   
pike.git/src/post_modules/GTK2/build_pgtk.pike:856:    break;       case "int":    case "uint":    declare = " gint a%[0]d = 0;\n";    if( name == "uint")    declare = " guint a%[0]d = 0;\n";    fetch = " a%[0]d = (gint)PGTK_GETINT(&Pike_sp[%[0]d-args]);\n";    pass = "a%[0]d";    break; +  case "bool": +  declare = " gboolean a%[0]d = 0;\n"; +  fetch = " a%[0]d = !!(gint)PGTK_GETINT(&Pike_sp[%[0]d-args]);\n"; +  pass = "a%[0]d"; +  break;       case "float":    declare = " gfloat a%[0]d = 0;\n";    fetch = " a%[0]d = (gfloat)PGTK_GETFLT(&Pike_sp[%[0]d-args]);\n";    pass = "a%[0]d";    break;       case "double":    declare = " gdouble a%[0]d = 0;\n";    fetch = " a%[0]d = (gint)PGTK_GETFLT(&Pike_sp[%[0]d-args]);\n";
pike.git/src/post_modules/GTK2/build_pgtk.pike:960:    {    if( array_type ||    !(array_type = parse_type( SPLIT( opt, "type" ) ) ) )    throw( sprintf("Unknown array option %O\n", opt) );    }    break;    }    }   // if(!sub && !array_type)   // { - // throw( sprintf("Cannot push %O", this_object()) ); + // throw( sprintf("Cannot push %O", this) );   // }    declare = " int _i%[0]d;\n struct array *_a%[0]d = 0;\n " +    "CONST "+sub+"\n";    pass = "a%d";    fetch =   #"    if( TYPEOF(Pike_sp[%[0]d-args]) != PIKE_T_ARRAY )    Pike_error("+S("Bad argument %d, expected array\n", 1,0,16)+#",\n %[0]d);    _a%[0]d = Pike_sp[%[0]d-args].u.array;   "+(check_size||"")+
pike.git/src/post_modules/GTK2/build_pgtk.pike:1017:       if( star ) pass = "*"+pass;    if( amp ) pass = "&"+pass;    }       int c_stack_consumed( int a )    {    if( !c_inited )c_init();    return consumed;    } -  string c_declare( int a, int|void const ) +  string c_declare( int a, int|void is_const )    {    if( !c_inited )c_init();    c_declared = 1;    if(!declare) return 0; -  if( const && +  if( is_const &&    (!free || (pushed && !has_value (get_modifiers(), "free"))) )    return sprintf( replace( declare, "CONST", "const" ), a );    return sprintf( replace( declare, "CONST", "" ), a ); -  +     }       string c_free( int a )    {    if( !c_inited )c_init();    return free && sprintf(free, a);    }       string c_fetch_from_stack( int a )    {
pike.git/src/post_modules/GTK2/build_pgtk.pike:1062:    return sprintf(pass,a);    }    }   }      int last_class_id = 2000;      class Class( string name, string file, int line )   {    array(Class) inherits = ({}); -  mapping(string:Function) functions = ([]); -  mapping(string:Signal) signals = ([]); -  mapping(string:Member) members = ([]); -  mapping(string:Property) properties= ([]); +  mapping(string:GtkFunction) functions = ([]); +  mapping(string:Signal) signals = ([]); +  mapping(string:Member) members = ([]); +  mapping(string:Property) properties= ([]);    string doc = "";    Class mixin_for;       array pre = ({});    string post = "";    array init = ({});    array exit = ({});       string _pass;    string _fetch;
pike.git/src/post_modules/GTK2/build_pgtk.pike:1112:    {    if( sscanf(name, "GTK2.%s", string pn ) )    return pn;    return (replace(replace(name,"GDK2","Gdk"),"PANGO","Pango")-".");    }          void create_default_sprintf( )    {    if( name == "_global" || mixin_for ) return 0; -  add_function( Function(this_object(), +  add_function( GtkFunction(this,    "_sprintf",    Type("string"), ({    Type("int"),    Type("mapping")    }), ({    "flags",    "options",    }),    SPLIT(    "{\n pgtk2_default__sprintf( args, "+
pike.git/src/post_modules/GTK2/build_pgtk.pike:1141:    void create_init_exit( )    {    if( !sizeof(inherits) && name != "_global" )    init = SPLIT((mixin_for?    "{\n pgtk2_setup_mixin( object, "+    glue_c_name(mixin_for->c_name())+"_program);\n}\n"    : "{\n pgtk2_clear_obj_struct( object );\n}\n"),    file) + init;       if( sizeof(init) ) -  add_function( Function(this_object(), "_init", 0, ({}), ({}), +  add_function( GtkFunction(this, "_init", 0, ({}), ({}),    init, ({}), "", file, line ) );    if( sizeof(exit) ) -  add_function( Function(this_object(), "_exit", 0, ({}), ({}), +  add_function( GtkFunction(this, "_exit", 0, ({}), ({}),    exit, ({}), "", file, line ) );    }       string c_type_define()    {    array q = c_name()/"_";    return upper_case( q[0]+"_TYPE_"+(q[1..]*"_") );    }       int is_gobject()
pike.git/src/post_modules/GTK2/build_pgtk.pike:1317:    return sprintf( _push, vv );    }       string direct_push( string x, int amp, int star )    {    if( amp ) x = "&("+x+")";    if( star) x = "*("+x+")";    return push( x );    }    -  +     protected string _sprintf(int fmt)    {    return fmt=='O' && sprintf("Class( %O /* %d funcs. */ )",name,    sizeof(functions)+sizeof(members)+    sizeof(properties)); -  +     }       class Ref( string file, int line, Class c ) { }       array(Ref) references = ({ });       Class add_function( object f )    {    functions[ f->name ] = f; -  return this_object(); +  return this;    }       Class add_signal( Signal s )    {    signals[ s->name ] = s; -  return this_object(); +  return this;    }       Class add_member( Member m )    {    members[ m->name ] = m; -  return this_object(); +  return this;    }       Class add_property( Property p )    {    properties[ p->name ] = p; -  return this_object(); +  return this;    }       Class add_ref( string f, int l, Class c )    {    references += ({ Ref( f, l, c ) }); -  return this_object(); +  return this;    }       Class add_init( array code )    {    init += code; -  return this_object(); +  return this;    }       Class add_exit( array code )    {    exit += code; -  return this_object(); +  return this;    }   }      mapping(string:Class) classes = ([]);   mapping(string:Constant) constants = ([]);   array global_pre = ({});      class Constant( string name, Type type, string file, int line )   {    string doc = "";
pike.git/src/post_modules/GTK2/build_pgtk.pike:1498:    case "sprintf_format":    case "sprintf_args...":    case "null":    case "void":    case "function":    case "callback":    case "array":    case "Stdio.File":    case "Image.Image":    case "Image.Color.Color": +  case "bool":    break;    default:    if( ty->name[0..0] != "G" && ty->name[0..0] != "P" && ty->name[0..0] != "A" )    SYNTAX(sprintf("%O is not a valid type",tt),t);    }    return ty;   }      int is_identifier( object t )   {
pike.git/src/post_modules/GTK2/build_pgtk.pike:1854:    break;    }       if( !body || (arrayp(body) && (body[0] != "{" || body[-1] != "}"))    || (objectp(body) && body!=";" ))    SYNTAX("Expected ; or function block",    (arrayp(body)?body[0]:body||token));    [arg_types,arg_names] = parse_args( args[1..sizeof(args)-2] );    if( arrayp(body) )    make_strings(body); -  Function f = Function( current_class, name->text, type, +  GtkFunction f = GtkFunction( current_class, name->text, type,    arg_types, arg_names, body,    current_require, doc, file, token->line );    current_class->add_function( f );    current_scope = f;    }    }    else /* token is an array (group) */    {    SYNTAX(token[0]->text+" not expected here",token[0]);    }
pike.git/src/post_modules/GTK2/build_pgtk.pike:1992:    destination_dir = combine_path( getcwd(), destination_dir );    if (destination_dir[-1] != '/')    destination_dir += "/";       if (signum("PIPE") >= 0) {    // It seems the combination Solaris + ABI64 + Xenofarm    // gets a SIGPIPE on writing to stderr.    signal(signum("PIPE"), sigpipe_handler);    }    -  if ((uname()->sysname == "SunOS") && (Pike.get_runtime_info()->abi == 64)) { -  // There seems to be some sort of problem with SIGPIPE on Solaris/ABI64. -  show_fds(); -  } -  +     if(!output)    {    werror("You must specify an output plugin\n");    exit(1);    }       add_constant( "Class", Class );    add_constant( "unsillycaps", unsillycaps );    add_constant( "Type", Type );    add_constant( "S", S );    add_constant( "data_offset", data_offset );    add_constant( "get_string_data", get_string_data );       object|array(object) q;    add_constant( "Node", typeof( q ) ); -  add_constant( "Function", Function ); +  add_constant( "GtkFunction", GtkFunction );    add_constant( "Constant", Constant );    add_constant( "COMPOSE", Parser.Pike.reconstitute_with_line_numbers );    object output_plugin = ((program)output)( source_dir, destination_dir, -  this_object() ); +  this );       if (string files = Stdio.read_file (destination_dir + "/files_to_compile")) {    int ok = 1;    foreach (files / " ", string file)    if (!file_stat (destination_dir + "/" + file)) {ok = 0; break;}    if( ok && output_plugin->up_to_date() )    {    exit(0);    }    }