Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/clang/lib/Basic/OperatorPrecedence.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- OperatorPrecedence.cpp ---------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
///
9
/// \file
10
/// Defines and computes precedence levels for binary/ternary operators.
11
///
12
//===----------------------------------------------------------------------===//
13
#include "clang/Basic/OperatorPrecedence.h"
14
15
namespace clang {
16
17
prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
18
114M
                               bool CPlusPlus11) {
19
114M
  switch (Kind) {
20
5.08M
  case tok::greater:
21
    // C++ [temp.names]p3:
22
    //   [...] When parsing a template-argument-list, the first
23
    //   non-nested > is taken as the ending delimiter rather than a
24
    //   greater-than operator. [...]
25
5.08M
    if (GreaterThanIsOperator)
26
5.08M
      return prec::Relational;
27
10
    return prec::Unknown;
28
29
47
  case tok::greatergreater:
30
    // C++11 [temp.names]p3:
31
    //
32
    //   [...] Similarly, the first non-nested >> is treated as two
33
    //   consecutive but distinct > tokens, the first of which is
34
    //   taken as the end of the template-argument-list and completes
35
    //   the template-id. [...]
36
47
    if (GreaterThanIsOperator || !CPlusPlus11)
37
47
      return prec::Shift;
38
0
    return prec::Unknown;
39
40
82.7M
  default:                        return prec::Unknown;
41
5.15M
  case tok::comma:                return prec::Comma;
42
1.76M
  case tok::equal:
43
1.78M
  case tok::starequal:
44
1.78M
  case tok::slashequal:
45
1.79M
  case tok::percentequal:
46
1.81M
  case tok::plusequal:
47
1.82M
  case tok::minusequal:
48
1.97M
  case tok::lesslessequal:
49
1.97M
  case tok::greatergreaterequal:
50
1.97M
  case tok::ampequal:
51
1.97M
  case tok::caretequal:
52
1.98M
  case tok::pipeequal:            return prec::Assignment;
53
328k
  case tok::question:             return prec::Conditional;
54
106k
  case tok::pipepipe:             return prec::LogicalOr;
55
0
  case tok::caretcaret:
56
45.9k
  case tok::ampamp:               return prec::LogicalAnd;
57
803k
  case tok::pipe:                 return prec::InclusiveOr;
58
121k
  case tok::caret:                return prec::ExclusiveOr;
59
429k
  case tok::amp:                  return prec::And;
60
31.4k
  case tok::exclaimequal:
61
171k
  case tok::equalequal:           return prec::Equality;
62
160k
  case tok::lessequal:
63
10.0M
  case tok::less:
64
10.0M
  case tok::greaterequal:         return prec::Relational;
65
1.20k
  case tok::spaceship:            return prec::Spaceship;
66
270k
  case tok::lessless:             return prec::Shift;
67
597k
  case tok::plus:
68
2.55M
  case tok::minus:                return prec::Additive;
69
2.30M
  case tok::percent:
70
3.75M
  case tok::slash:
71
4.21M
  case tok::star:                 return prec::Multiplicative;
72
8.60k
  case tok::periodstar:
73
9.47k
  case tok::arrowstar:            return prec::PointerToMember;
74
114M
  }
75
114M
}
76
77
}  // namespace clang