This commit is contained in:
Tim Taubert 2012-01-28 10:29:35 +01:00
Родитель a0f0cb5e8d 845dd96a48
Коммит df68f64aa8
3 изменённых файлов: 52 добавлений и 27 удалений

Просмотреть файл

@ -1208,7 +1208,7 @@ txFnStartTopVariable(PRInt32 aNamespaceID,
NS_ENSURE_TRUE(var, NS_ERROR_OUT_OF_MEMORY);
aState.openInstructionContainer(var);
rv = aState.pushPtr(var);
rv = aState.pushPtr(var, aState.eVariableItem);
NS_ENSURE_SUCCESS(rv, rv);
if (var->mValue) {
@ -1234,7 +1234,8 @@ txFnEndTopVariable(txStylesheetCompilerState& aState)
{
txHandlerTable* prev = aState.mHandlerTable;
aState.popHandlerTable();
txVariableItem* var = static_cast<txVariableItem*>(aState.popPtr());
txVariableItem* var =
static_cast<txVariableItem*>(aState.popPtr(aState.eVariableItem));
if (prev == gTxTopVariableHandler) {
// No children were found.
@ -1736,7 +1737,7 @@ txFnStartCopy(PRInt32 aNamespaceID,
nsAutoPtr<txCopy> copy(new txCopy);
NS_ENSURE_TRUE(copy, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = aState.pushPtr(copy);
nsresult rv = aState.pushPtr(copy, aState.eCopy);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoPtr<txInstruction> instr(copy.forget());
@ -1758,7 +1759,7 @@ txFnEndCopy(txStylesheetCompilerState& aState)
nsresult rv = aState.addInstruction(instr);
NS_ENSURE_SUCCESS(rv, rv);
txCopy* copy = static_cast<txCopy*>(aState.popPtr());
txCopy* copy = static_cast<txCopy*>(aState.popPtr(aState.eCopy));
rv = aState.addGotoTarget(&copy->mBailTarget);
NS_ENSURE_SUCCESS(rv, rv);
@ -1909,7 +1910,7 @@ txFnStartForEach(PRInt32 aNamespaceID,
nsAutoPtr<txPushNewContext> pushcontext(new txPushNewContext(select));
NS_ENSURE_TRUE(pushcontext, NS_ERROR_OUT_OF_MEMORY);
rv = aState.pushPtr(pushcontext);
rv = aState.pushPtr(pushcontext, aState.ePushNewContext);
NS_ENSURE_SUCCESS(rv, rv);
rv = aState.pushSorter(pushcontext);
@ -1922,7 +1923,7 @@ txFnStartForEach(PRInt32 aNamespaceID,
instr = new txPushNullTemplateRule;
NS_ENSURE_TRUE(instr, NS_ERROR_OUT_OF_MEMORY);
rv = aState.pushPtr(instr);
rv = aState.pushPtr(instr, aState.ePushNullTemplateRule);
NS_ENSURE_SUCCESS(rv, rv);
rv = aState.addInstruction(instr);
@ -1938,7 +1939,7 @@ txFnEndForEach(txStylesheetCompilerState& aState)
// This is a txPushNullTemplateRule
txInstruction* pnullrule =
static_cast<txInstruction*>(aState.popPtr());
static_cast<txInstruction*>(aState.popPtr(aState.ePushNullTemplateRule));
nsAutoPtr<txInstruction> instr(new txLoopNodeSet(pnullrule));
nsresult rv = aState.addInstruction(instr);
@ -1946,7 +1947,7 @@ txFnEndForEach(txStylesheetCompilerState& aState)
aState.popSorter();
txPushNewContext* pushcontext =
static_cast<txPushNewContext*>(aState.popPtr());
static_cast<txPushNewContext*>(aState.popPtr(aState.ePushNewContext));
aState.addGotoTarget(&pushcontext->mBailTarget);
return NS_OK;
@ -2001,7 +2002,7 @@ txFnStartIf(PRInt32 aNamespaceID,
nsAutoPtr<txConditionalGoto> condGoto(new txConditionalGoto(test, nsnull));
NS_ENSURE_TRUE(condGoto, NS_ERROR_OUT_OF_MEMORY);
rv = aState.pushPtr(condGoto);
rv = aState.pushPtr(condGoto, aState.eConditionalGoto);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoPtr<txInstruction> instr(condGoto.forget());
@ -2015,7 +2016,7 @@ static nsresult
txFnEndIf(txStylesheetCompilerState& aState)
{
txConditionalGoto* condGoto =
static_cast<txConditionalGoto*>(aState.popPtr());
static_cast<txConditionalGoto*>(aState.popPtr(aState.eConditionalGoto));
return aState.addGotoTarget(&condGoto->mTarget);
}
@ -2208,7 +2209,7 @@ txFnStartParam(PRInt32 aNamespaceID,
nsAutoPtr<txCheckParam> checkParam(new txCheckParam(name));
NS_ENSURE_SUCCESS(rv, rv);
rv = aState.pushPtr(checkParam);
rv = aState.pushPtr(checkParam, aState.eCheckParam);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoPtr<txInstruction> instr(checkParam.forget());
@ -2264,7 +2265,8 @@ txFnEndParam(txStylesheetCompilerState& aState)
rv = aState.addInstruction(instr);
NS_ENSURE_SUCCESS(rv, rv);
txCheckParam* checkParam = static_cast<txCheckParam*>(aState.popPtr());
txCheckParam* checkParam =
static_cast<txCheckParam*>(aState.popPtr(aState.eCheckParam));
aState.addGotoTarget(&checkParam->mBailTarget);
return NS_OK;
@ -2605,7 +2607,7 @@ txFnStartWhen(PRInt32 aNamespaceID,
nsAutoPtr<txConditionalGoto> condGoto(new txConditionalGoto(test, nsnull));
NS_ENSURE_TRUE(condGoto, NS_ERROR_OUT_OF_MEMORY);
rv = aState.pushPtr(condGoto);
rv = aState.pushPtr(condGoto, aState.eConditionalGoto);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoPtr<txInstruction> instr(condGoto.forget());
@ -2630,7 +2632,7 @@ txFnEndWhen(txStylesheetCompilerState& aState)
NS_ENSURE_SUCCESS(rv, rv);
txConditionalGoto* condGoto =
static_cast<txConditionalGoto*>(aState.popPtr());
static_cast<txConditionalGoto*>(aState.popPtr(aState.eConditionalGoto));
rv = aState.addGotoTarget(&condGoto->mTarget);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -342,7 +342,7 @@ txStylesheetCompiler::startElementInternal(PRInt32 aNamespaceID,
}
}
rv = pushPtr(const_cast<txElementHandler*>(handler));
rv = pushPtr(const_cast<txElementHandler*>(handler), eElementHandler);
NS_ENSURE_SUCCESS(rv, rv);
mElementContext->mDepth++;
@ -379,7 +379,7 @@ txStylesheetCompiler::endElement()
const txElementHandler* handler =
const_cast<const txElementHandler*>
(static_cast<txElementHandler*>(popPtr()));
(static_cast<txElementHandler*>(popPtr(eElementHandler)));
rv = (handler->mEndFunction)(*this);
NS_ENSURE_SUCCESS(rv, rv);
@ -636,7 +636,7 @@ txStylesheetCompilerState::~txStylesheetCompilerState()
nsresult
txStylesheetCompilerState::pushHandlerTable(txHandlerTable* aTable)
{
nsresult rv = pushPtr(mHandlerTable);
nsresult rv = pushPtr(mHandlerTable, eHandlerTable);
NS_ENSURE_SUCCESS(rv, rv);
mHandlerTable = aTable;
@ -647,13 +647,13 @@ txStylesheetCompilerState::pushHandlerTable(txHandlerTable* aTable)
void
txStylesheetCompilerState::popHandlerTable()
{
mHandlerTable = static_cast<txHandlerTable*>(popPtr());
mHandlerTable = static_cast<txHandlerTable*>(popPtr(eHandlerTable));
}
nsresult
txStylesheetCompilerState::pushSorter(txPushNewContext* aSorter)
{
nsresult rv = pushPtr(mSorter);
nsresult rv = pushPtr(mSorter, ePushNewContext);
NS_ENSURE_SUCCESS(rv, rv);
mSorter = aSorter;
@ -664,7 +664,7 @@ txStylesheetCompilerState::pushSorter(txPushNewContext* aSorter)
void
txStylesheetCompilerState::popSorter()
{
mSorter = static_cast<txPushNewContext*>(popPtr());
mSorter = static_cast<txPushNewContext*>(popPtr(ePushNewContext));
}
nsresult
@ -700,21 +700,31 @@ txStylesheetCompilerState::popObject()
}
nsresult
txStylesheetCompilerState::pushPtr(void* aPtr)
txStylesheetCompilerState::pushPtr(void* aPtr, enumStackType aType)
{
#ifdef TX_DEBUG_STACK
PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("pushPtr: %d\n", aPtr));
PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("pushPtr: 0x%x type %u\n", aPtr, aType));
#endif
mTypeStack.AppendElement(aType);
return mOtherStack.push(aPtr);
}
void*
txStylesheetCompilerState::popPtr()
txStylesheetCompilerState::popPtr(enumStackType aType)
{
PRUint32 stacklen = mTypeStack.Length();
NS_ABORT_IF_FALSE(stacklen > 0,
"Attempt to pop when type stack is empty\n");
enumStackType type = mTypeStack.ElementAt(stacklen - 1);
mTypeStack.RemoveElementAt(stacklen - 1);
void* value = mOtherStack.pop();
#ifdef TX_DEBUG_STACK
PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("popPtr: %d\n", value));
PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("popPtr: 0x%x type %u requested %u\n", value, type, aType));
#endif
NS_ABORT_IF_FALSE(type == aType,
"Expected type does not match top element type on stack");
return value;
}

Просмотреть файл

@ -116,6 +116,18 @@ public:
}
// Stack functions
enum enumStackType
{
eElementHandler,
eHandlerTable,
eVariableItem,
eCopy,
eInstruction,
ePushNewContext,
eConditionalGoto,
eCheckParam,
ePushNullTemplateRule
};
nsresult pushHandlerTable(txHandlerTable* aTable);
void popHandlerTable();
nsresult pushSorter(txPushNewContext* aSorter);
@ -124,9 +136,9 @@ public:
void popChooseGotoList();
nsresult pushObject(txObject* aObject);
txObject* popObject();
nsresult pushPtr(void* aPtr);
void* popPtr();
nsresult pushPtr(void* aPtr, enumStackType aType);
void* popPtr(enumStackType aType);
// stylesheet functions
nsresult addToplevelItem(txToplevelItem* aItem);
nsresult openInstructionContainer(txInstructionContainer* aContainer);
@ -185,6 +197,7 @@ protected:
bool mDoneWithThisStylesheet;
txStack mObjectStack;
txStack mOtherStack;
nsTArray<enumStackType> mTypeStack;
private:
txInstruction** mNextInstrPtr;