/* * TCC - Tiny C Compiler * * Copyright (c) 2001-2004 Fabrice Bellard * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "tcc.h" /********************************************************/ /* global variables */ /* display benchmark infos */ int total_lines; int total_bytes; /* parser */ static struct BufferedFile *file; static int ch, tok; static CValue tokc; static CString tokcstr; /* current parsed string, if any */ /* additional informations about token */ static int tok_flags; #define TOK_FLAG_BOL 0x0001 /* beginning of line before */ #define TOK_FLAG_BOF 0x0002 /* beginning of file before */ #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */ #define TOK_FLAG_EOF 0x0008 /* end of file */ static int *macro_ptr, *macro_ptr_allocated; static int *unget_saved_macro_ptr; static int unget_saved_buffer[TOK_MAX_SIZE + 1]; static int unget_buffer_enabled; static int parse_flags; #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */ #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */ #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a token. line feed is also returned at eof */ #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */ #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ static Section *text_section, *data_section, *bss_section; /* predefined sections */ static Section *cur_text_section; /* current section where function code is generated */ #ifdef CONFIG_TCC_ASM static Section *last_text_section; /* to handle .previous asm directive */ #endif /* bound check related sections */ static Section *bounds_section; /* contains global data bound description */ static Section *lbounds_section; /* contains local data bound description */ /* symbol sections */ static Section *symtab_section, *strtab_section; /* debug sections */ static Section *stab_section, *stabstr_section; /* loc : local variable index ind : output code index rsym: return symbol anon_sym: anonymous symbol index */ static int rsym, anon_sym, ind, loc; /* expression generation modifiers */ static int const_wanted; /* true if constant wanted */ static int nocode_wanted; /* true if no code generation wanted for an expression */ static int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ static CType func_vt; /* current function return type (used by return instruction) */ static int func_vc; static int last_line_num, last_ind, func_ind; /* debug last line number and pc */ static int tok_ident; static TokenSym **table_ident; static TokenSym *hash_ident[TOK_HASH_SIZE]; static char token_buf[STRING_MAX_SIZE + 1]; static char *funcname; static Sym *global_stack, *local_stack; static Sym *define_stack; static Sym *global_label_stack, *local_label_stack; /* symbol allocator */ #define SYM_POOL_NB (8192 / sizeof(Sym)) static Sym *sym_free_first; static void **sym_pools; static int nb_sym_pools; static SValue vstack[VSTACK_SIZE], *vtop; /* some predefined types */ static CType char_pointer_type, func_old_type, int_type; /* use GNU C extensions */ static int gnu_ext = 1; /* use Tiny C extensions */ static int tcc_ext = 1; /* max number of callers shown if error */ #ifdef CONFIG_TCC_BACKTRACE int num_callers = 6; const char **rt_bound_error_msg; #endif /* XXX: get rid of this ASAP */ static struct TCCState *tcc_state; /********************************************************/ /* function prototypes */ /* tccpp.c */ static void next(void); char *get_tok_str(int v, CValue *cv); /* tccgen.c */ static void parse_expr_type(CType *type); static void expr_type(CType *type); static void unary_type(CType *type); static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr); static int expr_const(void); static void expr_eq(void); static void gexpr(void); static void gen_inline_functions(void); static void decl(int l); static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only); static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope); int gv(int rc); void gv2(int rc1, int rc2); void move_reg(int r, int s); void save_regs(int n); void save_reg(int r); void vpop(void); void vswap(void); void vdup(void); int get_reg(int rc); int get_reg_ex(int rc,int rc2); void gen_op(int op); void force_charshort_cast(int t); static void gen_cast(CType *type); void vstore(void); static Sym *sym_find(int v); static Sym *sym_push(int v, CType *type, int r, int c); /* type handling */ static int type_size(CType *type, int *a); static inline CType *pointed_type(CType *type); static int pointed_size(CType *type); static int lvalue_type(int t); static int parse_btype(CType *type, AttributeDef *ad); static void type_decl(CType *type, AttributeDef *ad, int *v, int td); static int compare_types(CType *type1, CType *type2, int unqualified); static int is_compatible_types(CType *type1, CType *type2); static int is_compatible_parameter_types(CType *type1, CType *type2); int ieee_finite(double d); void vpushi(int v); void vpushll(long long v); void vrott(int n); void vnrott(int n); void lexpand_nr(void); static void vpush_global_sym(CType *type, int v); void vset(CType *type, int r, int v); void type_to_str(char *buf, int buf_size, CType *type, const char *varstr); static Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size); static Sym *external_global_sym(int v, CType *type, int r); /* section generation */ static void section_realloc(Section *sec, unsigned long new_size); static void *section_ptr_add(Section *sec, unsigned long size); static void put_extern_sym(Sym *sym, Section *section, unsigned long value, unsigned long size); static void greloc(Section *s, Sym *sym, unsigned long addr, int type); static int put_elf_str(Section *s, const char *sym); static int put_elf_sym(Section *s, unsigned long value, unsigned long size, int info, int other, int shndx, const char *name); static int add_elf_sym(Section *s, unsigned long value, unsigned long size, int info, int other, int sh_num, const char *name); static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol); static void put_stabs(const char *str, int type, int other, int desc, unsigned long value); static void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index); static void put_stabn(int type, int other, int desc, int value); static void put_stabd(int type, int other, int desc); static int tcc_add_dll(TCCState *s, const char *filename, int flags); #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */ #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ #define AFF_PREPROCESS 0x0004 /* preprocess file */ static int tcc_add_file_internal(TCCState *s, const char *filename, int flags); /* tcccoff.c */ int tcc_output_coff(TCCState *s1, FILE *f); /* tccpe.c */ void *resolve_sym(TCCState *s1, const char *sym, int type); int pe_load_def_file(struct TCCState *s1, int fd); int pe_test_res_file(void *v, int size); int pe_load_res_file(struct TCCState *s1, int fd); void pe_add_runtime(struct TCCState *s1); void pe_guess_outfile(char *objfilename, int output_type); int pe_output_file(struct TCCState *s1, const char *filename); /* tccasm.c */ #ifdef CONFIG_TCC_ASM static void asm_expr(TCCState *s1, ExprValue *pe); static int asm_int_expr(TCCState *s1); static int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); static int tcc_assemble(TCCState *s1, int do_preprocess); #endif static void asm_instr(void); static void asm_global_instr(void); /********************************************************/ /* global variables */ #ifdef TCC_TARGET_I386 #include "i386-gen.c" #endif #ifdef TCC_TARGET_ARM #include "arm-gen.c" #endif #ifdef TCC_TARGET_C67 #include "c67-gen.c" #endif #ifdef TCC_TARGET_X86_64 #include "x86_64-gen.c" #endif #ifdef CONFIG_TCC_STATIC #define RTLD_LAZY 0x001 #define RTLD_NOW 0x002 #define RTLD_GLOBAL 0x100 #define RTLD_DEFAULT NULL /* dummy function for profiling */ void *dlopen(const char *filename, int flag) { return NULL; } void dlclose(void *p) { } const char *dlerror(void) { return "error"; } typedef struct TCCSyms { char *str; void *ptr; } TCCSyms; #define TCCSYM(a) { #a, &a, }, /* add the symbol you want here if no dynamic linking is done */ static TCCSyms tcc_syms[] = { #if !defined(CONFIG_TCCBOOT) TCCSYM(printf) TCCSYM(fprintf) TCCSYM(fopen) TCCSYM(fclose) #endif { NULL, NULL }, }; void *resolve_sym(TCCState *s1, const char *symbol, int type) { TCCSyms *p; p = tcc_syms; while (p->str != NULL) { if (!strcmp(p->str, symbol)) return p->ptr; p++; } return NULL; } #elif !defined(_WIN32) #include void *resolve_sym(TCCState *s1, const char *sym, int type) { return dlsym(RTLD_DEFAULT, sym); } #endif /********************************************************/ /* we use our own 'finite' function to avoid potential problems with non standard math libs */ /* XXX: endianness dependent */ int ieee_finite(double d) { int *p = (int *)&d; return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31; } /* copy a string and truncate it. */ char *pstrcpy(char *buf, int buf_size, const char *s) { char *q, *q_end; int c; if (buf_size > 0) { q = buf; q_end = buf + buf_size - 1; while (q < q_end) { c = *s++; if (c == '\0') break; *q++ = c; } *q = '\0'; } return buf; } /* strcat and truncate. */ char *pstrcat(char *buf, int buf_size, const char *s) { int len; len = strlen(buf); if (len < buf_size) pstrcpy(buf + len, buf_size - len, s); return buf; } /* extract the basename of a file */ char *tcc_basename(const char *name) { char *p = strchr(name, 0); while (p > name && !IS_PATHSEP(p[-1])) --p; return p; } char *tcc_fileextension (const char *name) { char *b = tcc_basename(name); char *e = strrchr(b, '.'); return e ? e : strchr(b, 0); } #ifdef _WIN32 char *normalize_slashes(char *path) { char *p; for (p = path; *p; ++p) if (*p == '\\') *p = '/'; return path; } void tcc_set_lib_path_w32(TCCState *s) { /* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */ char path[1024], *p; GetModuleFileNameA(NULL, path, sizeof path); p = tcc_basename(normalize_slashes(strlwr(path))); if (p - 5 > path && 0 == strncmp(p - 5, "/bin/", 5)) p -= 5; else if (p > path) p--; *p = 0; tcc_set_lib_path(s, path); } #endif void set_pages_executable(void *ptr, unsigned long length) { #ifdef _WIN32 unsigned long old_protect; VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect); #else unsigned long start, end; start = (unsigned long)ptr & ~(PAGESIZE - 1); end = (unsigned long)ptr + length; end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1); mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC); #endif } /* memory management */ #ifdef MEM_DEBUG int mem_cur_size; int mem_max_size; unsigned malloc_usable_size(void*); #endif void tcc_free(void *ptr) { #ifdef MEM_DEBUG mem_cur_size -= malloc_usable_size(ptr); #endif free(ptr); } void *tcc_malloc(unsigned long size) { void *ptr; ptr = malloc(size); if (!ptr && size) error("memory full"); #ifdef MEM_DEBUG mem_cur_size += malloc_usable_size(ptr); if (mem_cur_size > mem_max_size) mem_max_size = mem_cur_size; #endif return ptr; } void *tcc_mallocz(unsigned long size) { void *ptr; ptr = tcc_malloc(size); memset(ptr, 0, size); return ptr; } void *tcc_realloc(void *ptr, unsigned long size) { void *ptr1; #ifdef MEM_DEBUG mem_cur_size -= malloc_usable_size(ptr); #endif ptr1 = realloc(ptr, size); #ifdef MEM_DEBUG /* NOTE: count not correct if alloc error, but not critical */ mem_cur_size += malloc_usable_size(ptr1); if (mem_cur_size > mem_max_size) mem_max_size = mem_cur_size; #endif return ptr1; } char *tcc_strdup(const char *str) { char *ptr; ptr = tcc_malloc(strlen(str) + 1); strcpy(ptr, str); return ptr; } #define free(p) use_tcc_free(p) #define malloc(s) use_tcc_malloc(s) #define realloc(p, s) use_tcc_realloc(p, s) void dynarray_add(void ***ptab, int *nb_ptr, void *data) { int nb, nb_alloc; void **pp; nb = *nb_ptr; pp = *ptab; /* every power of two we double array size */ if ((nb & (nb - 1)) == 0) { if (!nb) nb_alloc = 1; else nb_alloc = nb * 2;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.gui.widgets.titlebar</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.<a href="ranger.gui.html"><font color="#ffffff">gui</font></a>.<a href="ranger.gui.widgets.html"><font color="#ffffff">widgets</font></a>.titlebar</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/ranger/gui/widgets/titlebar.py">/home/hut/work/ranger/ranger/gui/widgets/titlebar.py</a></font></td></tr></table>
    <p><tt>The&nbsp;<a href="#TitleBar">TitleBar</a>&nbsp;widget&nbsp;displays&nbsp;the&nbsp;current&nbsp;path&nbsp;and&nbsp;some&nbsp;other&nbsp;useful<br>
