/* * Copyright (c) 2005 - 2006, Nils R. Weller * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef SUBEXPR_H #define SUBEXPR_H struct builtin; struct icode_list; struct token; struct vreg; struct ty_func; struct var_access { struct icode_instr *ii; struct var_access *next; struct var_access *prev; }; struct fetch_data { int type; #define FETCH_STRUMEM 1 #define FETCH_CONSTANT 2 #define FETCH_VARIABLE 3 #define FETCH_ADDRESS 4 struct decl *dec; struct token *constant; }; struct store_data { int type; #define STORE_STRUMEM 1 #define STORE_CONSTANT 2 #define STORE_VARIABLE 3 struct reg *fromreg; struct decl *to_var; }; struct fcall_data { struct builtin_data *builtin; struct decl *callto; struct vreg *calltovr; struct expr *args; struct ty_func *functype; struct vreg *lvalue; int nargs; }; struct s_expr { struct s_expr *next; struct icode_list *code; struct type *type; struct vreg *load; struct vreg *res; struct token *load_token; struct expr *is_expr; struct decl *var_lvalue; struct token *operators[128]; struct token *meat; struct token *is_sizeof; /* IMPORTANT: May not have same value as token.h macros ... */ #define SIZEOF_EXPR 1000 int is_lvalue; int only_load; int extype; int idiom; #define IDIOM_STAR_INC 1 /* *p++ */ #define IDIOM_STAR_DEC 2 /* *p-- */ #define IDIOM_INC_STAR 3 /* *++p */ #define IDIOM_DEC_STAR 4 /* *--p */ #define IDIOM_PAR_STAR_INC 5 /* (*p)++ */ #define IDIOM_PAR_INC_STAR 6 /* ++*p or ++(*p) */ #define IDIOM_PAR_STAR_DEC 7 /* (*p)-- */ #define IDIOM_PAR_DEC_STAR 8 /* --*p or --(*p) */ #define IDIOM_ADDR_OF_ELEM 10 /* &foo[bar] */ #define IDIOM_ADDR_OF_MEM 11 /* &foo.bar or &foo->bar */ }; struct s_expr * get_sub_expr(struct token **tok, int delim, int delim2, int extype); struct vreg * s_expr_to_icode(struct s_expr *s, struct vreg *lvalue, struct icode_list *il, int eval); struct fcall_data * alloc_fcall_data(void); #endif