Commit 7a41f96d by John Kessenich

HLSL: Implement 'this' keyword.

parent 3778979c
static float2 var = float2(1.0, 2.0);
struct type1
{
int memFun1(int3 var)
{
return var.z + this.var + var2;
}
int memFun2(int a)
{
int3 var = int3(1,2,3);
return var.z + (int)bar.y + this.var2;
}
float2 bar;
int var;
int var2;
};
float4 main() : SV_Target0
{
type1 T;
T.bar = var;
T.var = 7;
T.var2 = 9;
int i = T.memFun1(int3(10,11,12));
i += T.memFun2(17);
return float4(i,i,i,i);
}
......@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1929"
#define GLSLANG_DATE "21-Mar-2017"
#define GLSLANG_REVISION "Overload400-PrecQual.1930"
#define GLSLANG_DATE "22-Mar-2017"
......@@ -235,6 +235,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.structin.vert", "main"},
{"hlsl.structIoFourWay.frag", "main"},
{"hlsl.structStructName.frag", "main"},
{"hlsl.this.frag", "main"},
{"hlsl.intrinsics.vert", "VertexShaderFunction"},
{"hlsl.matType.frag", "PixelShaderFunction"},
{"hlsl.matType.bool.frag", "main"},
......
......@@ -75,16 +75,33 @@ void HlslGrammar::unimplemented(const char* error)
parseContext.error(token.loc, "Unimplemented", error, "");
}
// IDENTIFIER
// THIS
// type that can be used as IDENTIFIER
//
// Only process the next token if it is an identifier.
// Return true if it was an identifier.
bool HlslGrammar::acceptIdentifier(HlslToken& idToken)
{
// IDENTIFIER
if (peekTokenClass(EHTokIdentifier)) {
idToken = token;
advanceToken();
return true;
}
// THIS
// -> maps to the IDENTIFIER spelled with the internal special name for 'this'
if (peekTokenClass(EHTokThis)) {
idToken = token;
advanceToken();
idToken.tokenClass = EHTokIdentifier;
idToken.string = NewPoolTString(intermediate.implicitThisName);
return true;
}
// type that can be used as IDENTIFIER
// Even though "sample", "bool", "float", etc keywords (for types, interpolation modifiers),
// they ARE still accepted as identifiers. This is not a dense space: e.g, "void" is not a
// valid identifier, nor is "linear". This code special cases the known instances of this, so
......
......@@ -1538,15 +1538,14 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
TVariable *variable = new TVariable(param.name, *param.type);
if (i == 0 && function.hasImplicitThis()) {
// 'this' members are already in a symbol-table level,
// and we need to know what function parameter to map them to
// Anonymous 'this' members are already in a symbol-table level,
// and we need to know what function parameter to map them to.
symbolTable.makeInternalVariable(*variable);
pushImplicitThis(variable);
} else {
// Insert the parameters with name in the symbol table.
if (! symbolTable.insert(*variable))
error(loc, "redefinition", variable->getName().c_str(), "");
}
// Insert the parameters with name in the symbol table.
if (! symbolTable.insert(*variable))
error(loc, "redefinition", variable->getName().c_str(), "");
// Add the parameter to the AST
paramNodes = intermediate.growAggregate(paramNodes,
intermediate.addSymbol(*variable, loc),
......
......@@ -333,6 +333,7 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["cbuffer"] = EHTokCBuffer;
(*KeywordMap)["tbuffer"] = EHTokTBuffer;
(*KeywordMap)["typedef"] = EHTokTypedef;
(*KeywordMap)["this"] = EHTokThis;
(*KeywordMap)["true"] = EHTokBoolConstant;
(*KeywordMap)["false"] = EHTokBoolConstant;
......@@ -374,7 +375,6 @@ void HlslScanContext::fillInKeywordMap()
ReservedSet->insert("sizeof");
ReservedSet->insert("static_cast");
ReservedSet->insert("template");
ReservedSet->insert("this");
ReservedSet->insert("throw");
ReservedSet->insert("try");
ReservedSet->insert("typename");
......@@ -827,6 +827,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
case EHTokTypedef:
case EHTokCBuffer:
case EHTokTBuffer:
case EHTokThis:
return keyword;
case EHTokBoolConstant:
......
......@@ -273,6 +273,7 @@ enum EHlslTokenClass {
EHTokCBuffer,
EHTokTBuffer,
EHTokTypedef,
EHTokThis,
// constant
EHTokFloatConstant,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment