--------------------- PatchSet 112 Date: 2002/11/01 12:11:43 Author: rbcollins Branch: esi Tag: (none) Log: finish type cleanups Members: src/ESI.cc:1.1.2.20->1.1.2.21 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.20 retrieving revision 1.1.2.21 diff -u -r1.1.2.20 -r1.1.2.21 --- squid3/src/ESI.cc 1 Nov 2002 09:49:10 -0000 1.1.2.20 +++ squid3/src/ESI.cc 1 Nov 2002 12:11:43 -0000 1.1.2.21 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.20 2002/11/01 09:49:10 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.21 2002/11/01 12:11:43 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -158,11 +158,6 @@ ESI_KICK_SENT } esiKick_t; -typedef esiProcessResult_t esiProcessSelf (void *, int); /* process this element */ -#define PROCESS(foo, bar) foo->process(bar) -struct esiElementType { - esiProcessSelf *process; -}; struct esiElement { virtual bool addElement(esiElement *) { /* Don't accept children */ @@ -176,8 +171,6 @@ return ESI_PROCESS_COMPLETE; } virtual void deleteSelf() = 0; - - esiElementType *Vptr; }; /* some core operators */ @@ -206,18 +199,6 @@ ESI_ELEMENT_OTHERWISE } esiElementType_t; -static esiElementType _esiSequence = {processThunk}; -static esiElementType _esiInclude = {processThunk}; -static esiElementType _esiRemove = {processThunk}; -static esiElementType _esiTry = {processThunk}; -/* esiAttempt, esiExcept, esiVar, esiWhen and esiOtherwise are 'Sequences' */ -static esiElementType _esiAttempt = {processThunk}; -static esiElementType _esiExcept = {processThunk}; -static esiElementType _esiVar = {processThunk}; -static esiElementType _esiChoose = {processThunk}; -static esiElementType _esiWhen = {processThunk}; -static esiElementType _esiOtherwise= {processThunk}; - /* esiComment */ struct esiComment : public esiElement { void *operator new (size_t byteCount); @@ -270,7 +251,6 @@ int processedcount; struct { int dovars:1; /* for esiVar */ - int testtrue:1; /* for esiWhen */ } flags; }; CBDATA_TYPE (esiSequence); @@ -318,11 +298,21 @@ static esiElement * esiRemoveNew(void); /* esiAttempt */ -typedef esiSequence esiAttempt; +struct esiAttempt : public esiSequence{ + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); +}; +CBDATA_TYPE(esiAttempt); static esiElement *esiAttemptNew(void); /* esiExcept */ -typedef esiSequence esiExcept; +struct esiExcept : public esiSequence{ + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); +}; +CBDATA_TYPE(esiExcept); static esiElement *esiExceptNew(void); /* esiTry */ @@ -349,7 +339,12 @@ static esiElement *esiTryNew(void); /* esiVar */ -typedef esiSequence esiVar; +struct esiVar:public esiSequence{ + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); +}; +CBDATA_TYPE(esiVar); static esiElement *esiVarNew(void); /* esiChoose */ @@ -374,11 +369,27 @@ static esiElement *esiChooseNew(void); /* esiWhen */ -typedef esiSequence esiWhen; +struct esiWhen : public esiSequence +{ + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); + + bool testsTrue() const { return testValue;} + void setTestResult(bool aBool) {testValue = aBool;} +private: + bool testValue; +}; +CBDATA_TYPE (esiWhen); static esiElement *esiWhenNew(int attributes, const char **attr, esiVarState *); /* esiOtherwise */ -typedef esiSequence esiOtherwise; +struct esiOtherwise : public esiSequence{ + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); +}; +CBDATA_TYPE(esiOtherwise); static esiElement *esiOtherwiseNew(void); /* esiContext */ @@ -1855,7 +1866,6 @@ esiSequence::esiSequence() { - Vptr = &_esiSequence; elements = NULL; } @@ -1888,8 +1898,8 @@ { /* add an element to the output list */ /* Some elements require specific parents */ - if (element->Vptr == &_esiAttempt || - element->Vptr == &_esiExcept) { + if (dynamic_cast(element) || + dynamic_cast(element)) { debug (86,0)("esiSequenceAdd: misparented Attempt or Except element (section 3.4)\n"); return false; } @@ -2019,7 +2029,6 @@ { int i; assert (aContext); - Vptr = &_esiInclude; for (i = 0; attr[i] && i < attrcount; i += 2) { if (!strcmp(attr[i],"src")) { @@ -2212,7 +2221,6 @@ esiRemove::esiRemove() { - Vptr = &_esiRemove; } void @@ -2274,7 +2282,6 @@ esiTry::esiTry() { - Vptr = &_esiTry; } void @@ -2304,7 +2311,7 @@ cbdataFree (element); return true; } - if (element->Vptr == &_esiAttempt) { + if (dynamic_cast(element)) { if (attempt) { debug (86,1)("esiTryAdd: Failed for %p - try allready has an attempt node (section 3.4)\n",this); return false; @@ -2312,7 +2319,7 @@ attempt = element; return true; } - if (element->Vptr == &_esiExcept) { + if (dynamic_cast(element)) { if (except) { debug (86,1)("esiTryAdd: Failed for %p - try already has an except node (section 3.4)\n",this); return false; @@ -2339,7 +2346,7 @@ } if (!flags.attemptfailed) /* Try the attempt branch */ - switch ((rv = PROCESS(attempt, dovars))){ + switch ((rv = attempt->process(dovars))){ case ESI_PROCESS_COMPLETE: debug (86,5)("esiTryProcess: attempt Processed OK\n"); flags.attemptok = 1; @@ -2389,29 +2396,90 @@ } /* esiAttempt */ +void * +esiAttempt::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiAttempt)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiAttempt, esiSequenceFree); + rv = (void *)cbdataAlloc (esiAttempt); + return rv; +} + +void +esiAttempt::operator delete (void *address) +{ + cbdataFree ((esiAttempt *)address); +} + +void +esiAttempt::deleteSelf() +{ + delete this; +} + esiElement * esiAttemptNew () { - esiElement *rv = esiSequenceNew(); - rv->Vptr = &_esiAttempt; - return rv; + return new esiAttempt; } /* esiExcept */ +void * +esiExcept::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiExcept)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiExcept, esiSequenceFree); + rv = (void *)cbdataAlloc (esiExcept); + return rv; +} + +void +esiExcept::operator delete (void *address) +{ + cbdataFree ((esiExcept *)address); +} + +void +esiExcept::deleteSelf() +{ + delete this; +} + esiElement * esiExceptNew () { - esiElement *rv = esiSequenceNew(); - rv->Vptr = &_esiExcept; - return rv; + return new esiExcept; } /* esiVar */ +void * +esiVar::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiVar)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiVar, esiSequenceFree); + rv = (void *)cbdataAlloc (esiVar); + return rv; +} + +void +esiVar::operator delete (void *address) +{ + cbdataFree ((esiVar *)address); +} + +void +esiVar::deleteSelf() +{ + delete this; +} + esiElement * esiVarNew () { - esiSequence *rv = (esiSequence *)esiSequenceNew(); - rv->Vptr = &_esiVar; + esiVar *rv = new esiVar; rv->flags.dovars = 1; return (esiElement *)rv; } @@ -3011,7 +3079,6 @@ esiChoose::esiChoose() { - Vptr = &_esiChoose; elements = NULL; chosenelement = -1; } @@ -3041,11 +3108,11 @@ } /* Some elements require specific parents */ - if (!(element->Vptr == &_esiWhen || element->Vptr == &_esiOtherwise)) { + if (!(dynamic_cast(element) || dynamic_cast(element))) { debug (86,0)("esiChooseAdd: invalid child node for esi:choose (section 3.3)\n"); return false; } - if (element->Vptr == &_esiOtherwise) { + if (dynamic_cast(element)) { if (otherwise) { debug (86,0)("esiChooseAdd: only one otherwise node allowed for esi:choose (section 3.3)\n"); return false; @@ -3060,7 +3127,7 @@ debug (86,3)("esiChooseAdd: Added a new element, elements = %d\n", elementcount); if (chosenelement == -1) - if (((esiWhen *)element)->flags.testtrue) { + if (((esiWhen *)element)->testsTrue()) { chosenelement = elementcount - 1; debug (86,3)("esiChooseAdd: Chose element %d\n", elementcount); } @@ -3086,13 +3153,34 @@ } /* esiWhen */ +void * +esiWhen::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiWhen)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiWhen, esiSequenceFree); + rv = (void *)cbdataAlloc (esiWhen); + return rv; +} + +void +esiWhen::operator delete (void *address) +{ + cbdataFree ((esiWhen *)address); +} + +void +esiWhen::deleteSelf() +{ + delete this; +} + esiElement * esiWhenNew (int attrcount, const char **attr,esiVarState *varState) { - esiSequence *rv = (esiSequence *)esiSequenceNew(); + esiWhen *rv = new esiWhen; char const *expression = NULL; int i; - rv->Vptr = &_esiWhen; for (i = 0; attr[i] && i < attrcount; i += 2) { if (!strcmp(attr[i],"test")) { @@ -3114,18 +3202,38 @@ esiVarStateFeedData(varState, expression, strlen (expression)); /* expression is not our buffer */ expression = esiVarStateExtractChar (varState); - rv->flags.testtrue = esiExpressionEval (expression); + rv->setTestResult(esiExpressionEval (expression)); safe_free (expression); return (esiElement *)rv; } /* esiOtherwise */ +void * +esiOtherwise::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiOtherwise)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiOtherwise, esiSequenceFree); + rv = (void *)cbdataAlloc (esiOtherwise); + return rv; +} + +void +esiOtherwise::operator delete (void *address) +{ + cbdataFree ((esiOtherwise *)address); +} + +void +esiOtherwise::deleteSelf() +{ + delete this; +} + esiElement * esiOtherwiseNew () { - esiSequence *rv = (esiSequence *)esiSequenceNew(); - rv->Vptr = &_esiOtherwise; - return (esiElement *)rv; + return new esiOtherwise; }