Issue an error if "uniform" or "varying" qualifiers are applied to void types.

Issue #179.
This commit is contained in:
Matt Pharr
2012-02-21 12:26:42 -08:00
parent 95224f3f11
commit 8603f9838f
7 changed files with 69 additions and 17 deletions

View File

@@ -69,12 +69,21 @@ lApplyTypeQualifiers(int typeQualifiers, const Type *type, SourcePos pos) {
if ((typeQualifiers & TYPEQUAL_CONST) != 0)
type = type->GetAsConstType();
if ((typeQualifiers & TYPEQUAL_UNIFORM) != 0)
type = type->GetAsUniformType();
else if ((typeQualifiers & TYPEQUAL_VARYING) != 0)
type = type->GetAsVaryingType();
if ((typeQualifiers & TYPEQUAL_UNIFORM) != 0) {
if (type == AtomicType::Void)
Error(pos, "\"uniform\" qualifier is illegal with \"void\" type.");
else
type = type->GetAsUniformType();
}
else if ((typeQualifiers & TYPEQUAL_VARYING) != 0) {
if (type == AtomicType::Void)
Error(pos, "\"varying\" qualifier is illegal with \"void\" type.");
else
type = type->GetAsVaryingType();
}
else
type = type->GetAsUnboundVariabilityType();
if (type != AtomicType::Void)
type = type->GetAsUnboundVariabilityType();
if ((typeQualifiers & TYPEQUAL_UNSIGNED) != 0) {
if ((typeQualifiers & TYPEQUAL_SIGNED) != 0)

View File

@@ -473,8 +473,28 @@ rate_qualified_new
rate_qualified_new_type
: type_specifier { $$ = $1; }
| TOKEN_UNIFORM type_specifier { $$ = $2 ? $2->GetAsUniformType() : NULL; }
| TOKEN_VARYING type_specifier { $$ = $2 ? $2->GetAsVaryingType() : NULL; }
| TOKEN_UNIFORM type_specifier
{
if ($2 == NULL)
$$ = NULL;
else if ($2 == AtomicType::Void) {
Error(@1, "\"uniform\" qualifier is illegal with \"void\" type.");
$$ = NULL;
}
else
$$ = $2->GetAsUniformType();
}
| TOKEN_VARYING type_specifier
{
if ($2 == NULL)
$$ = NULL;
else if ($2 == AtomicType::Void) {
Error(@1, "\"varying\" qualifier is illegal with \"void\" type.");
$$ = NULL;
}
else
$$ = $2->GetAsVaryingType();
}
;
new_expression
@@ -803,10 +823,22 @@ specifier_qualifier_list
| type_qualifier specifier_qualifier_list
{
if ($2 != NULL) {
if ($1 == TYPEQUAL_UNIFORM)
$$ = $2->GetAsUniformType();
else if ($1 == TYPEQUAL_VARYING)
$$ = $2->GetAsVaryingType();
if ($1 == TYPEQUAL_UNIFORM) {
if ($2 == AtomicType::Void) {
Error(@1, "\"uniform\" qualifier is illegal with \"void\" type.");
$$ = NULL;
}
else
$$ = $2->GetAsUniformType();
}
else if ($1 == TYPEQUAL_VARYING) {
if ($2 == AtomicType::Void) {
Error(@1, "\"varying\" qualifier is illegal with \"void\" type.");
$$ = NULL;
}
else
$$ = $2->GetAsVaryingType();
}
else if ($1 == TYPEQUAL_CONST)
$$ = $2->GetAsConstType();
else if ($1 == TYPEQUAL_SIGNED) {

View File

@@ -0,0 +1,3 @@
// "varying" qualifier is illegal with "void" type
varying void *foo;

View File

@@ -0,0 +1,5 @@
// "uniform" qualifier is illegal with "void" type
struct FFF {
uniform void *x;
};

View File

@@ -0,0 +1,3 @@
// "varying" qualifier is illegal with "void" type
varying void *foo() { }

View File

@@ -0,0 +1,3 @@
// "varying" qualifier is illegal with "void" type
void foo(varying void *x) { }

View File

@@ -382,24 +382,21 @@ AtomicType::GetBaseType() const {
const AtomicType *
AtomicType::GetAsVaryingType() const {
if (this == AtomicType::Void)
return this;
Assert(this != AtomicType::Void);
return typeTable[basicType][Varying][isConst ? 1 : 0];
}
const AtomicType *
AtomicType::GetAsUniformType() const {
if (this == AtomicType::Void)
return this;
Assert(this != AtomicType::Void);
return typeTable[basicType][Uniform][isConst ? 1 : 0];
}
const AtomicType *
AtomicType::GetAsUnboundVariabilityType() const {
if (this == AtomicType::Void)
return this;
Assert(this != AtomicType::Void);
return typeTable[basicType][Unbound][isConst ? 1 : 0];
}