jscript: Added new ccval_t type for CC variable values.
This commit is contained in:
parent
166c97d549
commit
79dc3bc72e
@ -789,11 +789,7 @@ static int next_token(parser_ctx_t *ctx, void *lval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct _cc_var_t {
|
struct _cc_var_t {
|
||||||
BOOL is_num;
|
ccval_t val;
|
||||||
union {
|
|
||||||
BOOL b;
|
|
||||||
DOUBLE n;
|
|
||||||
} u;
|
|
||||||
struct _cc_var_t *next;
|
struct _cc_var_t *next;
|
||||||
unsigned name_len;
|
unsigned name_len;
|
||||||
WCHAR name[0];
|
WCHAR name[0];
|
||||||
@ -811,18 +807,18 @@ void release_cc(cc_ctx_t *cc)
|
|||||||
heap_free(cc);
|
heap_free(cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL add_cc_var(cc_ctx_t *cc, const WCHAR *name, cc_var_t *v)
|
static BOOL new_cc_var(cc_ctx_t *cc, const WCHAR *name, int len, ccval_t v)
|
||||||
{
|
{
|
||||||
cc_var_t *new_v;
|
cc_var_t *new_v;
|
||||||
unsigned len;
|
|
||||||
|
|
||||||
len = strlenW(name);
|
if(len == -1)
|
||||||
|
len = strlenW(name);
|
||||||
|
|
||||||
new_v = heap_alloc(sizeof(cc_var_t) + (len+1)*sizeof(WCHAR));
|
new_v = heap_alloc(sizeof(cc_var_t) + (len+1)*sizeof(WCHAR));
|
||||||
if(!new_v)
|
if(!new_v)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
memcpy(new_v, v, sizeof(*v));
|
new_v->val = v;
|
||||||
memcpy(new_v->name, name, (len+1)*sizeof(WCHAR));
|
memcpy(new_v->name, name, (len+1)*sizeof(WCHAR));
|
||||||
new_v->name_len = len;
|
new_v->name_len = len;
|
||||||
new_v->next = cc->vars;
|
new_v->next = cc->vars;
|
||||||
@ -845,7 +841,6 @@ static cc_var_t *find_cc_var(cc_ctx_t *cc, const WCHAR *name, unsigned name_len)
|
|||||||
static int init_cc(parser_ctx_t *ctx)
|
static int init_cc(parser_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
cc_ctx_t *cc;
|
cc_ctx_t *cc;
|
||||||
cc_var_t v;
|
|
||||||
|
|
||||||
static const WCHAR _win32W[] = {'_','w','i','n','3','2',0};
|
static const WCHAR _win32W[] = {'_','w','i','n','3','2',0};
|
||||||
static const WCHAR _win64W[] = {'_','w','i','n','6','4',0};
|
static const WCHAR _win64W[] = {'_','w','i','n','6','4',0};
|
||||||
@ -863,24 +858,12 @@ static int init_cc(parser_ctx_t *ctx)
|
|||||||
return lex_error(ctx, E_OUTOFMEMORY);
|
return lex_error(ctx, E_OUTOFMEMORY);
|
||||||
|
|
||||||
cc->vars = NULL;
|
cc->vars = NULL;
|
||||||
v.is_num = FALSE;
|
|
||||||
v.u.b = TRUE;
|
|
||||||
if(!add_cc_var(cc, _jscriptW, &v)
|
|
||||||
|| !add_cc_var(cc, sizeof(void*) == 8 ? _win64W : _win32W, &v)
|
|
||||||
|| !add_cc_var(cc, sizeof(void*) == 8 ? _amd64W : _x86W, &v)) {
|
|
||||||
release_cc(cc);
|
|
||||||
return lex_error(ctx, E_OUTOFMEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
v.is_num = TRUE;
|
if(!new_cc_var(cc, _jscriptW, -1, ccval_bool(TRUE))
|
||||||
v.u.n = JSCRIPT_BUILD_VERSION;
|
|| !new_cc_var(cc, sizeof(void*) == 8 ? _win64W : _win32W, -1, ccval_bool(TRUE))
|
||||||
if(!add_cc_var(cc, _jscript_buildW, &v)) {
|
|| !new_cc_var(cc, sizeof(void*) == 8 ? _amd64W : _x86W, -1, ccval_bool(TRUE))
|
||||||
release_cc(cc);
|
|| !new_cc_var(cc, _jscript_versionW, -1, ccval_num(JSCRIPT_MAJOR_VERSION + (DOUBLE)JSCRIPT_MINOR_VERSION/10.0))
|
||||||
return lex_error(ctx, E_OUTOFMEMORY);
|
|| !new_cc_var(cc, _jscript_buildW, -1, ccval_num(JSCRIPT_BUILD_VERSION))) {
|
||||||
}
|
|
||||||
|
|
||||||
v.u.n = JSCRIPT_MAJOR_VERSION + (DOUBLE)JSCRIPT_MINOR_VERSION/10.0;
|
|
||||||
if(!add_cc_var(cc, _jscript_versionW, &v)) {
|
|
||||||
release_cc(cc);
|
release_cc(cc);
|
||||||
return lex_error(ctx, E_OUTOFMEMORY);
|
return lex_error(ctx, E_OUTOFMEMORY);
|
||||||
}
|
}
|
||||||
@ -941,12 +924,12 @@ static int cc_token(parser_ctx_t *ctx, void *lval)
|
|||||||
|
|
||||||
var = find_cc_var(ctx->script->cc, ctx->ptr, id_len);
|
var = find_cc_var(ctx->script->cc, ctx->ptr, id_len);
|
||||||
ctx->ptr += id_len;
|
ctx->ptr += id_len;
|
||||||
if(!var || var->is_num) {
|
if(!var || var->val.is_num) {
|
||||||
*(literal_t**)lval = new_double_literal(ctx, var ? var->u.n : NAN);
|
*(literal_t**)lval = new_double_literal(ctx, var ? var->val.u.n : NAN);
|
||||||
return tNumericLiteral;
|
return tNumericLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(literal_t**)lval = new_boolean_literal(ctx, var->u.b);
|
*(literal_t**)lval = new_boolean_literal(ctx, var->val.u.b);
|
||||||
return tBooleanLiteral;
|
return tBooleanLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,14 @@ typedef struct _source_elements_t source_elements_t;
|
|||||||
typedef struct _expression_t expression_t;
|
typedef struct _expression_t expression_t;
|
||||||
typedef struct _statement_t statement_t;
|
typedef struct _statement_t statement_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BOOL is_num;
|
||||||
|
union {
|
||||||
|
BOOL b;
|
||||||
|
double n;
|
||||||
|
} u;
|
||||||
|
} ccval_t;
|
||||||
|
|
||||||
typedef struct _parser_ctx_t {
|
typedef struct _parser_ctx_t {
|
||||||
const WCHAR *begin;
|
const WCHAR *begin;
|
||||||
const WCHAR *end;
|
const WCHAR *end;
|
||||||
@ -352,3 +360,19 @@ typedef struct {
|
|||||||
expression_t expr;
|
expression_t expr;
|
||||||
prop_val_t *property_list;
|
prop_val_t *property_list;
|
||||||
} property_value_expression_t;
|
} property_value_expression_t;
|
||||||
|
|
||||||
|
static inline ccval_t ccval_num(double n)
|
||||||
|
{
|
||||||
|
ccval_t r;
|
||||||
|
r.is_num = TRUE;
|
||||||
|
r.u.n = n;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline ccval_t ccval_bool(BOOL b)
|
||||||
|
{
|
||||||
|
ccval_t r;
|
||||||
|
r.is_num = FALSE;
|
||||||
|
r.u.b = b;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user