Merge from petecoup/shortvec-in-struct branch.

Fixes issue #49: using short vector types in struct declarations
would give a bogus parse error.
This commit is contained in:
Pete Couperus
2011-07-06 09:07:51 +01:00
committed by Matt Pharr
parent 5cc750ecee
commit 126e065601
3 changed files with 54 additions and 7 deletions

View File

@@ -110,6 +110,7 @@ static const char *lBuiltinTokens[] = {
Expr *expr;
ExprList *exprList;
const Type *type;
const AtomicType *atomicType;
int typeQualifier;
StorageClass storageClass;
Stmt *stmt;
@@ -176,6 +177,8 @@ static const char *lBuiltinTokens[] = {
%type <type> specifier_qualifier_list struct_or_union_specifier
%type <type> enum_specifier type_specifier type_name
%type <type> short_vec_specifier
%type <atomicType> atomic_var_type_specifier
%type <typeQualifier> type_qualifier
%type <storageClass> storage_class_specifier
@@ -534,13 +537,7 @@ storage_class_specifier
;
type_specifier
: TOKEN_VOID { $$ = AtomicType::Void; }
| TOKEN_BOOL { $$ = AtomicType::VaryingBool; }
/* | TOKEN_CHAR { UNIMPLEMENTED; } */
| TOKEN_INT { $$ = AtomicType::VaryingInt32; }
| TOKEN_FLOAT { $$ = AtomicType::VaryingFloat; }
| TOKEN_DOUBLE { $$ = AtomicType::VaryingDouble; }
| TOKEN_INT64 { $$ = AtomicType::VaryingInt64; }
: atomic_var_type_specifier { $$ = $1; }
| TOKEN_TYPE_NAME
{ const Type *t = m->symbolTable->LookupType(yytext);
assert(t != NULL);
@@ -554,6 +551,25 @@ type_specifier
*/
;
atomic_var_type_specifier
: TOKEN_VOID { $$ = AtomicType::Void; }
| TOKEN_BOOL { $$ = AtomicType::VaryingBool; }
/* | TOKEN_CHAR { UNIMPLEMENTED; } */
| TOKEN_INT { $$ = AtomicType::VaryingInt32; }
| TOKEN_FLOAT { $$ = AtomicType::VaryingFloat; }
| TOKEN_DOUBLE { $$ = AtomicType::VaryingDouble; }
| TOKEN_INT64 { $$ = AtomicType::VaryingInt64; }
;
short_vec_specifier
: atomic_var_type_specifier '<' int_constant '>'
{
Type* vt =
new VectorType($1, $3);
$$ = vt;
}
;
struct_or_union_name
: TOKEN_IDENTIFIER { $$ = strdup(yytext); }
| TOKEN_TYPE_NAME { $$ = strdup(yytext); }
@@ -630,6 +646,7 @@ struct_declaration
specifier_qualifier_list
: type_specifier specifier_qualifier_list
| type_specifier
| short_vec_specifier
| type_qualifier specifier_qualifier_list
{
if ($1 == TYPEQUAL_UNIFORM)

View File

@@ -0,0 +1,15 @@
export uniform int width() { return programCount; }
export void f_v(uniform float RET[]) {
varying struct { float<2> v; } a;
a.v.x = 1;
a.v.y = 2;
RET[programIndex] = a.v.x + a.v.y;
}
export void result(uniform float RET[]) {
RET[programIndex] = 3;
}

View File

@@ -0,0 +1,15 @@
export uniform int width() { return programCount; }
export void f_v(uniform float RET[]) {
varying struct { float<2> v; } a;
a.v[0] = 1;
a.v[1] = 2;
RET[programIndex] = a.v[0] + a.v[1];
}
export void result(uniform float RET[]) {
RET[programIndex] = 3;
}