Preprocessor: Rationalize, simplify, and correct the stack of input sources and their tokenization. This included

- consistently dealing with EOF and its effect on error recovery (bug 11444, #1)
 - turning a simulated OO hierarchy of function pointers and typecasting into a real C++ class hierarchy
 - correctly handling '\' everywhere, in all classes of tokens, as a layer before preprocessing itself
 - conditionally handling '\n' in macro expansion input, depending on whether it is in a macro expression or not
 - delete some unused "memory cleanup" code


git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24626 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-12-30 20:34:28 +00:00
parent 08d182470b
commit fcb4ed054c
16 changed files with 750 additions and 479 deletions

View file

@ -75,7 +75,7 @@ NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT,
TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\****************************************************************************/
//
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@ -93,13 +93,6 @@ struct chunk {
struct chunk *next;
};
struct cleanup {
struct cleanup *next;
void (*fn)(void *, void *);
void *arg1;
void *arg2;
};
TPpContext::MemoryPool* TPpContext::mem_CreatePool(size_t chunksize, unsigned int align)
{
MemoryPool *pool;
@ -108,32 +101,28 @@ TPpContext::MemoryPool* TPpContext::mem_CreatePool(size_t chunksize, unsigned in
align = ALIGN;
if (chunksize == 0)
chunksize = CHUNKSIZE;
if (align & (align-1))
if (align & (align - 1))
return 0;
if (chunksize < sizeof(MemoryPool))
return 0;
if (chunksize & (align-1))
if (chunksize & (align - 1))
return 0;
if (!(pool = (MemoryPool*)malloc(chunksize)))
return 0;
pool->next = 0;
pool->chunksize = chunksize;
pool->alignmask = (uintptr_t)(align)-1;
pool->alignmask = (uintptr_t)(align) - 1;
pool->free = ((uintptr_t)(pool + 1) + pool->alignmask) & ~pool->alignmask;
pool->end = (uintptr_t)pool + chunksize;
pool->cleanup = 0;
return pool;
}
void TPpContext::mem_FreePool(MemoryPool *pool)
{
struct cleanup *cleanup;
struct chunk *p, *next;
struct chunk *p, *next;
for (cleanup = pool->cleanup; cleanup; cleanup = cleanup->next) {
cleanup->fn(cleanup->arg1, cleanup->arg2);
}
for (p = (struct chunk *)pool; p; p = next) {
next = p->next;
free(p);
@ -168,19 +157,4 @@ void* TPpContext::mem_Alloc(MemoryPool *pool, size_t size)
return rv;
}
int TPpContext::mem_AddCleanup(MemoryPool *pool, void (*fn)(void *, void*), void* arg1, void* arg2)
{
struct cleanup *cleanup;
pool->free = (pool->free + sizeof(void *) - 1) & ~(sizeof(void *)-1);
cleanup = (struct cleanup *)(mem_Alloc(pool, sizeof(struct cleanup)));
if (!cleanup) return -1;
cleanup->next = pool->cleanup;
cleanup->fn = fn;
cleanup->arg1 = arg1;
cleanup->arg2 = arg2;
pool->cleanup = cleanup;
return 0;
}
} // end namespace glslang