information.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="builtins.html#list">builtins.list</a>(<a href="builtins.html#object">builtins.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.titlebar.html#BarSide">BarSide</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.titlebar.html#Bar">Bar</a>
</font></dt><dt><font face="helvetica, arial"><a href="ranger.gui.widgets.titlebar.html#ColoredString">ColoredString</a>
</font></dt></dl>
</dd>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.html#Widget">ranger.gui.widgets.Widget</a>(<a href="ranger.gui.displayable.html#Displayable">ranger.gui.displayable.Displayable</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="ranger.gui.widgets.titlebar.html#TitleBar">TitleBar</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Bar">class <strong>Bar</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Bar-__init__"><strong>__init__</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-add"><strong>add</strong></a>(self, *a, **kw)</dt></dl>

<dl><dt><a name="Bar-addright"><strong>addright</strong></a>(self, *a, **kw)</dt></dl>

<dl><dt><a name="Bar-combine"><strong>combine</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-fill_gap"><strong>fill_gap</strong></a>(self, char, wid, gapwidth<font color="#909090">=False</font>)</dt></dl>

<dl><dt><a name="Bar-fixedsize"><strong>fixedsize</strong></a>(self)</dt></dl>

<dl><dt><a name="Bar-shrink_by_cutting"><strong>shrink_by_cutting</strong></a>(self, wid)</dt></dl>

<dl><dt><a name="Bar-shrink_by_removing"><strong>shrink_by_removing</strong></a>(self, wid)</dt></dl>

<dl><dt><a name="Bar-sumsize"><strong>sumsize</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Data and other attributes defined here:<br>
<dl><dt><strong>gap</strong> = None</dl>

<dl><dt><strong>left</strong> = None</dl>

<dl><dt><strong>right</strong> = None</dl>

</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="BarSide">class <strong>BarSide</strong></a>(<a href="builtins.html#list">builtins.list</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="ranger.gui.widgets.titlebar.html#BarSide">BarSide</a></dd>
<dd><a href="builtins.html#list">builtins.list</a></dd>
<dd><a href="builtins.html#object">builtins.object</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="BarSide-add"><strong>add</strong></a>(self, string, *lst, **kw)</dt></dl>

<dl><dt><a name="BarSide-fixedsize"><strong>fixedsize</strong></a>(self)</dt></dl>

<dl><dt><a name="BarSide-nonfixed_items"><strong>nonfixed_items</strong></a>(self)</dt></dl>

<dl><dt><a name="BarSide-sumsize"><strong>sumsize</strong></a>(self)</dt></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<hr>
Methods inherited from <a href="builtins.html#list">builtins.list</a>:<br>
<dl><dt><a name="BarSide-__add__"><strong>__add__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__add__">__add__</a>(y)&nbsp;&lt;==&gt;&nbsp;x+y</tt></dd></dl>

<dl><dt><a name="BarSide-__contains__"><strong>__contains__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__contains__">__contains__</a>(y)&nbsp;&lt;==&gt;&nbsp;y&nbsp;in&nbsp;x</tt></dd></dl>

<dl><dt><a name="BarSide-__delitem__"><strong>__delitem__</strong></a>(...)</dt>&l