Skip to content

Commit

Permalink
Issue 785 - Make 'cent' and 'ucent' syntactically valid pending imple…
Browse files Browse the repository at this point in the history
…mentation

This adds just enough of cent and ucent to parse, but fail at the semantic stage.  This allows cent and ucent to be used inside version and static if blocks.
  • Loading branch information
yebblies committed Oct 28, 2012
1 parent 4c67f3a commit 2e70bca
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lexer.c
Expand Up @@ -2833,8 +2833,8 @@ static Keyword keywords[] =
{ "uint", TOKuns32 },
{ "long", TOKint64 },
{ "ulong", TOKuns64 },
{ "cent", TOKcent, },
{ "ucent", TOKucent, },
{ "cent", TOKint128, },
{ "ucent", TOKuns128, },
{ "float", TOKfloat32 },
{ "double", TOKfloat64 },
{ "real", TOKfloat80 },
Expand Down
5 changes: 4 additions & 1 deletion src/lexer.h
Expand Up @@ -120,11 +120,11 @@ enum TOK
TOKint16, TOKuns16,
TOKint32, TOKuns32,
TOKint64, TOKuns64,
TOKint128, TOKuns128,
TOKfloat32, TOKfloat64, TOKfloat80,
TOKimaginary32, TOKimaginary64, TOKimaginary80,
TOKcomplex32, TOKcomplex64, TOKcomplex80,
TOKchar, TOKwchar, TOKdchar, TOKbit, TOKbool,
TOKcent, TOKucent,

// 152
// Aggregates
Expand Down Expand Up @@ -186,6 +186,7 @@ enum TOK
case TOKint16: case TOKuns16: \
case TOKint32: case TOKuns32: \
case TOKint64: case TOKuns64: \
case TOKint128: case TOKuns128: \
case TOKfloat32: case TOKfloat64: case TOKfloat80: \
case TOKimaginary32: case TOKimaginary64: case TOKimaginary80: \
case TOKcomplex32: case TOKcomplex64: case TOKcomplex80: \
Expand All @@ -201,6 +202,8 @@ enum TOK
case TOKuns32: t = Type::tuns32; goto LabelX; \
case TOKint64: t = Type::tint64; goto LabelX; \
case TOKuns64: t = Type::tuns64; goto LabelX; \
case TOKint128: t = Type::tint128; goto LabelX; \
case TOKuns128: t = Type::tuns128; goto LabelX; \
case TOKfloat32: t = Type::tfloat32; goto LabelX; \
case TOKfloat64: t = Type::tfloat64; goto LabelX; \
case TOKfloat80: t = Type::tfloat80; goto LabelX; \
Expand Down
19 changes: 19 additions & 0 deletions src/mtype.c
Expand Up @@ -248,6 +248,8 @@ void Type::init()
mangleChar[Tslice] = '@';
mangleChar[Treturn] = '@';
mangleChar[Tvector] = '@';
mangleChar[Tint128] = '@';
mangleChar[Tuns128] = '@';

mangleChar[Tnull] = 'n'; // same as TypeNone

Expand All @@ -260,6 +262,7 @@ void Type::init()
// Set basic types
static TY basetab[] =
{ Tvoid, Tint8, Tuns8, Tint16, Tuns16, Tint32, Tuns32, Tint64, Tuns64,
Tint128, Tuns128,
Tfloat32, Tfloat64, Tfloat80,
Timaginary32, Timaginary64, Timaginary80,
Tcomplex32, Tcomplex64, Tcomplex80,
Expand Down Expand Up @@ -330,6 +333,12 @@ unsigned Type::alignsize()

Type *Type::semantic(Loc loc, Scope *sc)
{
if (ty == Tint128 || ty == Tuns128)
{
error(loc, "cent and ucent types not implemented");
return terror;
}

return merge();
}

Expand Down Expand Up @@ -2622,6 +2631,14 @@ TypeBasic::TypeBasic(TY ty)
flags |= TFLAGSintegral | TFLAGSunsigned | TFLAGSvector;
break;

case Tint128: d = Token::toChars(TOKint128);
flags |= TFLAGSintegral;
break;

case Tuns128: d = Token::toChars(TOKuns128);
flags |= TFLAGSintegral | TFLAGSunsigned;
break;

case Tfloat64: d = Token::toChars(TOKfloat64);
flags |= TFLAGSfloating | TFLAGSreal | TFLAGSvector;
break;
Expand Down Expand Up @@ -2725,6 +2742,8 @@ d_uns64 TypeBasic::size(Loc loc)
case Tcomplex32:
size = 8; break;
case Tcomplex64:
case Tint128:
case Tuns128:
size = 16; break;
case Tcomplex80:
size = REALSIZE * 2; break;
Expand Down
4 changes: 4 additions & 0 deletions src/mtype.h
Expand Up @@ -99,6 +99,8 @@ enum ENUMTY
Treturn,
Tnull,
Tvector,
Tint128,
Tuns128,
TMAX
};
typedef unsigned char TY; // ENUMTY
Expand Down Expand Up @@ -152,6 +154,8 @@ struct Type : Object
#define tuns32 basic[Tuns32]
#define tint64 basic[Tint64]
#define tuns64 basic[Tuns64]
#define tint128 basic[Tint128]
#define tuns128 basic[Tuns128]
#define tfloat32 basic[Tfloat32]
#define tfloat64 basic[Tfloat64]
#define tfloat80 basic[Tfloat80]
Expand Down
11 changes: 11 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -4348,6 +4348,17 @@ class Bar6848 : Foo6848
}
}

/***************************************************/

version(none)
{
cent issue785;
ucent issue785;
}

static assert(!is(cent) && !is(ucent));
static assert(!__traits(compiles, { cent x; }));

/***************************************************/
// 6847

Expand Down

0 comments on commit 2e70bca

Please sign in to comment.