Replace C4AList with some std::lists

floating-point
Günther Brammer 2011-02-26 00:48:19 +01:00
parent 5c18c7aa33
commit 7ce65373a3
9 changed files with 18 additions and 222 deletions

View File

@ -488,8 +488,6 @@ set(OC_CLONK_SOURCES
src/platform/StdWindow.h
src/platform/StdAppCommon.h
src/platform/StdAppCommon.cpp
src/script/C4AList.cpp
src/script/C4AList.h
src/script/C4Aul.cpp
src/script/C4AulExec.h
src/script/C4AulExec.cpp

View File

@ -500,8 +500,6 @@ src/res/Play.h \
src/res/Rect.h \
src/res/resource.h \
src/res/Static.h \
src/script/C4AList.cpp \
src/script/C4AList.h \
src/script/C4Aul.cpp \
src/script/C4AulDebug.cpp \
src/script/C4AulDebug.h \

View File

@ -26,7 +26,6 @@
// class declarations
class C4Action;
class C4AList;
struct C4AulContext;
class C4AulDefFunc;
class C4AulFunc;

View File

@ -1,100 +0,0 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2001 Sven Eberhardt
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
*
* Portions might be copyrighted by other authors who have contributed
* to OpenClonk.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* See isc_license.txt for full license and disclaimer.
*
* "Clonk" is a registered trademark of Matthes Bender.
* See clonk_trademark_license.txt for full license.
*/
// an associative list
#include <C4Include.h>
#include <C4AList.h>
/* associative list */
C4AList::C4AList()
{
// init list with no chunks
// other values will be inited upon first Grow()
Table = NULL;
}
C4AList::~C4AList()
{
// clear list
Clear();
}
void C4AList::Clear()
{
// free chunks
C4AListChunk *c = Table;
while (c)
{
C4AListChunk *c2 = c->Next;
delete c;
c = c2;
}
// reset values
Table = NULL;
}
void C4AList::Grow()
{
// create table if not existant
if (!Table)
{
Table = CurrC = new C4AListChunk;
}
else
{
// otherwise, add new chunk to end of table
CurrC->Next = new C4AListChunk;
CurrC = CurrC->Next;
}
// init new chunk
ZeroMemory(CurrC, sizeof(C4AListChunk));
// reset current chunk pos
Curr = &CurrC->Entries[0];
CCount = 0;
}
C4AListEntry *C4AList::push(C4ID pVar, void *pVal)
{
// init/grow list if necessary
if (!Table || (CCount == C4AListChunkSize)) Grow();
// push to end of list
C4AListEntry *Entry = Curr;
Entry->Var = pVar; Entry->Val = pVal;
// select next entry
CCount++; Curr++;
// done, hand back entry
return Entry;
}
C4AListEntry *C4AListEntry::next()
{
// search entries; beginning at this
C4AListEntry *pOff = this + 1;
// entry is valid? fine
if (pOff->Var) return pOff;
// check if it's just the end of a chunk
if (!(pOff = (C4AListEntry *) pOff->Val))
// it's a stop entry or the end of the list; return failure
return NULL;
// return beginning of next chunk, if valid
if (pOff->Var) return pOff;
// otherwise, fail
return NULL;
}

View File

@ -1,60 +0,0 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2001 Sven Eberhardt
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
*
* Portions might be copyrighted by other authors who have contributed
* to OpenClonk.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* See isc_license.txt for full license and disclaimer.
*
* "Clonk" is a registered trademark of Matthes Bender.
* See clonk_trademark_license.txt for full license.
*/
// an associated list
// used by C4AulScriptEngine, as virtual function table and include/dependency list
#ifndef INC_C4AList
#define INC_C4AList
#include <C4Id.h>
#define C4AListChunkSize 128 // number of table entries for each chunk
// table entry
struct C4AListEntry
{
C4ID Var; void *Val;
C4AListEntry *next(); // get entry after the given one
};
// bunch of table entries
struct C4AListChunk
{
C4AListEntry Entries[C4AListChunkSize]; // table entries
void *Stop; // stop entry; should always be NULL
C4AListChunk *Next; // next chunk
};
// associative list
class C4AList
{
protected:
C4AListChunk *Table, *CurrC; // first/last table chunk
int CCount; // number of entries in current chunk
C4AListEntry *Curr; // next available entry to be used
void Grow(); // append chunk
public:
C4AList(); // constructor
~C4AList(); // destructor
void Clear(); // clear the list
C4AListEntry *push(C4ID Var = C4ID::None, void *pVal = NULL); // push var/value pair to end of list
};
#endif

View File

@ -188,8 +188,8 @@ void C4AulScript::Default()
Owner = Engine = NULL;
Func0 = FuncL = NULL;
// prepare include list
Includes = NULL;
Appends = NULL;
Includes.clear();
Appends.clear();
stringTable = 0;
}
@ -216,7 +216,8 @@ void C4AulScript::Unreg()
void C4AulScript::Clear()
{
// remove includes
Includes = NULL;
Includes.clear();
Appends.clear();
// delete child scripts + funcs
while (Child0) // Child0->Unreg();
if (Child0->Delete()) delete Child0; else Child0->Unreg();
@ -464,8 +465,6 @@ void C4AulScriptEngine::Clear()
// clear inherited
C4AulScript::Clear();
// clear own stuff
// clear tables
itbl.Clear(); atbl.Clear();
// reset values
warnCnt = errCnt = nonStrictCnt = lineCnt = 0;
// resetting name lists will reset all data lists, too

View File

@ -25,7 +25,6 @@
#ifndef INC_C4Aul
#define INC_C4Aul
#include <C4AList.h>
#include <C4ValueMap.h>
#include <C4Id.h>
#include <C4Script.h>
@ -488,8 +487,8 @@ protected:
bool Preparsing; // set while preparse
bool Resolving; // set while include-resolving, to catch circular includes
C4AListEntry *Includes; // include list
C4AListEntry *Appends; // append list
std::list<C4ID> Includes; // include list
std::list<C4ID> Appends; // append list
// internal function used to find overloaded functions
C4AulFunc *GetOverloadedFunc(C4AulFunc *ByFunc);
@ -521,10 +520,7 @@ protected:
// holds all C4AulScripts
class C4AulScriptEngine : public C4AulScript
{
protected:
C4AList itbl; // include table
C4AList atbl; // append table
C4AulFuncMap FuncLookUp;
#ifndef NOAULDEBUG
C4AulDebug *pDebug;

View File

@ -35,11 +35,11 @@ bool C4AulScript::ResolveAppends(C4DefList *rDefs)
for (C4AulScript *s = Child0; s; s = s->Next) s->ResolveAppends(rDefs);
// resolve local appends
if (State != ASS_PREPARSED) return false;
for (C4AListEntry *a = Appends; a; a = a->next())
for (std::list<C4ID>::iterator a = Appends.begin(); a != Appends.end(); ++a)
{
if (a->Var)
if (*a)
{
C4Def *Def = rDefs->ID2Def(a->Var);
C4Def *Def = rDefs->ID2Def(*a);
if (Def)
AppendTo(Def->Script, true);
else
@ -47,7 +47,7 @@ bool C4AulScript::ResolveAppends(C4DefList *rDefs)
// save id in buffer because AulWarn will use the buffer of C4IdText
// to get the id of the object in which the error occurs...
// (stupid static buffers...)
Warn("script to #appendto not found: ", a->Var.ToString());
Warn("script to #appendto not found: ", a->ToString());
}
}
else
@ -84,9 +84,9 @@ bool C4AulScript::ResolveIncludes(C4DefList *rDefs)
}
Resolving=true;
// append all includes to local script
for (C4AListEntry *i = Includes; i; i = i->next())
for (std::list<C4ID>::iterator i = Includes.begin(); i != Includes.end(); ++i)
{
C4Def *Def = rDefs->ID2Def(i->Var);
C4Def *Def = rDefs->ID2Def(*i);
if (Def)
{
// resolve #includes in included script first (#include-chains :( )
@ -101,7 +101,7 @@ bool C4AulScript::ResolveIncludes(C4DefList *rDefs)
// save id in buffer because AulWarn will use the buffer of C4IdText
// to get the id of the object in which the error occurs...
// (stupid static buffers...)
Warn("script to #include not found: ", i->Var.ToString());
Warn("script to #include not found: ", i->ToString());
}
}
IncludesResolved = true;

View File

@ -111,7 +111,6 @@ enum C4AulTokenType
ATT_BCLOSE2,// "]"
ATT_BLOPEN, // "{"
ATT_BLCLOSE,// "}"
ATT_SEP, // "|"
ATT_CALL, // "->"
ATT_CALLFS, // "->~"
ATT_STAR, // "*"
@ -233,7 +232,7 @@ void C4AulScript::Warn(const char *pMsg, const char *pIdtf)
void C4AulParseState::Warn(const char *pMsg, const char *pIdtf)
{
// do not show errors for System.c4g scripts that appear to be pure #appendto scripts
if (Fn && !Fn->Owner->Def && Fn->Owner->Appends) return;
if (Fn && !Fn->Owner->Def && !Fn->Owner->Appends.empty()) return;
// script doesn't own function -> skip
// (exception: global functions)
//if(pFunc) if(pFunc->pOrgScript != pScript && pScript != (C4AulScript *)&::ScriptEngine) return;
@ -929,10 +928,7 @@ bool C4AulScript::Preparse()
if (!Script) { State = ASS_PREPARSED; return true; }
// clear stuff
/* simply setting Includes to NULL will waste some space in the associative list
however, this is just a few bytes per updated definition in developer mode, which
seems acceptable for me. The mem will be released when destroying the list */
Includes = NULL; Appends=NULL;
Includes.clear(); Appends.clear();
// reset code
ClearCode();
while (Func0)
@ -1289,7 +1285,6 @@ const char * C4AulParseState::GetTokenName(C4AulTokenType TokenType)
case ATT_BCLOSE2: return "']'";
case ATT_BLOPEN: return "'{'";
case ATT_BLCLOSE: return "'}'";
case ATT_SEP: return "'|'";
case ATT_CALL: return "'->'";
case ATT_CALLFS: return "'->~'";
case ATT_STAR: return "'*'";
@ -1377,8 +1372,7 @@ void C4AulParseState::Parse_Script()
C4ID Id = C4ID(StdStrBuf(Idtf));
Shift();
// add to include list
C4AListEntry *e = a->Engine->itbl.push(Id);
if (!a->Includes) a->Includes = e;
a->Includes.push_front(Id);
IncludeCount++;
}
else if (SEqual(Idtf, C4AUL_Append))
@ -1402,8 +1396,7 @@ void C4AulParseState::Parse_Script()
UnexpectedToken("identifier or '*'");
}
// add to append list
C4AListEntry *e = a->Engine->atbl.push(Id);
if (!a->Appends) a->Appends = e;
a->Appends.push_back(Id);
}
else if (SEqual(Idtf, C4AUL_Strict))
{
@ -1480,33 +1473,6 @@ void C4AulParseState::Parse_Script()
all_ok = false;
delete err;
}
// includes were added?
if (a->Includes)
{
// reverse include order, for compatiblity with the C4Script syntax
if (IncludeCount > 1)
{
C4AListEntry *i = a->Includes;
while (IncludeCount > 1)
{
C4AListEntry *i2 = i;
for (int cnt = IncludeCount - 1; cnt; cnt--) i2 = i2->next();
C4AListEntry xchg = *i; *i = *i2; *i2 = xchg;
i = i->next(); IncludeCount -= 2;
}
}
// push stop entry for include list
a->Engine->itbl.push();
}
// appends were added?
if (a->Appends)
{
// push stop entry for append list
a->Engine->atbl.push();
}
}
void C4AulParseState::Parse_FuncHead()
@ -3106,7 +3072,7 @@ bool C4AulScript::Parse()
catch (C4AulError *err)
{
// do not show errors for System.c4g scripts that appear to be pure #appendto scripts
if (Fn->Owner->Def || !Fn->Owner->Appends)
if (Fn->Owner->Def || Fn->Owner->Appends.empty())
{
// show
err->show();