Debian Codegraph @

js/src/frontend/ParseNodeVerify.cpp

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "frontend/ParseNodeVerify.h"
8
9 #include "frontend/ParseNodeVisitor.h"
10
11 using namespace js;
12
13 #ifdef DEBUG
14
15 namespace js {
16 namespace frontend {
17
18 class ParseNodeVerifier : public ParseNodeVisitor<ParseNodeVerifier> {
19 using Base = ParseNodeVisitor<ParseNodeVerifier>;
20
21 const LifoAlloc& alloc_;
22
23 public:
24 ParseNodeVerifier(FrontendContext* fc, const LifoAlloc& alloc)
25 : Base(fc), alloc_(alloc) {}
26
27 [[nodiscard]] bool visit(ParseNode* pn) {
28 // pn->size() asserts that pn->pn_kind is valid, so we don't redundantly
29 // assert that here.
30 JS_PARSE_NODE_ASSERT(alloc_.contains(pn),
31 "start of parse node is in alloc");
32 JS_PARSE_NODE_ASSERT(alloc_.contains((unsigned char*)pn + pn->size()),
33 "end of parse node is in alloc");
34 if (pn->is<ListNode>()) {
35 pn->as<ListNode>().checkConsistency();
36 }
37 return Base::visit(pn);
38 }
39 };
40
41 } // namespace frontend
42 } // namespace js
43
44 bool frontend::CheckParseTree(FrontendContext* fc, const LifoAlloc& alloc,
45 ParseNode* pn) {
46 ParseNodeVerifier verifier(fc, alloc);
47 return verifier.visit(pn);
48 }
49
50 #endif // DEBUG