Add a view_as operator.
This commit is contained in:
parent
cb4fdf1aa9
commit
68e0645813
@ -562,6 +562,7 @@ int pc_enablewarning(int number,int enable);
|
|||||||
const char *pc_tagname(int tag);
|
const char *pc_tagname(int tag);
|
||||||
int parse_decl(declinfo_t *decl, int flags);
|
int parse_decl(declinfo_t *decl, int flags);
|
||||||
const char *type_to_name(int tag);
|
const char *type_to_name(int tag);
|
||||||
|
bool parse_new_typename(const token_t *tok, int *tagp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Functions called from the compiler (to be implemented by you)
|
* Functions called from the compiler (to be implemented by you)
|
||||||
|
@ -157,7 +157,6 @@ static void inst_datetime_defines(void);
|
|||||||
static void inst_binary_name(char *binfname);
|
static void inst_binary_name(char *binfname);
|
||||||
static int operatorname(char *name);
|
static int operatorname(char *name);
|
||||||
static int parse_new_typename(const token_t *tok);
|
static int parse_new_typename(const token_t *tok);
|
||||||
static bool parse_new_typename(const token_t *tok, int *outp);
|
|
||||||
static int parse_new_decl(declinfo_t *decl, const token_t *first, int flags);
|
static int parse_new_decl(declinfo_t *decl, const token_t *first, int flags);
|
||||||
static int reparse_old_decl(declinfo_t *decl, int flags);
|
static int reparse_old_decl(declinfo_t *decl, int flags);
|
||||||
static int reparse_new_decl(declinfo_t *decl, int flags);
|
static int reparse_new_decl(declinfo_t *decl, int flags);
|
||||||
@ -3116,7 +3115,7 @@ static int parse_new_typename(const token_t *tok)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_new_typename(const token_t *tok, int *tagp)
|
bool parse_new_typename(const token_t *tok, int *tagp)
|
||||||
{
|
{
|
||||||
int tag = parse_new_typename(tok);
|
int tag = parse_new_typename(tok);
|
||||||
if (tag >= 0)
|
if (tag >= 0)
|
||||||
|
@ -1660,6 +1660,33 @@ static int hier2(value *lval)
|
|||||||
callfunction(target, NULL, lval, TRUE);
|
callfunction(target, NULL, lval, TRUE);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
case tVIEW_AS: /* newer tagname override */
|
||||||
|
{
|
||||||
|
needtoken('<');
|
||||||
|
int tag = 0;
|
||||||
|
{
|
||||||
|
token_t tok;
|
||||||
|
lextok(&tok);
|
||||||
|
if (!parse_new_typename(&tok, &tag))
|
||||||
|
tag = 0;
|
||||||
|
}
|
||||||
|
needtoken('>');
|
||||||
|
|
||||||
|
if (tag == pc_tag_void)
|
||||||
|
error(144);
|
||||||
|
|
||||||
|
lval->cmptag = tag;
|
||||||
|
lvalue = hier12(lval);
|
||||||
|
|
||||||
|
if ((lval->tag & OBJECTTAG) || (tag & OBJECTTAG)) {
|
||||||
|
matchtag(tag, lval->tag, MATCHTAG_COERCE);
|
||||||
|
} else if ((tag & FUNCTAG) != (lval->tag & FUNCTAG)) {
|
||||||
|
// Warn: unsupported cast.
|
||||||
|
error(237);
|
||||||
|
}
|
||||||
|
lval->tag = tag;
|
||||||
|
return lvalue;
|
||||||
|
}
|
||||||
case tLABEL: /* tagname override */
|
case tLABEL: /* tagname override */
|
||||||
tag=pc_addtag(st);
|
tag=pc_addtag(st);
|
||||||
lval->cmptag=tag;
|
lval->cmptag=tag;
|
||||||
|
3
sourcepawn/compiler/tests/fail-cannot-view-as-void.sp
Normal file
3
sourcepawn/compiler/tests/fail-cannot-view-as-void.sp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public float egg() {
|
||||||
|
return view_as<void>(10);
|
||||||
|
}
|
1
sourcepawn/compiler/tests/fail-cannot-view-as-void.txt
Normal file
1
sourcepawn/compiler/tests/fail-cannot-view-as-void.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
(2) : error 144: void cannot be used as a variable type
|
3
sourcepawn/compiler/tests/ok-view-int-as-float.sp
Normal file
3
sourcepawn/compiler/tests/ok-view-int-as-float.sp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public float egg() {
|
||||||
|
return view_as<float>(10);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user