ICCItem *fnLogical (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData) // fnLogical // // Logical operators // // (and exp1 exp2 ... expn) // (or exp1 exp2 ... expn) { CCodeChain *pCC = pCtx->pCC; int i; // Loop over all arguments for (i = 0; i < pArguments->GetCount(); i++) { ICCItem *pResult; ICCItem *pArg = pArguments->GetElement(i); // Evaluate the item if (pArg->IsQuoted()) pResult = pArg->Reference(); else { pResult = pCC->Eval(pCtx, pArg); if (pResult->IsError()) return pResult; } // If we are evaluating NOT then reverse the value if (dwData == FN_LOGICAL_NOT) { if (pResult->IsNil()) { pResult->Discard(pCC); return pCC->CreateTrue(); } else { pResult->Discard(pCC); return pCC->CreateNil(); } } // If we are evaluating AND and we've got Nil, then // we can guarantee that the expression is Nil else if (dwData == FN_LOGICAL_AND && pResult->IsNil()) return pResult; // Otherwise, if we're evaluating OR and we've got non-Nil, // then we can guarantee that the expression is True else if (dwData == FN_LOGICAL_OR && !pResult->IsNil()) { pResult->Discard(pCC); return pCC->CreateTrue(); } // Otherwise, we continue pResult->Discard(pCC); } // If we get here then all the operands are the same (either all // True or all Nil depending) if (dwData == FN_LOGICAL_AND) return pCC->CreateTrue(); else return pCC->CreateNil(); }
ALERROR CLanguageDataBlock::InitFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // InitFromXML // // Initializes from an XML block { int i; for (i = 0; i < pDesc->GetContentElementCount(); i++) { CXMLElement *pItem = pDesc->GetContentElement(i); CString sID = pItem->GetAttribute(ID_ATTRIB); if (sID.IsBlank()) { Ctx.sError = strPatternSubst(CONSTLIT("Invalid id in <Language> block")); return ERR_FAIL; } if (strEquals(pItem->GetTag(), TEXT_TAG)) { // Link the code CCodeChainCtx CCCtx; ICCItem *pCode = CCCtx.Link(pItem->GetContentText(0), 0, NULL); if (pCode->IsError()) { Ctx.sError = strPatternSubst(CONSTLIT("Language id: %s : %s"), sID, pCode->GetStringValue()); return ERR_FAIL; } // Add an entry bool bIsNew; SEntry *pEntry = m_Data.SetAt(sID, &bIsNew); if (!bIsNew) { Ctx.sError = strPatternSubst(CONSTLIT("Duplicate <Language> element: %s"), sID); return ERR_FAIL; } // If pCode is a string and not an identifier, then we can just // store it directly. if (pCode->IsIdentifier() && pCode->IsQuoted()) { pEntry->pCode = NULL; pEntry->sText = pCode->GetStringValue(); } // Otherwise we store the code else pEntry->pCode = pCode->Reference(); // Done CCCtx.Discard(pCode); } else if (strEquals(pItem->GetTag(), MESSAGE_TAG)) { // Add an entry bool bIsNew; SEntry *pEntry = m_Data.SetAt(sID, &bIsNew); if (!bIsNew) { Ctx.sError = strPatternSubst(CONSTLIT("Duplicate <Language> element: %s"), sID); return ERR_FAIL; } // Set the text pEntry->pCode = NULL; pEntry->sText = pItem->GetAttribute(TEXT_ATTRIB); } else { Ctx.sError = strPatternSubst(CONSTLIT("Invalid element in <Language> block: <%s>"), pItem->GetTag()); return ERR_FAIL; } } return NOERROR; }