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 @@ ...@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // 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). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1929" #define GLSLANG_REVISION "Overload400-PrecQual.1930"
#define GLSLANG_DATE "21-Mar-2017" #define GLSLANG_DATE "22-Mar-2017"
...@@ -235,6 +235,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -235,6 +235,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.structin.vert", "main"}, {"hlsl.structin.vert", "main"},
{"hlsl.structIoFourWay.frag", "main"}, {"hlsl.structIoFourWay.frag", "main"},
{"hlsl.structStructName.frag", "main"}, {"hlsl.structStructName.frag", "main"},
{"hlsl.this.frag", "main"},
{"hlsl.intrinsics.vert", "VertexShaderFunction"}, {"hlsl.intrinsics.vert", "VertexShaderFunction"},
{"hlsl.matType.frag", "PixelShaderFunction"}, {"hlsl.matType.frag", "PixelShaderFunction"},
{"hlsl.matType.bool.frag", "main"}, {"hlsl.matType.bool.frag", "main"},
......
...@@ -75,16 +75,33 @@ void HlslGrammar::unimplemented(const char* error) ...@@ -75,16 +75,33 @@ void HlslGrammar::unimplemented(const char* error)
parseContext.error(token.loc, "Unimplemented", 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. // Only process the next token if it is an identifier.
// Return true if it was an identifier. // Return true if it was an identifier.
bool HlslGrammar::acceptIdentifier(HlslToken& idToken) bool HlslGrammar::acceptIdentifier(HlslToken& idToken)
{ {
// IDENTIFIER
if (peekTokenClass(EHTokIdentifier)) { if (peekTokenClass(EHTokIdentifier)) {
idToken = token; idToken = token;
advanceToken(); advanceToken();
return true; 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), // 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 // 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 // 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 ...@@ -1538,15 +1538,14 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l
TVariable *variable = new TVariable(param.name, *param.type); TVariable *variable = new TVariable(param.name, *param.type);
if (i == 0 && function.hasImplicitThis()) { if (i == 0 && function.hasImplicitThis()) {
// 'this' members are already in a symbol-table level, // Anonymous 'this' members are already in a symbol-table level,
// and we need to know what function parameter to map them to // and we need to know what function parameter to map them to.
symbolTable.makeInternalVariable(*variable); symbolTable.makeInternalVariable(*variable);
pushImplicitThis(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 // Add the parameter to the AST
paramNodes = intermediate.growAggregate(paramNodes, paramNodes = intermediate.growAggregate(paramNodes,
intermediate.addSymbol(*variable, loc), intermediate.addSymbol(*variable, loc),
......
...@@ -333,6 +333,7 @@ void HlslScanContext::fillInKeywordMap() ...@@ -333,6 +333,7 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["cbuffer"] = EHTokCBuffer; (*KeywordMap)["cbuffer"] = EHTokCBuffer;
(*KeywordMap)["tbuffer"] = EHTokTBuffer; (*KeywordMap)["tbuffer"] = EHTokTBuffer;
(*KeywordMap)["typedef"] = EHTokTypedef; (*KeywordMap)["typedef"] = EHTokTypedef;
(*KeywordMap)["this"] = EHTokThis;
(*KeywordMap)["true"] = EHTokBoolConstant; (*KeywordMap)["true"] = EHTokBoolConstant;
(*KeywordMap)["false"] = EHTokBoolConstant; (*KeywordMap)["false"] = EHTokBoolConstant;
...@@ -374,7 +375,6 @@ void HlslScanContext::fillInKeywordMap() ...@@ -374,7 +375,6 @@ void HlslScanContext::fillInKeywordMap()
ReservedSet->insert("sizeof"); ReservedSet->insert("sizeof");
ReservedSet->insert("static_cast"); ReservedSet->insert("static_cast");
ReservedSet->insert("template"); ReservedSet->insert("template");
ReservedSet->insert("this");
ReservedSet->insert("throw"); ReservedSet->insert("throw");
ReservedSet->insert("try"); ReservedSet->insert("try");
ReservedSet->insert("typename"); ReservedSet->insert("typename");
...@@ -827,6 +827,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier() ...@@ -827,6 +827,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
case EHTokTypedef: case EHTokTypedef:
case EHTokCBuffer: case EHTokCBuffer:
case EHTokTBuffer: case EHTokTBuffer:
case EHTokThis:
return keyword; return keyword;
case EHTokBoolConstant: case EHTokBoolConstant:
......
...@@ -273,6 +273,7 @@ enum EHlslTokenClass { ...@@ -273,6 +273,7 @@ enum EHlslTokenClass {
EHTokCBuffer, EHTokCBuffer,
EHTokTBuffer, EHTokTBuffer,
EHTokTypedef, EHTokTypedef,
EHTokThis,
// constant // constant
EHTokFloatConstant, 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