Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: xfa/fxfa/parser/xfa_script_nodehelper.cpp

Issue 2031873003: Get rid of NULLs in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@nullptr_fpdfsdk
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" 7 #include "xfa/fxfa/parser/xfa_script_nodehelper.h"
8 8
9 #include "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 #include "xfa/fxfa/parser/xfa_doclayout.h" 10 #include "xfa/fxfa/parser/xfa_doclayout.h"
11 #include "xfa/fxfa/parser/xfa_document.h" 11 #include "xfa/fxfa/parser/xfa_document.h"
12 #include "xfa/fxfa/parser/xfa_localemgr.h" 12 #include "xfa/fxfa/parser/xfa_localemgr.h"
13 #include "xfa/fxfa/parser/xfa_object.h" 13 #include "xfa/fxfa/parser/xfa_object.h"
14 #include "xfa/fxfa/parser/xfa_parser.h" 14 #include "xfa/fxfa/parser/xfa_parser.h"
15 #include "xfa/fxfa/parser/xfa_script.h" 15 #include "xfa/fxfa/parser/xfa_script.h"
16 #include "xfa/fxfa/parser/xfa_script_imp.h" 16 #include "xfa/fxfa/parser/xfa_script_imp.h"
17 #include "xfa/fxfa/parser/xfa_utils.h" 17 #include "xfa/fxfa/parser/xfa_utils.h"
18 18
19 CXFA_NodeHelper::CXFA_NodeHelper(void) 19 CXFA_NodeHelper::CXFA_NodeHelper(void)
20 : m_eLastCreateType(XFA_ELEMENT_DataValue), 20 : m_eLastCreateType(XFA_ELEMENT_DataValue),
21 m_pCreateParent(NULL), 21 m_pCreateParent(nullptr),
22 m_iCreateCount(0), 22 m_iCreateCount(0),
23 m_iCreateFlag(XFA_RESOLVENODE_RSTYPE_CreateNodeOne), 23 m_iCreateFlag(XFA_RESOLVENODE_RSTYPE_CreateNodeOne),
24 m_iCurAllStart(-1), 24 m_iCurAllStart(-1),
25 m_pAllStartParent(NULL) {} 25 m_pAllStartParent(nullptr) {}
26 CXFA_NodeHelper::~CXFA_NodeHelper(void) {} 26 CXFA_NodeHelper::~CXFA_NodeHelper(void) {}
27 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild( 27 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild(
28 CXFA_Node* parent, 28 CXFA_Node* parent,
29 const FX_WCHAR* pwsName, 29 const FX_WCHAR* pwsName,
30 FX_BOOL bIsClassName) { 30 FX_BOOL bIsClassName) {
31 if (parent == NULL) { 31 if (!parent)
32 return NULL; 32 return nullptr;
33 } 33
34 CXFA_NodeArray siblings; 34 CXFA_NodeArray siblings;
35 uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); 35 uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false);
36 XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); 36 XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName);
37 if (siblings.GetSize() == 0) { 37 if (siblings.GetSize() == 0) {
38 return NULL; 38 return nullptr;
39 } 39 }
40 return siblings[0]; 40 return siblings[0];
41 } 41 }
42 int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, 42 int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode,
43 XFA_LOGIC_TYPE eLogicType, 43 XFA_LOGIC_TYPE eLogicType,
44 CXFA_NodeArray* pSiblings, 44 CXFA_NodeArray* pSiblings,
45 FX_BOOL bIsClassName) { 45 FX_BOOL bIsClassName) {
46 if (!pNode) 46 if (!pNode)
47 return 0; 47 return 0;
48 CXFA_Node* parent = 48 CXFA_Node* parent =
49 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); 49 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent);
50 if (!parent) 50 if (!parent)
51 return 0; 51 return 0;
52 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( 52 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
53 parent->GetClassID(), pNode->GetClassID(), XFA_XDPPACKET_UNKNOWN); 53 parent->GetClassID(), pNode->GetClassID(), XFA_XDPPACKET_UNKNOWN);
54 if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { 54 if (!pProperty && eLogicType == XFA_LOGIC_Transparent) {
55 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); 55 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent);
56 if (parent == NULL) { 56 if (!parent)
57 return 0; 57 return 0;
58 }
59 } 58 }
60 if (bIsClassName) { 59 if (bIsClassName) {
61 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), 60 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(),
62 pSiblings, eLogicType, bIsClassName); 61 pSiblings, eLogicType, bIsClassName);
63 } else { 62 } else {
64 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, 63 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings,
65 eLogicType, bIsClassName); 64 eLogicType, bIsClassName);
66 } 65 }
67 } 66 }
68 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseAnySiblings( 67 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseAnySiblings(
69 CXFA_Node* parent, 68 CXFA_Node* parent,
70 uint32_t dNameHash, 69 uint32_t dNameHash,
71 CXFA_NodeArray* pSiblings, 70 CXFA_NodeArray* pSiblings,
72 FX_BOOL bIsClassName) { 71 FX_BOOL bIsClassName) {
73 if (parent == NULL || pSiblings == NULL) { 72 if (!parent || !pSiblings)
74 return 0; 73 return 0;
75 } 74
76 int32_t nCount = 0; 75 int32_t nCount = 0;
77 int32_t i = 0; 76 int32_t i = 0;
78 CXFA_NodeArray properties; 77 CXFA_NodeArray properties;
79 parent->GetNodeList(properties, XFA_NODEFILTER_Properties); 78 parent->GetNodeList(properties, XFA_NODEFILTER_Properties);
80 int32_t nProperties = properties.GetSize(); 79 int32_t nProperties = properties.GetSize();
81 for (i = 0; i < nProperties; ++i) { 80 for (i = 0; i < nProperties; ++i) {
82 CXFA_Node* child = properties[i]; 81 CXFA_Node* child = properties[i];
83 if (bIsClassName) { 82 if (bIsClassName) {
84 if (child->GetClassHashCode() == dNameHash) { 83 if (child->GetClassHashCode() == dNameHash) {
85 pSiblings->Add(child); 84 pSiblings->Add(child);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 bIsClassName); 123 bIsClassName);
125 } 124 }
126 return nCount; 125 return nCount;
127 } 126 }
128 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseSiblings(CXFA_Node* parent, 127 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseSiblings(CXFA_Node* parent,
129 uint32_t dNameHash, 128 uint32_t dNameHash,
130 CXFA_NodeArray* pSiblings, 129 CXFA_NodeArray* pSiblings,
131 XFA_LOGIC_TYPE eLogicType, 130 XFA_LOGIC_TYPE eLogicType,
132 FX_BOOL bIsClassName, 131 FX_BOOL bIsClassName,
133 FX_BOOL bIsFindProperty) { 132 FX_BOOL bIsFindProperty) {
134 if (parent == NULL || pSiblings == NULL) { 133 if (!parent || !pSiblings)
135 return 0; 134 return 0;
136 } 135
137 int32_t nCount = 0; 136 int32_t nCount = 0;
138 int32_t i = 0; 137 int32_t i = 0;
139 if (bIsFindProperty) { 138 if (bIsFindProperty) {
140 CXFA_NodeArray properties; 139 CXFA_NodeArray properties;
141 parent->GetNodeList(properties, XFA_NODEFILTER_Properties); 140 parent->GetNodeList(properties, XFA_NODEFILTER_Properties);
142 int32_t nProperties = properties.GetSize(); 141 int32_t nProperties = properties.GetSize();
143 for (i = 0; i < nProperties; ++i) { 142 for (i = 0; i < nProperties; ++i) {
144 CXFA_Node* child = properties[i]; 143 CXFA_Node* child = properties[i];
145 if (bIsClassName) { 144 if (bIsClassName) {
146 if (child->GetClassHashCode() == dNameHash) { 145 if (child->GetClassHashCode() == dNameHash) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, 196 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings,
198 eLogicType, bIsClassName, FALSE); 197 eLogicType, bIsClassName, FALSE);
199 } 198 }
200 } 199 }
201 return nCount; 200 return nCount;
202 } 201 }
203 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( 202 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent(
204 CXFA_Node* pNode, 203 CXFA_Node* pNode,
205 XFA_LOGIC_TYPE eLogicType) { 204 XFA_LOGIC_TYPE eLogicType) {
206 if (!pNode) { 205 if (!pNode) {
207 return NULL; 206 return nullptr;
208 } 207 }
209 if (eLogicType == XFA_LOGIC_NoTransparent) { 208 if (eLogicType == XFA_LOGIC_NoTransparent) {
210 return pNode->GetNodeItem(XFA_NODEITEM_Parent); 209 return pNode->GetNodeItem(XFA_NODEITEM_Parent);
211 } 210 }
212 CXFA_Node* parent; 211 CXFA_Node* parent;
213 CXFA_Node* node = pNode; 212 CXFA_Node* node = pNode;
214 while (TRUE) { 213 while (TRUE) {
215 parent = XFA_ResolveNodes_GetParent(node); 214 parent = XFA_ResolveNodes_GetParent(node);
216 if (parent == NULL) { 215 if (!parent)
217 break; 216 break;
218 } 217
219 XFA_ELEMENT parentElement = parent->GetClassID(); 218 XFA_ELEMENT parentElement = parent->GetClassID();
220 if ((!parent->IsUnnamed() && parentElement != XFA_ELEMENT_SubformSet) || 219 if ((!parent->IsUnnamed() && parentElement != XFA_ELEMENT_SubformSet) ||
221 parentElement == XFA_ELEMENT_Variables) { 220 parentElement == XFA_ELEMENT_Variables) {
222 break; 221 break;
223 } 222 }
224 node = parent; 223 node = parent;
225 } 224 }
226 return parent; 225 return parent;
227 } 226 }
228 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, 227 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode,
229 XFA_LOGIC_TYPE eLogicType, 228 XFA_LOGIC_TYPE eLogicType,
230 FX_BOOL bIsProperty, 229 FX_BOOL bIsProperty,
231 FX_BOOL bIsClassIndex) { 230 FX_BOOL bIsClassIndex) {
232 CXFA_Node* parent = 231 CXFA_Node* parent =
233 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); 232 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent);
234 if (parent == NULL) { 233 if (!parent)
235 return 0; 234 return 0;
236 } 235
237 if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { 236 if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) {
238 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); 237 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent);
239 if (parent == NULL) { 238 if (!parent)
240 return 0; 239 return 0;
241 }
242 } 240 }
243 uint32_t dwHashName = pNode->GetNameHash(); 241 uint32_t dwHashName = pNode->GetNameHash();
244 if (bIsClassIndex) { 242 if (bIsClassIndex) {
245 dwHashName = pNode->GetClassHashCode(); 243 dwHashName = pNode->GetClassHashCode();
246 } 244 }
247 CXFA_NodeArray siblings; 245 CXFA_NodeArray siblings;
248 int32_t iSize = XFA_NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, 246 int32_t iSize = XFA_NodeAcc_TraverseSiblings(parent, dwHashName, &siblings,
249 eLogicType, bIsClassIndex); 247 eLogicType, bIsClassIndex);
250 for (int32_t i = 0; i < iSize; ++i) { 248 for (int32_t i = 0; i < iSize; ++i) {
251 CXFA_Node* child = siblings[i]; 249 CXFA_Node* child = siblings[i];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); 284 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE));
287 return; 285 return;
288 } 286 }
289 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); 287 ws = refNode->GetCData(XFA_ATTRIBUTE_Name);
290 ws.Replace(L".", L"\\."); 288 ws.Replace(L".", L"\\.");
291 wsName.Format(L"%s[%d]", ws.c_str(), 289 wsName.Format(L"%s[%d]", ws.c_str(),
292 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); 290 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE));
293 } 291 }
294 292
295 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { 293 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) {
296 if (refNode == NULL) { 294 if (!refNode)
297 return FALSE; 295 return FALSE;
298 } 296
299 XFA_ELEMENT eRefNode = refNode->GetClassID(); 297 XFA_ELEMENT eRefNode = refNode->GetClassID();
300 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || 298 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) ||
301 eRefNode == XFA_ELEMENT_SubformSet || eRefNode == XFA_ELEMENT_Area || 299 eRefNode == XFA_ELEMENT_SubformSet || eRefNode == XFA_ELEMENT_Area ||
302 eRefNode == XFA_ELEMENT_Proto) { 300 eRefNode == XFA_ELEMENT_Proto) {
303 return TRUE; 301 return TRUE;
304 } 302 }
305 return FALSE; 303 return FALSE;
306 } 304 }
307 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( 305 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition(
308 CFX_WideString& wsCondition) { 306 CFX_WideString& wsCondition) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 m_iCreateCount = iIndex; 338 m_iCreateCount = iIndex;
341 return TRUE; 339 return TRUE;
342 } 340 }
343 return FALSE; 341 return FALSE;
344 } 342 }
345 FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode( 343 FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode(
346 CFX_WideString wsName, 344 CFX_WideString wsName,
347 CFX_WideString wsCondition, 345 CFX_WideString wsCondition,
348 FX_BOOL bLastNode, 346 FX_BOOL bLastNode,
349 CXFA_ScriptContext* pScriptContext) { 347 CXFA_ScriptContext* pScriptContext) {
350 if (m_pCreateParent == NULL) { 348 if (!m_pCreateParent)
351 return FALSE; 349 return FALSE;
352 } 350
353 FX_BOOL bIsClassName = FALSE; 351 FX_BOOL bIsClassName = FALSE;
354 FX_BOOL bResult = FALSE; 352 FX_BOOL bResult = FALSE;
355 if (wsName.GetAt(0) == '!') { 353 if (wsName.GetAt(0) == '!') {
356 wsName = wsName.Right(wsName.GetLength() - 1); 354 wsName = wsName.Right(wsName.GetLength() - 1);
357 m_pCreateParent = ToNode( 355 m_pCreateParent = ToNode(
358 pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); 356 pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets));
359 } 357 }
360 if (wsName.GetAt(0) == '#') { 358 if (wsName.GetAt(0) == '#') {
361 bIsClassName = TRUE; 359 bIsClassName = TRUE;
362 wsName = wsName.Right(wsName.GetLength() - 1); 360 wsName = wsName.Right(wsName.GetLength() - 1);
363 } 361 }
364 if (m_iCreateCount == 0) { 362 if (m_iCreateCount == 0) {
365 XFA_CreateNode_ForCondition(wsCondition); 363 XFA_CreateNode_ForCondition(wsCondition);
366 } 364 }
367 if (bIsClassName) { 365 if (bIsClassName) {
368 const XFA_ELEMENTINFO* lpElement = XFA_GetElementByName(wsName.AsStringC()); 366 const XFA_ELEMENTINFO* lpElement = XFA_GetElementByName(wsName.AsStringC());
369 if (lpElement == NULL) { 367 if (!lpElement)
370 return FALSE; 368 return FALSE;
371 } 369
372 for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { 370 for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) {
373 CXFA_Node* pNewNode = 371 CXFA_Node* pNewNode =
374 m_pCreateParent->CreateSamePacketNode(lpElement->eName); 372 m_pCreateParent->CreateSamePacketNode(lpElement->eName);
375 if (pNewNode) { 373 if (pNewNode) {
376 m_pCreateParent->InsertChild(pNewNode); 374 m_pCreateParent->InsertChild(pNewNode);
377 if (iIndex == m_iCreateCount - 1) { 375 if (iIndex == m_iCreateCount - 1) {
378 m_pCreateParent = pNewNode; 376 m_pCreateParent = pNewNode;
379 } 377 }
380 bResult = TRUE; 378 bResult = TRUE;
381 } 379 }
(...skipping 10 matching lines...) Expand all
392 pNewNode->CreateXMLMappingNode(); 390 pNewNode->CreateXMLMappingNode();
393 m_pCreateParent->InsertChild(pNewNode); 391 m_pCreateParent->InsertChild(pNewNode);
394 if (iIndex == m_iCreateCount - 1) { 392 if (iIndex == m_iCreateCount - 1) {
395 m_pCreateParent = pNewNode; 393 m_pCreateParent = pNewNode;
396 } 394 }
397 bResult = TRUE; 395 bResult = TRUE;
398 } 396 }
399 } 397 }
400 } 398 }
401 if (!bResult) { 399 if (!bResult) {
402 m_pCreateParent = NULL; 400 m_pCreateParent = nullptr;
403 } 401 }
404 return bResult; 402 return bResult;
405 } 403 }
406 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { 404 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) {
407 if (refNode == NULL) { 405 if (!refNode)
408 return; 406 return;
409 } 407
410 if (refNode->GetClassID() == XFA_ELEMENT_Subform) { 408 if (refNode->GetClassID() == XFA_ELEMENT_Subform) {
411 m_eLastCreateType = XFA_ELEMENT_DataGroup; 409 m_eLastCreateType = XFA_ELEMENT_DataGroup;
412 } else if (refNode->GetClassID() == XFA_ELEMENT_Field) { 410 } else if (refNode->GetClassID() == XFA_ELEMENT_Field) {
413 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) 411 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode)
414 ? XFA_ELEMENT_DataGroup 412 ? XFA_ELEMENT_DataGroup
415 : XFA_ELEMENT_DataValue; 413 : XFA_ELEMENT_DataValue;
416 } else if (refNode->GetClassID() == XFA_ELEMENT_ExclGroup) { 414 } else if (refNode->GetClassID() == XFA_ELEMENT_ExclGroup) {
417 m_eLastCreateType = XFA_ELEMENT_DataValue; 415 m_eLastCreateType = XFA_ELEMENT_DataValue;
418 } 416 }
419 } 417 }
420 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { 418 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) {
421 CXFA_Node* parent = 419 CXFA_Node* parent =
422 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); 420 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent);
423 return parent && refNode && 421 return parent && refNode &&
424 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(), 422 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(),
425 XFA_XDPPACKET_UNKNOWN); 423 XFA_XDPPACKET_UNKNOWN);
426 } 424 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp ('k') | xfa/fxfa/parser/xfa_script_resolveprocessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698