2006-03-03 11:45:45 +00:00
|
|
|
/*
|
2007-02-23 08:17:51 +00:00
|
|
|
* $Id: val.h,v 1.62 2007-02-23 08:17:51 bacon Exp $
|
2007-02-03 10:52:36 +00:00
|
|
|
*
|
|
|
|
* {License}
|
2006-03-03 11:45:45 +00:00
|
|
|
*/
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
#ifndef _ASE_AWK_VAL_H_
|
|
|
|
#define _ASE_AWK_VAL_H_
|
2006-03-03 11:45:45 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
#ifndef _ASE_AWK_AWK_H_
|
2007-01-14 15:08:01 +00:00
|
|
|
#error Include <ase/awk/awk.h> first
|
2006-03-03 11:45:45 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-23 08:17:51 +00:00
|
|
|
#include <ase/cmn/str.h>
|
2007-01-14 15:08:01 +00:00
|
|
|
#include <ase/awk/map.h>
|
|
|
|
|
2006-11-19 11:55:17 +00:00
|
|
|
enum ase_awk_val_type_t
|
2006-03-04 15:54:37 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
|
2006-09-28 06:58:10 +00:00
|
|
|
* must be synchronized with an internal table of the __cmp_val
|
|
|
|
* function in run.c */
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_NIL = 0,
|
|
|
|
ASE_AWK_VAL_INT = 1,
|
|
|
|
ASE_AWK_VAL_REAL = 2,
|
|
|
|
ASE_AWK_VAL_STR = 3,
|
|
|
|
|
|
|
|
ASE_AWK_VAL_REX = 4,
|
|
|
|
ASE_AWK_VAL_MAP = 5,
|
|
|
|
ASE_AWK_VAL_REF = 6
|
2006-08-20 15:49:48 +00:00
|
|
|
};
|
|
|
|
|
2006-11-19 11:55:17 +00:00
|
|
|
enum ase_awk_val_ref_id_t
|
2006-08-20 15:49:48 +00:00
|
|
|
{
|
|
|
|
/* keep these items in the same order as corresponding items
|
|
|
|
* in tree.h */
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_REF_NAMED,
|
|
|
|
ASE_AWK_VAL_REF_GLOBAL,
|
|
|
|
ASE_AWK_VAL_REF_LOCAL,
|
|
|
|
ASE_AWK_VAL_REF_ARG,
|
|
|
|
ASE_AWK_VAL_REF_NAMEDIDX,
|
|
|
|
ASE_AWK_VAL_REF_GLOBALIDX,
|
|
|
|
ASE_AWK_VAL_REF_LOCALIDX,
|
|
|
|
ASE_AWK_VAL_REF_ARGIDX,
|
|
|
|
ASE_AWK_VAL_REF_POS
|
2006-03-04 15:54:37 +00:00
|
|
|
};
|
|
|
|
|
2006-11-19 11:55:17 +00:00
|
|
|
enum ase_awk_valtostr_opt_t
|
2006-10-11 15:02:26 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
|
|
|
|
ASE_AWK_VALTOSTR_PRINT = (1 << 1)
|
2006-10-11 15:02:26 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
|
|
|
|
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
|
|
|
|
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
|
|
|
|
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
|
|
|
|
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
|
|
|
|
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
|
|
|
|
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
|
2006-03-03 11:45:45 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
#if ASE_SIZEOF_INT == 2
|
|
|
|
#define ASE_AWK_VAL_HDR \
|
2006-04-17 16:12:02 +00:00
|
|
|
unsigned int type: 3; \
|
2006-04-30 18:05:07 +00:00
|
|
|
unsigned int ref: 13
|
|
|
|
#else
|
2006-10-24 04:10:12 +00:00
|
|
|
#define ASE_AWK_VAL_HDR \
|
2006-04-30 18:05:07 +00:00
|
|
|
unsigned int type: 3; \
|
|
|
|
unsigned int ref: 29
|
|
|
|
#endif
|
2006-03-03 11:45:45 +00:00
|
|
|
|
2007-01-14 15:08:01 +00:00
|
|
|
#ifndef ASE_AWK_NDE_INT_DEFINED
|
|
|
|
#define ASE_AWK_NDE_INT_DEFINED
|
2007-02-18 11:12:18 +00:00
|
|
|
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
|
2007-01-14 15:08:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ASE_AWK_NDE_REAL_DEFINED
|
|
|
|
#define ASE_AWK_NDE_REAL_DEFINED
|
2007-02-18 11:12:18 +00:00
|
|
|
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
|
2007-01-14 15:08:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
struct ase_awk_val_t
|
2006-03-03 11:45:45 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
2006-03-03 11:45:45 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_NIL */
|
|
|
|
struct ase_awk_val_nil_t
|
2006-03-07 15:55:14 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
2006-03-07 15:55:14 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_INT */
|
|
|
|
struct ase_awk_val_int_t
|
2006-03-03 11:45:45 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
|
|
|
ase_long_t val;
|
|
|
|
ase_awk_nde_int_t* nde;
|
2006-03-03 11:45:45 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_REAL */
|
|
|
|
struct ase_awk_val_real_t
|
2006-03-03 11:45:45 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
|
|
|
ase_real_t val;
|
|
|
|
ase_awk_nde_real_t* nde;
|
2006-03-03 11:45:45 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_STR */
|
|
|
|
struct ase_awk_val_str_t
|
2006-03-03 11:45:45 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
|
|
|
ase_char_t* buf;
|
|
|
|
ase_size_t len;
|
2006-03-03 11:45:45 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_REX */
|
|
|
|
struct ase_awk_val_rex_t
|
2006-04-24 11:26:00 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
|
|
|
ase_char_t* buf;
|
|
|
|
ase_size_t len;
|
2006-07-26 15:00:01 +00:00
|
|
|
void* code;
|
2006-04-24 11:26:00 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_MAP */
|
|
|
|
struct ase_awk_val_map_t
|
2006-03-27 15:44:38 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
2006-04-26 15:53:17 +00:00
|
|
|
|
2006-10-01 14:48:48 +00:00
|
|
|
/* TODO: make val_map to array if the indices used are all
|
|
|
|
* integers switch to map dynamically once the
|
|
|
|
* non-integral index is seen.
|
2006-04-26 15:53:17 +00:00
|
|
|
*/
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_awk_map_t* map;
|
2006-03-27 15:44:38 +00:00
|
|
|
};
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
/* ASE_AWK_VAL_REF */
|
|
|
|
struct ase_awk_val_ref_t
|
2006-08-20 15:49:48 +00:00
|
|
|
{
|
2006-10-24 04:10:12 +00:00
|
|
|
ASE_AWK_VAL_HDR;
|
2006-08-20 15:49:48 +00:00
|
|
|
|
|
|
|
int id;
|
2006-10-24 04:10:12 +00:00
|
|
|
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
|
2007-01-14 15:08:01 +00:00
|
|
|
* positional variable. Otherwise, adr points to the value
|
2006-10-01 14:48:48 +00:00
|
|
|
* directly. */
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_awk_val_t** adr;
|
2006-08-20 15:49:48 +00:00
|
|
|
};
|
|
|
|
|
2006-03-04 15:54:37 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
extern ase_awk_val_t* ase_awk_val_nil;
|
|
|
|
extern ase_awk_val_t* ase_awk_val_zls;
|
2006-12-16 14:48:31 +00:00
|
|
|
extern ase_awk_val_t* ase_awk_val_negone;
|
2006-10-24 04:10:12 +00:00
|
|
|
extern ase_awk_val_t* ase_awk_val_zero;
|
|
|
|
extern ase_awk_val_t* ase_awk_val_one;
|
2006-03-07 15:55:14 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
|
|
|
|
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
|
2006-08-31 15:22:40 +00:00
|
|
|
|
2006-11-16 15:16:25 +00:00
|
|
|
ase_awk_val_t* ase_awk_makestrval0 (
|
|
|
|
ase_awk_run_t* run, const ase_char_t* str);
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_awk_val_t* ase_awk_makestrval (
|
|
|
|
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
|
2006-11-16 15:16:25 +00:00
|
|
|
ase_awk_val_t* ase_awk_makestrval_nodup (
|
|
|
|
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_awk_val_t* ase_awk_makestrval2 (
|
|
|
|
ase_awk_run_t* run,
|
|
|
|
const ase_char_t* str1, ase_size_t len1,
|
|
|
|
const ase_char_t* str2, ase_size_t len2);
|
2006-08-31 15:22:40 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_awk_val_t* ase_awk_makerexval (
|
|
|
|
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
|
|
|
|
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
|
|
|
|
ase_awk_val_t* ase_awk_makerefval (
|
|
|
|
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
|
2006-03-05 17:07:33 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_bool_t ase_awk_isbuiltinval (ase_awk_val_t* val);
|
2006-06-30 16:46:34 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
|
2006-11-16 11:53:16 +00:00
|
|
|
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
|
2006-10-24 04:10:12 +00:00
|
|
|
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
|
|
|
|
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
|
2006-03-23 13:26:04 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_bool_t ase_awk_valtobool (
|
|
|
|
ase_awk_run_t* run, ase_awk_val_t* val);
|
2006-10-12 04:17:58 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
ase_char_t* ase_awk_valtostr (
|
|
|
|
ase_awk_run_t* run, ase_awk_val_t* val,
|
2007-02-23 08:17:51 +00:00
|
|
|
int opt, ase_str_t* buf, ase_size_t* len);
|
2006-10-12 04:17:58 +00:00
|
|
|
|
2006-10-24 04:10:12 +00:00
|
|
|
int ase_awk_valtonum (
|
|
|
|
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
|
2006-12-02 16:26:29 +00:00
|
|
|
int ase_awk_strtonum (
|
2006-12-04 12:59:01 +00:00
|
|
|
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
|
2006-12-02 16:26:29 +00:00
|
|
|
ase_long_t* l, ase_real_t* r);
|
2006-06-21 11:45:26 +00:00
|
|
|
|
2006-10-28 05:24:08 +00:00
|
|
|
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
|
2006-03-04 15:54:37 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-03 11:45:45 +00:00
|
|
|
#endif
|