HLSL: Non-functional: consolidate function declarator information.
This commit is contained in:
@@ -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.1899"
|
#define GLSLANG_REVISION "Overload400-PrecQual.1901"
|
||||||
#define GLSLANG_DATE "11-Mar-2017"
|
#define GLSLANG_DATE "11-Mar-2017"
|
||||||
|
|||||||
@@ -92,6 +92,14 @@ namespace glslang {
|
|||||||
|
|
||||||
std::unordered_map<TAttributeType, TIntermAggregate*> attributes;
|
std::unordered_map<TAttributeType, TIntermAggregate*> attributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TFunctionDeclarator {
|
||||||
|
public:
|
||||||
|
TSourceLoc loc;
|
||||||
|
TFunction* function;
|
||||||
|
TAttributeMap attributes;
|
||||||
|
};
|
||||||
|
|
||||||
} // end namespace glslang
|
} // end namespace glslang
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -301,8 +301,8 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList)
|
|||||||
bool declarator_list = false; // true when processing comma separation
|
bool declarator_list = false; // true when processing comma separation
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
TAttributeMap attributes;
|
TFunctionDeclarator declarator;
|
||||||
acceptAttributes(attributes);
|
acceptAttributes(declarator.attributes);
|
||||||
|
|
||||||
// typedef
|
// typedef
|
||||||
bool typedefDecl = acceptTokenClass(EHTokTypedef);
|
bool typedefDecl = acceptTokenClass(EHTokTypedef);
|
||||||
@@ -334,26 +334,27 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList)
|
|||||||
parseContext.renameShaderFunction(fnName);
|
parseContext.renameShaderFunction(fnName);
|
||||||
|
|
||||||
// function_parameters
|
// function_parameters
|
||||||
TFunction& function = *new TFunction(fnName, declaredType);
|
declarator.function = new TFunction(fnName, declaredType);
|
||||||
if (!acceptFunctionParameters(function)) {
|
if (!acceptFunctionParameters(*declarator.function)) {
|
||||||
expected("function parameter list");
|
expected("function parameter list");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// post_decls
|
// post_decls
|
||||||
acceptPostDecls(function.getWritableType().getQualifier());
|
acceptPostDecls(declarator.function->getWritableType().getQualifier());
|
||||||
|
|
||||||
// compound_statement (function body definition) or just a prototype?
|
// compound_statement (function body definition) or just a prototype?
|
||||||
|
declarator.loc = token.loc;
|
||||||
if (peekTokenClass(EHTokLeftBrace)) {
|
if (peekTokenClass(EHTokLeftBrace)) {
|
||||||
if (declarator_list)
|
if (declarator_list)
|
||||||
parseContext.error(idToken.loc, "function body can't be in a declarator list", "{", "");
|
parseContext.error(idToken.loc, "function body can't be in a declarator list", "{", "");
|
||||||
if (typedefDecl)
|
if (typedefDecl)
|
||||||
parseContext.error(idToken.loc, "function body can't be in a typedef", "{", "");
|
parseContext.error(idToken.loc, "function body can't be in a typedef", "{", "");
|
||||||
return acceptFunctionDefinition(function, nodeList, attributes);
|
return acceptFunctionDefinition(declarator, nodeList);
|
||||||
} else {
|
} else {
|
||||||
if (typedefDecl)
|
if (typedefDecl)
|
||||||
parseContext.error(idToken.loc, "function typedefs not implemented", "{", "");
|
parseContext.error(idToken.loc, "function typedefs not implemented", "{", "");
|
||||||
parseContext.handleFunctionDeclarator(idToken.loc, function, true);
|
parseContext.handleFunctionDeclarator(declarator.loc, *declarator.function, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// A variable declaration. Fix the storage qualifier if it's a global.
|
// A variable declaration. Fix the storage qualifier if it's a global.
|
||||||
@@ -1962,7 +1963,8 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode*
|
|||||||
if (peekTokenClass(EHTokLeftParen)) {
|
if (peekTokenClass(EHTokLeftParen)) {
|
||||||
// function_parameters
|
// function_parameters
|
||||||
if (!declarator_list) {
|
if (!declarator_list) {
|
||||||
functionDefinitionAccepted = acceptMemberFunctionDefinition(nodeList, typeName, memberType, *idToken.string);
|
functionDefinitionAccepted = acceptMemberFunctionDefinition(nodeList, typeName, memberType,
|
||||||
|
*idToken.string);
|
||||||
if (functionDefinitionAccepted)
|
if (functionDefinitionAccepted)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2029,22 +2031,23 @@ bool HlslGrammar::acceptMemberFunctionDefinition(TIntermNode*& nodeList, const T
|
|||||||
bool accepted = false;
|
bool accepted = false;
|
||||||
|
|
||||||
TString* functionName = parseContext.getFullMemberFunctionName(memberName, type.getQualifier().storage == EvqGlobal);
|
TString* functionName = parseContext.getFullMemberFunctionName(memberName, type.getQualifier().storage == EvqGlobal);
|
||||||
TFunction& function = *new TFunction(functionName, type);
|
TFunctionDeclarator declarator;
|
||||||
|
declarator.function = new TFunction(functionName, type);
|
||||||
|
|
||||||
// function_parameters
|
// function_parameters
|
||||||
if (acceptFunctionParameters(function)) {
|
if (acceptFunctionParameters(*declarator.function)) {
|
||||||
// post_decls
|
// post_decls
|
||||||
acceptPostDecls(function.getWritableType().getQualifier());
|
acceptPostDecls(declarator.function->getWritableType().getQualifier());
|
||||||
|
|
||||||
// compound_statement (function body definition)
|
// compound_statement (function body definition)
|
||||||
if (peekTokenClass(EHTokLeftBrace)) {
|
if (peekTokenClass(EHTokLeftBrace)) {
|
||||||
if (function.getType().getQualifier().storage != EvqGlobal) {
|
if (declarator.function->getType().getQualifier().storage != EvqGlobal) {
|
||||||
expected("only static member functions are accepted");
|
expected("only static member functions are accepted");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAttributeMap attributes;
|
declarator.loc = token.loc;
|
||||||
accepted = acceptFunctionDefinition(function, nodeList, attributes);
|
accepted = acceptFunctionDefinition(declarator, nodeList);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
expected("function parameter list");
|
expected("function parameter list");
|
||||||
@@ -2180,17 +2183,21 @@ bool HlslGrammar::acceptParameterDeclaration(TFunction& function)
|
|||||||
|
|
||||||
// Do the work to create the function definition in addition to
|
// Do the work to create the function definition in addition to
|
||||||
// parsing the body (compound_statement).
|
// parsing the body (compound_statement).
|
||||||
bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& nodeList, const TAttributeMap& attributes)
|
bool HlslGrammar::acceptFunctionDefinition(TFunctionDeclarator& declarator, TIntermNode*& nodeList)
|
||||||
{
|
{
|
||||||
TFunction& functionDeclarator = parseContext.handleFunctionDeclarator(token.loc, function, false /* not prototype */);
|
parseContext.handleFunctionDeclarator(declarator.loc, *declarator.function, false /* not prototype */);
|
||||||
TSourceLoc loc = token.loc;
|
|
||||||
|
|
||||||
// we might get back and entry-point
|
return acceptFunctionBody(declarator, nodeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HlslGrammar::acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList)
|
||||||
|
{
|
||||||
|
// we might get back an entry-point
|
||||||
TIntermNode* entryPointNode = nullptr;
|
TIntermNode* entryPointNode = nullptr;
|
||||||
|
|
||||||
// This does a pushScope()
|
// This does a pushScope()
|
||||||
TIntermNode* functionNode = parseContext.handleFunctionDefinition(loc, functionDeclarator, attributes,
|
TIntermNode* functionNode = parseContext.handleFunctionDefinition(declarator.loc, *declarator.function,
|
||||||
entryPointNode);
|
declarator.attributes, entryPointNode);
|
||||||
|
|
||||||
// compound_statement
|
// compound_statement
|
||||||
TIntermNode* functionBody = nullptr;
|
TIntermNode* functionBody = nullptr;
|
||||||
@@ -2198,7 +2205,7 @@ bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& no
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// this does a popScope()
|
// this does a popScope()
|
||||||
parseContext.handleFunctionBody(loc, functionDeclarator, functionBody, functionNode);
|
parseContext.handleFunctionBody(declarator.loc, *declarator.function, functionBody, functionNode);
|
||||||
|
|
||||||
// Hook up the 1 or 2 function definitions.
|
// Hook up the 1 or 2 function definitions.
|
||||||
nodeList = intermediate.growAggregate(nodeList, functionNode);
|
nodeList = intermediate.growAggregate(nodeList, functionNode);
|
||||||
|
|||||||
@@ -43,7 +43,8 @@
|
|||||||
|
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
class TAttributeMap; // forward declare
|
class TAttributeMap;
|
||||||
|
class TFunctionDeclarator;
|
||||||
|
|
||||||
// Should just be the grammar aspect of HLSL.
|
// Should just be the grammar aspect of HLSL.
|
||||||
// Described in more detail in hlslGrammar.cpp.
|
// Described in more detail in hlslGrammar.cpp.
|
||||||
@@ -91,7 +92,8 @@ namespace glslang {
|
|||||||
const TType&, const TString& memberName);
|
const TType&, const TString& memberName);
|
||||||
bool acceptFunctionParameters(TFunction&);
|
bool acceptFunctionParameters(TFunction&);
|
||||||
bool acceptParameterDeclaration(TFunction&);
|
bool acceptParameterDeclaration(TFunction&);
|
||||||
bool acceptFunctionDefinition(TFunction&, TIntermNode*& nodeList, const TAttributeMap&);
|
bool acceptFunctionDefinition(TFunctionDeclarator&, TIntermNode*& nodeList);
|
||||||
|
bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList);
|
||||||
bool acceptParenExpression(TIntermTyped*&);
|
bool acceptParenExpression(TIntermTyped*&);
|
||||||
bool acceptExpression(TIntermTyped*&);
|
bool acceptExpression(TIntermTyped*&);
|
||||||
bool acceptInitializer(TIntermTyped*&);
|
bool acceptInitializer(TIntermTyped*&);
|
||||||
|
|||||||
@@ -1414,7 +1414,7 @@ void HlslParseContext::assignLocations(TVariable& variable)
|
|||||||
// Handle seeing a function declarator in the grammar. This is the precursor
|
// Handle seeing a function declarator in the grammar. This is the precursor
|
||||||
// to recognizing a function prototype or function definition.
|
// to recognizing a function prototype or function definition.
|
||||||
//
|
//
|
||||||
TFunction& HlslParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFunction& function, bool prototype)
|
void HlslParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFunction& function, bool prototype)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Multiple declarations of the same function name are allowed.
|
// Multiple declarations of the same function name are allowed.
|
||||||
@@ -1442,13 +1442,6 @@ TFunction& HlslParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFu
|
|||||||
// other forms of name collisions.
|
// other forms of name collisions.
|
||||||
if (! symbolTable.insert(function))
|
if (! symbolTable.insert(function))
|
||||||
error(loc, "function name is redeclaration of existing name", function.getName().c_str(), "");
|
error(loc, "function name is redeclaration of existing name", function.getName().c_str(), "");
|
||||||
|
|
||||||
//
|
|
||||||
// If this is a redeclaration, it could also be a definition,
|
|
||||||
// in which case, we need to use the parameter names from this one, and not the one that's
|
|
||||||
// being redeclared. So, pass back this declaration, not the one in the symbol table.
|
|
||||||
//
|
|
||||||
return function;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add interstage IO variables to the linkage in canonical order.
|
// Add interstage IO variables to the linkage in canonical order.
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public:
|
|||||||
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
TIntermTyped* handleDotDereference(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||||
bool isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
bool isBuiltInMethod(const TSourceLoc&, TIntermTyped* base, const TString& field);
|
||||||
void assignLocations(TVariable& variable);
|
void assignLocations(TVariable& variable);
|
||||||
TFunction& handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
|
void handleFunctionDeclarator(const TSourceLoc&, TFunction& function, bool prototype);
|
||||||
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributeMap&, TIntermNode*& entryPointTree);
|
TIntermAggregate* handleFunctionDefinition(const TSourceLoc&, TFunction&, const TAttributeMap&, TIntermNode*& entryPointTree);
|
||||||
TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributeMap&);
|
TIntermNode* transformEntryPoint(const TSourceLoc&, TFunction&, const TAttributeMap&);
|
||||||
void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node);
|
void handleFunctionBody(const TSourceLoc&, TFunction&, TIntermNode* functionBody, TIntermNode*& node);
|
||||||
|
|||||||
Reference in New Issue
Block a user