Create a new ppRequireExtensions method for preprocessor.
Now extensions required by preprocessor should be checked via the ppRequireExtensions method. This is more clear and coherent with the rest of the code.
This commit is contained in:
parent
1eed969b2d
commit
484bb12703
@ -236,7 +236,8 @@ public:
|
|||||||
void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc);
|
void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc);
|
||||||
void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc);
|
void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc);
|
||||||
void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc);
|
void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc);
|
||||||
void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc, bool requiredByPreprocessor = false);
|
void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
|
||||||
|
void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
|
||||||
TExtensionBehavior getExtensionBehavior(const char*);
|
TExtensionBehavior getExtensionBehavior(const char*);
|
||||||
bool extensionTurnedOn(const char* const extension);
|
bool extensionTurnedOn(const char* const extension);
|
||||||
bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);
|
bool extensionsTurnedOn(int numExtensions, const char* const extensions[]);
|
||||||
@ -259,6 +260,7 @@ protected:
|
|||||||
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
|
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
|
||||||
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
|
TIntermTyped* convertInitializerList(const TSourceLoc&, const TType&, TIntermTyped* initializer);
|
||||||
TOperator mapTypeToConstructorOp(const TType&) const;
|
TOperator mapTypeToConstructorOp(const TType&) const;
|
||||||
|
bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
|
||||||
void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
|
void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
|
||||||
void finalErrorCheck();
|
void finalErrorCheck();
|
||||||
void outputMessage(const TSourceLoc&, const char* szReason, const char* szToken,
|
void outputMessage(const TSourceLoc&, const char* szReason, const char* szToken,
|
||||||
|
@ -411,17 +411,15 @@ void TParseContext::requireNotRemoved(const TSourceLoc& loc, int profileMask, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// Returns true if at least one of the extensions in the extensions parameter is requested. Otherwise, returns false.
|
||||||
// Use when there are no profile/version to check, it's just an error if one of the
|
// Warns appropriately if the requested behavior of an extension is "warn".
|
||||||
// extensions is not present.
|
bool TParseContext::checkExtensionsRequested(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
|
||||||
//
|
|
||||||
void TParseContext::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc, bool requiredByPreprocessor)
|
|
||||||
{
|
{
|
||||||
// First, see if any of the extensions are enabled
|
// First, see if any of the extensions are enabled
|
||||||
for (int i = 0; i < numExtensions; ++i) {
|
for (int i = 0; i < numExtensions; ++i) {
|
||||||
TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
|
TExtensionBehavior behavior = getExtensionBehavior(extensions[i]);
|
||||||
if (behavior == EBhEnable || behavior == EBhRequire)
|
if (behavior == EBhEnable || behavior == EBhRequire)
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if any extensions want to give a warning on use; give warnings for all such extensions
|
// See if any extensions want to give a warning on use; give warnings for all such extensions
|
||||||
@ -438,24 +436,46 @@ void TParseContext::requireExtensions(const TSourceLoc& loc, int numExtensions,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (warned)
|
if (warned)
|
||||||
return;
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use when there are no profile/version to check, it's just an error if one of the
|
||||||
|
// extensions is not present.
|
||||||
|
//
|
||||||
|
void TParseContext::requireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
|
||||||
|
{
|
||||||
|
if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc)) return;
|
||||||
|
|
||||||
// If we get this far, give errors explaining what extensions are needed
|
// If we get this far, give errors explaining what extensions are needed
|
||||||
if (numExtensions == 1)
|
if (numExtensions == 1)
|
||||||
if (requiredByPreprocessor)
|
|
||||||
ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
|
|
||||||
else
|
|
||||||
error(loc, "required extension not requested:", featureDesc, extensions[0]);
|
error(loc, "required extension not requested:", featureDesc, extensions[0]);
|
||||||
else {
|
else {
|
||||||
if (requiredByPreprocessor)
|
|
||||||
ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
|
|
||||||
else
|
|
||||||
error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
|
error(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
|
||||||
for (int i = 0; i < numExtensions; ++i)
|
for (int i = 0; i < numExtensions; ++i)
|
||||||
infoSink.info.message(EPrefixNone, extensions[i]);
|
infoSink.info.message(EPrefixNone, extensions[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use by preprocessor when there are no profile/version to check, it's just an error if one of the
|
||||||
|
// extensions is not present.
|
||||||
|
//
|
||||||
|
void TParseContext::ppRequireExtensions(const TSourceLoc& loc, int numExtensions, const char* const extensions[], const char* featureDesc)
|
||||||
|
{
|
||||||
|
if (checkExtensionsRequested(loc, numExtensions, extensions, featureDesc)) return;
|
||||||
|
|
||||||
|
// If we get this far, give errors explaining what extensions are needed
|
||||||
|
if (numExtensions == 1)
|
||||||
|
ppError(loc, "required extension not requested:", featureDesc, extensions[0]);
|
||||||
|
else {
|
||||||
|
ppError(loc, "required extension not requested:", featureDesc, "Possible extensions include:");
|
||||||
|
for (int i = 0; i < numExtensions; ++i)
|
||||||
|
infoSink.info.message(EPrefixNone, extensions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TExtensionBehavior TParseContext::getExtensionBehavior(const char* extension)
|
TExtensionBehavior TParseContext::getExtensionBehavior(const char* extension)
|
||||||
{
|
{
|
||||||
auto iter = extensionBehavior.find(TString(extension));
|
auto iter = extensionBehavior.find(TString(extension));
|
||||||
|
@ -675,7 +675,7 @@ int TPpContext::CPPline(TPpToken* ppToken)
|
|||||||
|
|
||||||
if (token != '\n') {
|
if (token != '\n') {
|
||||||
if (token == PpAtomConstString) {
|
if (token == PpAtomConstString) {
|
||||||
parseContext.requireExtensions(directiveLoc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based #line", true);
|
parseContext.ppRequireExtensions(directiveLoc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based #line");
|
||||||
// We need to save a copy of the string instead of pointing
|
// We need to save a copy of the string instead of pointing
|
||||||
// to the name field of the token since the name field
|
// to the name field of the token since the name field
|
||||||
// will likely be overwritten by the next token scan.
|
// will likely be overwritten by the next token scan.
|
||||||
@ -892,7 +892,7 @@ int TPpContext::readCPPline(TPpToken* ppToken)
|
|||||||
token = CPPifdef(0, ppToken);
|
token = CPPifdef(0, ppToken);
|
||||||
break;
|
break;
|
||||||
case PpAtomInclude:
|
case PpAtomInclude:
|
||||||
parseContext.requireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_include_directive, "#include", true);
|
parseContext.ppRequireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_include_directive, "#include");
|
||||||
token = CPPinclude(ppToken);
|
token = CPPinclude(ppToken);
|
||||||
break;
|
break;
|
||||||
case PpAtomLine:
|
case PpAtomLine:
|
||||||
@ -1017,7 +1017,7 @@ int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool
|
|||||||
|
|
||||||
case PpAtomFileMacro: {
|
case PpAtomFileMacro: {
|
||||||
if (const char* current_file = parseContext.getCurrentLoc().name) {
|
if (const char* current_file = parseContext.getCurrentLoc().name) {
|
||||||
parseContext.requireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based __FILE__", true);
|
parseContext.ppRequireExtensions(ppToken->loc, 1, &E_GL_GOOGLE_cpp_style_line_directive, "filename-based __FILE__");
|
||||||
sprintf(ppToken->name, "\"%s\"", current_file);
|
sprintf(ppToken->name, "\"%s\"", current_file);
|
||||||
} else {
|
} else {
|
||||||
ppToken->ival = parseContext.getCurrentLoc().string;
|
ppToken->ival = parseContext.getCurrentLoc().string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user