Add a view_as operator.

This commit is contained in:
David Anderson 2014-11-30 19:08:25 -08:00
parent cb4fdf1aa9
commit 68e0645813
6 changed files with 36 additions and 2 deletions

View File

@ -562,6 +562,7 @@ int pc_enablewarning(int number,int enable);
const char *pc_tagname(int tag);
int parse_decl(declinfo_t *decl, int flags);
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)

View File

@ -157,7 +157,6 @@ static void inst_datetime_defines(void);
static void inst_binary_name(char *binfname);
static int operatorname(char *name);
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 reparse_old_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;
}
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);
if (tag >= 0)

View File

@ -1660,6 +1660,33 @@ static int hier2(value *lval)
callfunction(target, NULL, lval, TRUE);
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 */
tag=pc_addtag(st);
lval->cmptag=tag;

View File

@ -0,0 +1,3 @@
public float egg() {
return view_as<void>(10);
}

View File

@ -0,0 +1 @@
(2) : error 144: void cannot be used as a variable type

View File

@ -0,0 +1,3 @@
public float egg() {
return view_as<float>(10);
}