YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/parser/parse_context.cc
Line
Count
Source (jump to first uncovered line)
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/parse_context.h"
16
17
#include <stdio.h>
18
19
#include "yb/yql/cql/ql/ptree/parse_tree.h"
20
#include "yb/yql/cql/ql/ptree/pt_expr.h"
21
22
namespace yb {
23
namespace ql {
24
25
using std::endl;
26
using std::istream;
27
using std::min;
28
using std::shared_ptr;
29
using std::string;
30
31
//--------------------------------------------------------------------------------------------------
32
// ParseContext
33
//--------------------------------------------------------------------------------------------------
34
35
ParseContext::ParseContext(const string& stmt,
36
                           const bool reparsed,
37
                           const MemTrackerPtr& mem_tracker,
38
                           const bool internal)
39
    : ProcessContext(std::make_unique<ParseTree>(stmt, reparsed, mem_tracker, internal)),
40
      bind_variables_(PTreeMem()),
41
      stmt_offset_(0),
42
      trace_scanning_(false),
43
342k
      trace_parsing_(false) {
44
45
  // The MAC version of FLEX requires empty or valid input stream. It does not allow input file to
46
  // be nullptr.
47
342k
  ql_file_ = std::make_unique<istream>(nullptr);
48
49
342k
  if (VLOG_IS_ON(3)) {
50
0
    trace_scanning_ = true;
51
0
    trace_parsing_ = true;
52
0
  }
53
342k
}
54
55
341k
ParseContext::~ParseContext() {
56
341k
}
57
58
//--------------------------------------------------------------------------------------------------
59
60
679k
size_t ParseContext::Read(char* buf, size_t max_size) {
61
679k
  const size_t copy_size = min<size_t>(stmt().length() - stmt_offset_, max_size);
62
679k
  if (copy_size > 0) {
63
337k
    stmt().copy(buf, copy_size, stmt_offset_);
64
337k
    stmt_offset_ += copy_size;
65
337k
    return copy_size;
66
337k
  }
67
342k
  return 0;
68
679k
}
69
70
320k
void ParseContext::GetBindVariables(MCVector<PTBindVar*> *vars) {
71
320k
  vars->clear();
72
335k
  for (auto it = bind_variables_.cbegin(); it != bind_variables_.cend(); 
it++15.4k
) {
73
15.4k
    PTBindVar *var = *it;
74
    // Set the ordinal position of the bind variable in the statement also.
75
15.4k
    if (var->is_unset_pos()) {
76
15.4k
      var->set_pos(bind_pos_);
77
15.4k
    }
78
15.4k
    vars->push_back(var);
79
15.4k
    bind_pos_++;
80
15.4k
  }
81
  // Once the current statement has copied the bind variables found in it, clear the bind vars
82
  // before we process the next statement.
83
320k
  bind_variables_.clear();
84
320k
}
85
86
0
void ParseContext::Warn(const location& loc, const char *msg, ErrorCode error_code) {
87
0
  ProcessContext::Warn(Location(loc), msg, error_code);
88
0
}
89
90
// Handling parsing error.
91
CHECKED_STATUS ParseContext::Error(const location& loc,
92
                                   const char *msg,
93
                                   ErrorCode error_code,
94
1
                                   const char* token) {
95
1
  return ProcessContext::Error(Location(loc), msg, error_code, token);
96
1
}
97
98
86
CHECKED_STATUS ParseContext::Error(const location& loc, const char *msg, const char* token) {
99
86
  return ProcessContext::Error(Location(loc), msg, token);
100
86
}
101
102
12
CHECKED_STATUS ParseContext::Error(const location& loc, ErrorCode error_code, const char* token) {
103
12
  return ProcessContext::Error(Location(loc), error_code, token);
104
12
}
105
106
34.2k
bool ParseContext::SetCmp::operator()(const PTBindVar* v1, const PTBindVar* v2) const {
107
34.2k
  const YBLocation& l1 = v1->loc();
108
34.2k
  const YBLocation& l2 = v2->loc();
109
34.2k
  return (l1.BeginLine() < l2.BeginLine() ||
110
34.2k
          
(34.2k
l1.BeginLine() == l2.BeginLine()34.2k
&&
l1.BeginColumn() < l2.BeginColumn()34.2k
));
111
34.2k
}
112
113
}  // namespace ql
114
}  // namespace yb