HLSL: Implement 'this' keyword.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user