// 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.1706"
-#define GLSLANG_DATE "19-Dec-2016"
+#define GLSLANG_REVISION "Overload400-PrecQual.1713"
+#define GLSLANG_DATE "20-Dec-2016"
do {
parserToken = &token;
TPpToken ppToken;
- tokenText = pp->tokenize(&ppToken);
+ tokenText = pp->tokenize(ppToken);
if (tokenText == nullptr || tokenText[0] == 0)
return 0;
// This is a list of tokens that do not require a space before or after.
static const std::string unNeededSpaceTokens = ";()[]";
static const std::string noSpaceBeforeTokens = ",";
- glslang::TPpToken token;
+ glslang::TPpToken ppToken;
parseContext.setScanner(&input);
ppContext.setInput(input, versionWillBeError);
});
int lastToken = EndOfInput; // lastToken records the last token processed.
- while (const char* tok = ppContext.tokenize(&token)) {
+ while (const char* tok = ppContext.tokenize(ppToken)) {
bool isNewString = lineSync.syncToMostRecentString();
- bool isNewLine = lineSync.syncToLine(token.loc.line);
+ bool isNewLine = lineSync.syncToLine(ppToken.loc.line);
if (isNewLine) {
// Don't emit whitespace onto empty lines.
// Copy any whitespace characters at the start of a line
// from the input to the output.
- outputStream << std::string(token.loc.column - 1, ' ');
+ outputStream << std::string(ppToken.loc.column - 1, ' ');
}
// Output a space in between tokens, but not at the start of a line,
// and also not around special tokens. This helps with readability
// and consistency.
if (!isNewString && !isNewLine && lastToken != EndOfInput &&
- (unNeededSpaceTokens.find((char)token.token) == std::string::npos) &&
+ (unNeededSpaceTokens.find((char)ppToken.token) == std::string::npos) &&
(unNeededSpaceTokens.find((char)lastToken) == std::string::npos) &&
- (noSpaceBeforeTokens.find((char)token.token) == std::string::npos)) {
+ (noSpaceBeforeTokens.find((char)ppToken.token) == std::string::npos)) {
outputStream << " ";
}
- lastToken = token.token;
+ lastToken = ppToken.token;
outputStream << tok;
}
outputStream << std::endl;
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
-//
-// cpp.c
-//
#define _CRT_SECURE_NO_WARNINGS
parseContext.reservedPpErrorCheck(ppToken->loc, ppToken->name, "#define");
}
- // save the original atom
+ // save the original macro name
const int defAtom = ppToken->atom;
// gather parameters to the macro, between (...)
*/
int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
{
- int atom;
int depth = 0;
int token = scanToken(ppToken);
if ((token = scanToken(ppToken)) != PpAtomIdentifier)
continue;
- atom = ppToken->atom;
+ int atom = ppToken->atom;
if (atom == PpAtomIf || atom == PpAtomIfdef || atom == PpAtomIfndef) {
depth++;
ifdepth++;
int TPpContext::evalToToken(int token, bool shortCircuit, int& res, bool& err, TPpToken* ppToken)
{
while (token == PpAtomIdentifier && ppToken->atom != PpAtomDefined) {
- int macroReturn = MacroExpand(ppToken->atom, ppToken, true, false);
+ int macroReturn = MacroExpand(ppToken, true, false);
if (macroReturn == 0) {
parseContext.ppError(ppToken->loc, "can't evaluate expression", "preprocessor evaluation", "");
err = true;
pushInput(new tMarkerInput(this));
pushTokenStreamInput(arg);
while ((token = scanToken(ppToken)) != tMarkerInput::marker) {
- if (token == PpAtomIdentifier && MacroExpand(ppToken->atom, ppToken, false, newLineOkay) != 0)
+ if (token == PpAtomIdentifier && MacroExpand(ppToken, false, newLineOkay) != 0)
continue;
RecordToken(*expandedArg, token, ppToken);
}
}
//
-// Check an identifier (atom) to see if it is a macro that should be expanded.
+// Check a token to see if it is a macro that should be expanded.
// If it is, and defined, push a tInput that will produce the appropriate expansion
// and return 1.
// If it is, but undefined, and expandUndef is requested, push a tInput that will
// expand to 0 and return -1.
// Otherwise, return 0 to indicate no expansion, which is not necessarily an error.
//
-int TPpContext::MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool newLineOkay)
+int TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay)
{
ppToken->space = false;
- switch (atom) {
+ switch (ppToken->atom) {
case PpAtomLineMacro:
ppToken->ival = parseContext.getCurrentLoc().line;
snprintf(ppToken->name, sizeof(ppToken->name), "%d", ppToken->ival);
break;
}
- MacroSymbol* macro = lookupMacroDef(atom);
+ MacroSymbol* macro = lookupMacroDef(ppToken->atom);
int token;
int depth = 0;
TSourceLoc loc = ppToken->loc; // in case we go to the next line before discovering the error
in->mac = macro;
+ int atom = ppToken->atom;
if (macro->args.size() > 0 || macro->emptyArgs) {
token = scanToken(ppToken);
if (newLineOkay) {
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
-//
-// atom.c
-//
-
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
}
//
-// Map an already created atom to its string.
+// Lookup up mapping of atom -> string.
//
const char* TPpContext::GetAtomString(int atom)
{
}
//
-// Add forced mapping of string to atom.
+// Add mappings:
+// - string -> atom
+// - atom -> string
//
void TPpContext::AddAtomFixed(const char* s, int atom)
{
void setPreamble(const char* preamble, size_t length);
- const char* tokenize(TPpToken* ppToken);
- int tokenPaste(TPpToken&);
+ const char* tokenize(TPpToken& ppToken);
+ int tokenPaste(int token, TPpToken&);
class tInput {
public:
int CPPextension(TPpToken * ppToken);
int readCPPline(TPpToken * ppToken);
TokenStream* PrescanMacroArg(TokenStream&, TPpToken*, bool newLineOkay);
- int MacroExpand(int atom, TPpToken* ppToken, bool expandUndef, bool newLineOkay);
+ int MacroExpand(TPpToken* ppToken, bool expandUndef, bool newLineOkay);
//
// From PpTokens.cpp
}
bool inComment;
+ std::string rootFileName;
+ std::stack<TShader::Includer::IncludeResult*> includeStack;
+ std::string currentSourceFile;
//
// From PpAtom.cpp
TAtomMap atomMap;
TStringMap stringMap;
- std::stack<TShader::Includer::IncludeResult*> includeStack;
- std::string currentSourceFile;
- std::string rootFileName;
int nextAtom;
void InitAtomTable();
void AddAtomFixed(const char* s, int atom);
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
-//
-// scanner.c
-//
#define _CRT_SECURE_NO_WARNINGS
// Return string pointer to next token.
// Return 0 when no more tokens.
//
-const char* TPpContext::tokenize(TPpToken* ppToken)
+const char* TPpContext::tokenize(TPpToken& ppToken)
{
- int token = '\n';
-
for(;;) {
- token = scanToken(ppToken);
- ppToken->token = token;
+ int token = scanToken(&ppToken);
// Handle token-pasting logic
- token = tokenPaste(*ppToken);
- ppToken->token = token;
+ token = tokenPaste(token, ppToken);
+ ppToken.token = token;
if (token == EndOfInput) {
missingEndifCheck();
}
if (token == '#') {
if (previous_token == '\n') {
- token = readCPPline(ppToken);
+ token = readCPPline(&ppToken);
if (token == EndOfInput) {
missingEndifCheck();
return nullptr;
}
continue;
} else {
- parseContext.ppError(ppToken->loc, "preprocessor directive cannot be preceded by another token", "#", "");
+ parseContext.ppError(ppToken.loc, "preprocessor directive cannot be preceded by another token", "#", "");
return nullptr;
}
}
continue;
// expand macros
- if (token == PpAtomIdentifier && MacroExpand(ppToken->atom, ppToken, false, true) != 0)
+ if (token == PpAtomIdentifier && MacroExpand(&ppToken, false, true) != 0)
continue;
const char* tokenString = nullptr;
#ifdef AMD_EXTENSIONS
case PpAtomConstFloat16:
#endif
- tokenString = ppToken->name;
+ tokenString = ppToken.name;
break;
case PpAtomConstString:
if (parseContext.intermediate.getSource() == EShSourceHlsl) {
// HLSL allows string literals.
- tokenString = ppToken->name;
+ tokenString = ppToken.name;
} else {
- parseContext.ppError(ppToken->loc, "string literals not supported", "\"\"", "");
+ parseContext.ppError(ppToken.loc, "string literals not supported", "\"\"", "");
}
break;
case '\'':
- parseContext.ppError(ppToken->loc, "character literals not supported", "\'", "");
+ parseContext.ppError(ppToken.loc, "character literals not supported", "\'", "");
break;
default:
tokenString = GetAtomString(token);
// stream of tokens from a replacement list. Degenerates to no processing if a
// replacement list is not the source of the token stream.
//
-int TPpContext::tokenPaste(TPpToken& ppToken)
+int TPpContext::tokenPaste(int token, TPpToken& ppToken)
{
// starting with ## is illegal, skip to next token
- if (ppToken.token == PpAtomPaste) {
+ if (token == PpAtomPaste) {
parseContext.ppError(ppToken.loc, "unexpected location", "##", "");
- ppToken.token = scanToken(&ppToken);
+ return scanToken(&ppToken);
}
+ int resultToken = token; // "foo" pasted with "35" is an identifier, not a number
+
// ## can be chained, process all in the chain at once
while (peekPasting()) {
TPpToken pastedPpToken;
// next token has to be ##
- pastedPpToken.token = scanToken(&pastedPpToken);
- assert(pastedPpToken.token == PpAtomPaste);
+ token = scanToken(&pastedPpToken);
+ assert(token == PpAtomPaste);
if (endOfReplacementList()) {
parseContext.ppError(ppToken.loc, "unexpected location; end of replacement list", "##", "");
}
// get the token after the ##
- scanToken(&pastedPpToken);
+ token = scanToken(&pastedPpToken);
// combine the tokens
+ if (resultToken != PpAtomIdentifier)
+ parseContext.ppError(ppToken.loc, "only supported for preprocessing identifiers", "##", "");
if (strlen(ppToken.name) + strlen(pastedPpToken.name) > MaxTokenLength)
parseContext.ppError(ppToken.loc, "combined tokens are too long", "##", "");
strncat(ppToken.name, pastedPpToken.name, MaxTokenLength - strlen(ppToken.name));
ppToken.atom = LookUpAddString(ppToken.name);
- if (ppToken.token != PpAtomIdentifier)
- parseContext.ppError(ppToken.loc, "only supported for preprocessing identifiers", "##", "");
}
- return ppToken.token;
+ return resultToken;
}
// Checks if we've seen balanced #if...#endif
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
-//
-// symbols.c
-//
-
-#include <cassert>
-#include <cstdlib>
-#include <cstring>
-
-#include "PpContext.h"
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////// Symbol Table Variables: ///////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-namespace glslang {
-
-} // end namespace glslang
*/
int TPpContext::ReadToken(TokenStream& pTok, TPpToken *ppToken)
{
- char* tokenText = ppToken->name;
int ltoken, len;
int ch;
ch = lReadByte(pTok);
while (ch != 0 && ch != EndOfInput) {
if (len < MaxTokenLength) {
- tokenText[len] = (char)ch;
+ ppToken->name[len] = (char)ch;
len++;
ch = lReadByte(pTok);
} else {
break;
}
}
- tokenText[len] = 0;
+ ppToken->name[len] = 0;
switch (ltoken) {
case PpAtomIdentifier:
- ppToken->atom = LookUpAddString(tokenText);
+ ppToken->atom = LookUpAddString(ppToken->name);
break;
case PpAtomConstString:
break;
ppToken->dval = atof(ppToken->name);
break;
case PpAtomConstInt:
- if (len > 0 && tokenText[0] == '0') {
- if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
+ if (len > 0 && ppToken->name[0] == '0') {
+ if (len > 1 && (ppToken->name[1] == 'x' || ppToken->name[1] == 'X'))
ppToken->ival = (int)strtol(ppToken->name, 0, 16);
else
ppToken->ival = (int)strtol(ppToken->name, 0, 8);
ppToken->ival = atoi(ppToken->name);
break;
case PpAtomConstUint:
- if (len > 0 && tokenText[0] == '0') {
- if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
+ if (len > 0 && ppToken->name[0] == '0') {
+ if (len > 1 && (ppToken->name[1] == 'x' || ppToken->name[1] == 'X'))
ppToken->ival = (int)strtoul(ppToken->name, 0, 16);
else
ppToken->ival = (int)strtoul(ppToken->name, 0, 8);
ppToken->ival = (int)strtoul(ppToken->name, 0, 10);
break;
case PpAtomConstInt64:
- if (len > 0 && tokenText[0] == '0') {
- if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
+ if (len > 0 && ppToken->name[0] == '0') {
+ if (len > 1 && (ppToken->name[1] == 'x' || ppToken->name[1] == 'X'))
ppToken->i64val = strtoll(ppToken->name, nullptr, 16);
else
ppToken->i64val = strtoll(ppToken->name, nullptr, 8);
ppToken->i64val = atoll(ppToken->name);
break;
case PpAtomConstUint64:
- if (len > 0 && tokenText[0] == '0') {
- if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
+ if (len > 0 && ppToken->name[0] == '0') {
+ if (len > 1 && (ppToken->name[1] == 'x' || ppToken->name[1] == 'X'))
ppToken->i64val = (long long)strtoull(ppToken->name, nullptr, 16);
else
ppToken->i64val = (long long)strtoull(ppToken->name, nullptr, 8);
do {
parserToken = &token;
TPpToken ppToken;
- tokenText = ppContext.tokenize(&ppToken);
+ tokenText = ppContext.tokenize(ppToken);
if (tokenText == nullptr)
return EHTokNone;