YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/parser/parser.cc
Line
Count
Source
1
//--------------------------------------------------------------------------------------------------
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//--------------------------------------------------------------------------------------------------
15
#include "yb/yql/cql/ql/parser/parser.h"
16
17
namespace yb {
18
namespace ql {
19
20
using std::endl;
21
using std::shared_ptr;
22
using std::string;
23
using std::to_string;
24
25
//--------------------------------------------------------------------------------------------------
26
// Class Parser.
27
//--------------------------------------------------------------------------------------------------
28
Parser::Parser()
29
    : lex_processor_(),
30
17.1k
      gram_processor_(this) {
31
17.1k
}
32
33
1
Parser::~Parser() {
34
1
}
35
36
//--------------------------------------------------------------------------------------------------
37
38
Status Parser::Parse(const string& stmt, const bool reparsed, const MemTrackerPtr& mem_tracker,
39
336k
                     const bool internal) {
40
336k
  parse_context_ = ParseContext::UniPtr(new ParseContext(stmt, reparsed, mem_tracker, internal));
41
336k
  lex_processor_.ScanInit(parse_context());
42
336k
  gram_processor_.set_debug_level(parse_context_->trace_parsing());
43
44
336k
  if (gram_processor_.parse() == 0 &&
45
335k
      parse_context_->error_code() == ErrorCode::SUCCESS) {
46
18.4E
    VLOG(3) << "Successfully parsed statement \"" << parse_context_->stmt()
47
18.4E
            << "\". Result = <" << parse_context_->parse_tree() << ">" << endl;
48
1.70k
  } else {
49
1.60k
    VLOG(3) << kErrorFontStart << "Failed to parse \"" << parse_context_->stmt() << "\""
50
1.60k
            << kErrorFontEnd << endl;
51
1.70k
  }
52
53
336k
  return parse_context_->GetStatus();
54
336k
}
55
56
//--------------------------------------------------------------------------------------------------
57
58
334k
ParseTree::UniPtr Parser::Done() {
59
  // When releasing the parse tree, we must free the context because it has references to the tree
60
  // which doesn't belong to this context any longer.
61
334k
  ParseTree::UniPtr ptree = parse_context_->AcquireParseTree();
62
334k
  parse_context_ = nullptr;
63
334k
  return ptree;
64
334k
}
65
66
//--------------------------------------------------------------------------------------------------
67
68
4.35M
GramProcessor::symbol_type Parser::Scan() {
69
4.35M
  return lex_processor_.Scan();
70
4.35M
}
71
72
}  // namespace ql
73
}  // namespace yb