From 51cdd90fa80f81b3f6162f3b26ece8b9f0df30e7 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Tue, 18 Feb 2014 23:37:57 +0000 Subject: [PATCH] Fix the few non-portable uses of "char" (where a -1 might be relevant): All uses of char are now either "int", "unsigned char" or char arrays for storing strings. Also, went to consistent "char* foo" coding convention. (There were only a few ambiguous uses.) git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@25400 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- StandAlone/StandAlone.cpp | 18 +++++++-------- glslang/Include/InfoSink.h | 2 +- glslang/Include/Types.h | 4 ++-- glslang/Include/revision.h | 4 ++-- glslang/MachineIndependent/InfoSink.cpp | 2 +- glslang/MachineIndependent/ParseHelper.cpp | 10 ++++----- glslang/MachineIndependent/ParseHelper.h | 26 +++++++++++----------- glslang/MachineIndependent/PoolAlloc.cpp | 4 ++-- glslang/MachineIndependent/Scan.cpp | 8 +++---- glslang/MachineIndependent/Scan.h | 6 ++--- glslang/MachineIndependent/Versions.cpp | 16 ++++++------- glslang/MachineIndependent/preprocessor/PpAtom.cpp | 10 ++++----- .../MachineIndependent/preprocessor/PpContext.h | 22 +++++++++--------- .../MachineIndependent/preprocessor/PpSymbols.cpp | 6 ++--- .../MachineIndependent/preprocessor/PpTokens.cpp | 6 ++--- 15 files changed, 72 insertions(+), 72 deletions(-) diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index e917c20..dd07657 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -93,7 +93,7 @@ ShBinding FixedAttributeBindings[] = { ShBindingTable FixedAttributeTable = { 3, FixedAttributeBindings }; EShLanguage FindLanguage(const std::string& name); -void CompileFile(const char *fileName, ShHandle); +void CompileFile(const char* fileName, ShHandle); void usage(); void FreeFileData(char** data); char** ReadFileData(const char* fileName); @@ -212,7 +212,7 @@ const char* DefaultConfig = void ProcessConfigFile() { char** configStrings = 0; - char *config = 0; + char* config = 0; if (ConfigFile.size() > 0) { configStrings = ReadFileData(ConfigFile.c_str()); if (configStrings) @@ -746,7 +746,7 @@ EShLanguage FindLanguage(const std::string& name) // Read a file's data into a string, and compile it using the old interface ShCompile, // for non-linkable results. // -void CompileFile(const char *fileName, ShHandle compiler) +void CompileFile(const char* fileName, ShHandle compiler) { int ret; char** shaderStrings = ReadFileData(fileName); @@ -832,8 +832,8 @@ void usage() int fopen_s( FILE** pFile, - const char *filename, - const char *mode + const char* filename, + const char* mode ) { if (!pFile || !filename || !mode) { @@ -858,11 +858,11 @@ int fopen_s( // // Malloc a string of sufficient size and read a string into it. // -char** ReadFileData(const char *fileName) +char** ReadFileData(const char* fileName) { FILE *in; int errorCode = fopen_s(&in, fileName, "r"); - char *fdata; + char* fdata; int count = 0; const int maxSourceStrings = 5; char** return_data = (char**)malloc(maxSourceStrings+1); @@ -879,7 +879,7 @@ char** ReadFileData(const char *fileName) fseek(in, 0, SEEK_SET); - if (!(fdata = (char *)malloc(count+2))) { + if (!(fdata = (char*)malloc(count+2))) { printf("Error allocating memory\n"); return 0; } @@ -917,7 +917,7 @@ char** ReadFileData(const char *fileName) return return_data; } -void FreeFileData(char **data) +void FreeFileData(char** data) { for(int i=0;i(inUseList) + currentPageOffset; + unsigned char* memory = reinterpret_cast(inUseList) + currentPageOffset; currentPageOffset += allocationSize; currentPageOffset = (currentPageOffset + alignmentMask) & ~alignmentMask; @@ -320,7 +320,7 @@ void* TPoolAllocator::allocate(size_t numBytes) new(memory) tHeader(inUseList, 1); inUseList = memory; - unsigned char* ret = reinterpret_cast(inUseList) + headerSkip; + unsigned char* ret = reinterpret_cast(inUseList) + headerSkip; currentPageOffset = (headerSkip + allocationSize + alignmentMask) & ~alignmentMask; return initializeAllocation(inUseList, ret, numBytes); diff --git a/glslang/MachineIndependent/Scan.cpp b/glslang/MachineIndependent/Scan.cpp index fa2dd5b..0a2a237 100644 --- a/glslang/MachineIndependent/Scan.cpp +++ b/glslang/MachineIndependent/Scan.cpp @@ -56,7 +56,7 @@ namespace glslang { // read past any white space void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab) { - char c = peek(); // don't accidentally consume anything other than whitespace + int c = peek(); // don't accidentally consume anything other than whitespace while (c == ' ' || c == '\t' || c == '\r' || c == '\n') { if (c == '\r' || c == '\n') foundNonSpaceTab = true; @@ -72,7 +72,7 @@ bool TInputScanner::consumeComment() return false; get(); // consume the '/' - char c = peek(); + int c = peek(); if (c == '/') { // a '//' style comment @@ -139,7 +139,7 @@ void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab) consumeWhiteSpace(foundNonSpaceTab); // if not starting a comment now, then done - char c = peek(); + int c = peek(); if (c != '/' || c < 0) return; @@ -176,7 +176,7 @@ bool TInputScanner::scanVersion(int& version, EProfile& profile) return true; // whitespace - char c; + int c; do { c = get(); } while (c == ' ' || c == '\t'); diff --git a/glslang/MachineIndependent/Scan.h b/glslang/MachineIndependent/Scan.h index bd6b80f..1c6dd6a 100644 --- a/glslang/MachineIndependent/Scan.h +++ b/glslang/MachineIndependent/Scan.h @@ -62,12 +62,12 @@ public: // anything else is the next character // retrieve the next character and advance one character - char get() + int get() { if (currentSource >= numSources) return -1; - char ret = sources[currentSource][currentChar]; + int ret = sources[currentSource][currentChar]; if (ret == '\n') ++loc[currentSource].line; advance(); @@ -76,7 +76,7 @@ public: } // retrieve the next character, no advance - char peek() + int peek() { if (currentSource >= numSources) return -1; diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 00ad793..f4ba5b3 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -226,7 +226,7 @@ const char* ProfileName(EProfile profile) // Operation: If the current profile is not one of the profileMask, // give an error message. // -void TParseContext::requireProfile(TSourceLoc loc, int profileMask, const char *featureDesc) +void TParseContext::requireProfile(TSourceLoc loc, int profileMask, const char* featureDesc) { if (! (profile & profileMask)) error(loc, "not supported with this profile:", featureDesc, ProfileName(profile)); @@ -265,7 +265,7 @@ const char* StageName(EShLanguage stage) // // entry point that takes multiple extensions -void TParseContext::profileRequires(TSourceLoc loc, int profileMask, int minVersion, int numExtensions, const char* const extensions[], const char *featureDesc) +void TParseContext::profileRequires(TSourceLoc loc, int profileMask, int minVersion, int numExtensions, const char* const extensions[], const char* featureDesc) { if (profile & profileMask) { bool okay = false; @@ -290,7 +290,7 @@ void TParseContext::profileRequires(TSourceLoc loc, int profileMask, int minVers } // entry point for the above that takes a single extension -void TParseContext::profileRequires(TSourceLoc loc, int profileMask, int minVersion, const char* extension, const char *featureDesc) +void TParseContext::profileRequires(TSourceLoc loc, int profileMask, int minVersion, const char* extension, const char* featureDesc) { profileRequires(loc, profileMask, minVersion, extension ? 1 : 0, &extension, featureDesc); } @@ -302,7 +302,7 @@ void TParseContext::profileRequires(TSourceLoc loc, int profileMask, int minVers // // Operation: If the current stage is not present, give an error message. // -void TParseContext::requireStage(TSourceLoc loc, EShLanguageMask languageMask, const char *featureDesc) +void TParseContext::requireStage(TSourceLoc loc, EShLanguageMask languageMask, const char* featureDesc) { if (((1 << language) & languageMask) == 0) error(loc, "not supported in this stage:", featureDesc, StageName(language)); @@ -310,7 +310,7 @@ void TParseContext::requireStage(TSourceLoc loc, EShLanguageMask languageMask, c // If only one stage supports a feature, this can be called. But, all supporting stages // must be specified with one call. -void TParseContext::requireStage(TSourceLoc loc, EShLanguage stage, const char *featureDesc) +void TParseContext::requireStage(TSourceLoc loc, EShLanguage stage, const char* featureDesc) { requireStage(loc, static_cast(1 << stage), featureDesc); } @@ -319,7 +319,7 @@ void TParseContext::requireStage(TSourceLoc loc, EShLanguage stage, const char * // Within a set of profiles, see if a feature is deprecated and give an error or warning based on whether // a future compatibility context is being use. // -void TParseContext::checkDeprecated(TSourceLoc loc, int profileMask, int depVersion, const char *featureDesc) +void TParseContext::checkDeprecated(TSourceLoc loc, int profileMask, int depVersion, const char* featureDesc) { if (profile & profileMask) { if (version >= depVersion) { @@ -336,7 +336,7 @@ void TParseContext::checkDeprecated(TSourceLoc loc, int profileMask, int depVers // Within a set of profiles, see if a feature has now been removed and if so, give an error. // The version argument is the first version no longer having the feature. // -void TParseContext::requireNotRemoved(TSourceLoc loc, int profileMask, int removedVersion, const char *featureDesc) +void TParseContext::requireNotRemoved(TSourceLoc loc, int profileMask, int removedVersion, const char* featureDesc) { if (profile & profileMask) { if (version >= removedVersion) { @@ -352,7 +352,7 @@ void TParseContext::requireNotRemoved(TSourceLoc loc, int profileMask, int remov // 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(TSourceLoc loc, int numExtensions, const char* const extensions[], const char *featureDesc) +void TParseContext::requireExtensions(TSourceLoc loc, int numExtensions, const char* const extensions[], const char* featureDesc) { // First, see if any of the extensions are enabled for (int i = 0; i < numExtensions; ++i) { diff --git a/glslang/MachineIndependent/preprocessor/PpAtom.cpp b/glslang/MachineIndependent/preprocessor/PpAtom.cpp index f4537a6..b6609da 100644 --- a/glslang/MachineIndependent/preprocessor/PpAtom.cpp +++ b/glslang/MachineIndependent/preprocessor/PpAtom.cpp @@ -96,7 +96,7 @@ using namespace glslang; const struct { int val; - const char *str; + const char* str; } tokens[] = { { CPP_AND_OP, "&&" }, { CPP_AND_ASSIGN, "&=" }, @@ -128,7 +128,7 @@ namespace glslang { // // Map a new or existing string to an atom, inventing a new atom if necessary. // -int TPpContext::LookUpAddString(const char *s) +int TPpContext::LookUpAddString(const char* s) { TAtomMap::const_iterator it = atomMap.find(s); if (it == atomMap.end()) @@ -140,7 +140,7 @@ int TPpContext::LookUpAddString(const char *s) // // Map an already created atom to its string. // -const char *TPpContext::GetAtomString(int atom) +const char* TPpContext::GetAtomString(int atom) { if (atom == 0) return ""; @@ -159,7 +159,7 @@ const char *TPpContext::GetAtomString(int atom) // // Add forced mapping of string to atom. // -int TPpContext::AddAtomFixed(const char *s, int atom) +int TPpContext::AddAtomFixed(const char* s, int atom) { TAtomMap::const_iterator it = atomMap.insert(std::pair(s, atom)).first; if (stringMap.size() < (size_t)atom + 1) @@ -175,7 +175,7 @@ int TPpContext::AddAtomFixed(const char *s, int atom) void TPpContext::InitAtomTable() { // Add single character tokens to the atom table: - const char *s = "~!%^&*()-+=|,.<>/?;:[]{}#"; + const char* s = "~!%^&*()-+=|,.<>/?;:[]{}#"; char t[2]; t[1] = '\0'; diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 213bdc7..69edc2c 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -232,7 +232,7 @@ protected: int ifdepth; // current #if-#else-#endif nesting in the cpp.c file (pre-processor) bool elseSeen[maxIfNesting]; // Keep a track of whether an else has been seen at a particular depth int elsetracker; // #if-#else and #endif constructs...Counter. - const char *ErrMsg; + const char* ErrMsg; class tMacroInput : public tInput { public: @@ -371,17 +371,17 @@ protected: class tStringInput : public tInput { public: tStringInput(TPpContext* pp, TInputScanner& i) : tInput(pp), input(&i) { } - virtual int scan(TPpToken *); + virtual int scan(TPpToken*); virtual int getch(); virtual void ungetch(); protected: TInputScanner* input; }; - int InitScanner(TPpContext *cpp); - int ScanFromString(char *s); + int InitScanner(TPpContext* cpp); + int ScanFromString(char* s); void missingEndifCheck(); - int lFloatConst(char *str, int len, int ch, TPpToken * ppToken); + int lFloatConst(char* str, int len, int ch, TPpToken* ppToken); bool inComment; @@ -394,17 +394,17 @@ protected: TStringMap stringMap; int nextAtom; void InitAtomTable(); - int AddAtomFixed(const char *s, int atom); - int LookUpAddString(const char *s); - const char *GetAtomString(int atom); + int AddAtomFixed(const char* s, int atom); + int LookUpAddString(const char* s); + const char* GetAtomString(int atom); // // From PpMemory.cpp // MemoryPool *mem_CreatePool(size_t chunksize, unsigned align); - void mem_FreePool(MemoryPool *); - void *mem_Alloc(MemoryPool *p, size_t size); - int mem_AddCleanup(MemoryPool *p, void (*fn)(void *, void*), void *arg1, void* arg2); + void mem_FreePool(MemoryPool*); + void *mem_Alloc(MemoryPool* p, size_t size); + int mem_AddCleanup(MemoryPool* p, void (*fn)(void *, void*), void* arg1, void* arg2); }; } // end namespace glslang diff --git a/glslang/MachineIndependent/preprocessor/PpSymbols.cpp b/glslang/MachineIndependent/preprocessor/PpSymbols.cpp index 590c186..3ae7264 100644 --- a/glslang/MachineIndependent/preprocessor/PpSymbols.cpp +++ b/glslang/MachineIndependent/preprocessor/PpSymbols.cpp @@ -98,15 +98,15 @@ namespace glslang { */ TPpContext::Symbol* TPpContext::NewSymbol(int atom) { - Symbol *lSymb; - char *pch; + Symbol* lSymb; + char* pch; int ii; lSymb = (Symbol *) mem_Alloc(pool, sizeof(Symbol)); lSymb->atom = atom; // Clear macro - pch = (char *) &lSymb->mac; + pch = (char*) &lSymb->mac; for (ii = 0; ii < sizeof(lSymb->mac); ii++) *pch++ = 0; diff --git a/glslang/MachineIndependent/preprocessor/PpTokens.cpp b/glslang/MachineIndependent/preprocessor/PpTokens.cpp index 98228a6..ad555fc 100644 --- a/glslang/MachineIndependent/preprocessor/PpTokens.cpp +++ b/glslang/MachineIndependent/preprocessor/PpTokens.cpp @@ -117,8 +117,8 @@ int TPpContext::lReadByte(TokenStream *pTok) */ void TPpContext::RecordToken(TokenStream *pTok, int token, TPpToken* ppToken) { - const char *s; - char *str = NULL; + const char* s; + char* str = NULL; if (token > 256) lAddByte(pTok, (unsigned char)((token & 0x7f) + 0x80)); @@ -164,7 +164,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken) { char tokenText[TPpToken::maxTokenLength + 1]; int ltoken, len; - char ch; + int ch; ltoken = lReadByte(pTok); ppToken->loc = parseContext.getCurrentLoc(); -- 2.7.4