X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftypes%2Fnum_exp.h;h=e1b3b223beab9635c27e86fd490ebfaea9fa095b;hp=c54a5af0b1f18c3e39074deebd90070c96d89743;hb=2f5af21b263403997e154658635d6b6e6eaab453;hpb=898c6dac30d12d7fe56662d66a8e73c340926d64 diff --git a/src/types/num_exp.h b/src/types/num_exp.h index c54a5af..e1b3b22 100644 --- a/src/types/num_exp.h +++ b/src/types/num_exp.h @@ -1,5 +1,36 @@ -#ifndef _PSI_TYPES_NUM_EXP -#define _PSI_TYPES_NUM_EXP +/******************************************************************************* + Copyright (c) 2016, Michael Wallner . + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * 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 PSI_TYPES_NUM_EXP +#define PSI_TYPES_NUM_EXP + +#include "token.h" + +#include "constant.h" +#include "decl_var.h" +#include "impl_val.h" typedef struct num_exp { struct psi_token *token; @@ -15,71 +46,16 @@ typedef struct num_exp { struct num_exp *operand; } num_exp; -static inline num_exp *init_num_exp(token_t t, void *num) { - num_exp *exp = calloc(1, sizeof(*exp)); - switch (exp->t = t) { - case PSI_T_NUMBER: - case PSI_T_NSNAME: - exp->u.numb = strdup(num); - break; - case PSI_T_NAME: - exp->u.dvar = num; - break; - EMPTY_SWITCH_DEFAULT_CASE(); - } - return exp; -} - -static inline num_exp *copy_num_exp(num_exp *exp) { - decl_var *dvar; - num_exp *num = calloc(1, sizeof(*num)); - - memcpy(num, exp, sizeof(*num)); +num_exp *init_num_exp(token_t t, void *num); +num_exp *copy_num_exp(num_exp *exp); +void free_num_exp(num_exp *exp); +void dump_num_exp(int fd, num_exp *exp); - if (num->token) { - num->token = psi_token_copy(num->token); - } - if (num->operand) { - num->operand = copy_num_exp(num->operand); - } - switch (num->t) { - case PSI_T_NUMBER: - case PSI_T_NSNAME: - num->u.numb = strdup(num->u.numb); - break; - case PSI_T_NAME: - dvar = init_decl_var(num->u.dvar->name, num->u.dvar->pointer_level, num->u.dvar->array_size); - dvar->arg = num->u.dvar->arg; - if (num->u.dvar->token) { - dvar->token = psi_token_copy(num->u.dvar->token); - } - num->u.dvar = dvar; - break; - } - return num; -} +struct psi_data; +struct decl_args; +struct decl_arg; +struct decl_enum; -static inline void free_num_exp(num_exp *exp) { - if (exp->token) { - free(exp->token); - } - switch (exp->t) { - case PSI_T_NUMBER: - free(exp->u.numb); - break; - case PSI_T_NSNAME: - break; - case PSI_T_NAME: - free_decl_var(exp->u.dvar); - break; - case PSI_T_ENUM: - break; - EMPTY_SWITCH_DEFAULT_CASE(); - } - if (exp->operand) { - free_num_exp(exp->operand); - } - free(exp); -} +int validate_num_exp(struct psi_data *data, num_exp *exp, struct decl_args *dargs, struct decl_arg *func, struct decl_enum *enm); #endif