cpp

Coverage Report

Created: 2022-09-21 22:22

/home/andy/git/oilshell/oil/mycpp/builtins.h
Line
Count
Source (jump to first uncovered line)
1
// builtins.h: Statically typed Python builtins.
2
//
3
// Builtin types: tuples, NotImplementedError, AssertionError
4
// Builtin functions: print(), repr(), ord()
5
// Builtin operators: str_concat(), str_repeat(), list_repeat()
6
7
#ifndef GC_BUILTINS_H
8
#define GC_BUILTINS_H
9
10
class Str;
11
12
class IndexError {};
13
class ValueError {};
14
class KeyError {};
15
16
class EOFError {};
17
18
class NotImplementedError {
19
 public:
20
0
  NotImplementedError() {
21
0
  }
22
0
  explicit NotImplementedError(int i) {  // e.g. in expr_to_ast
23
0
  }
24
0
  explicit NotImplementedError(const char* s) {
25
0
  }
26
0
  explicit NotImplementedError(Str* s) {
27
0
  }
28
};
29
30
class AssertionError {
31
 public:
32
0
  AssertionError() {
33
0
  }
34
0
  explicit AssertionError(int i) {  // e.g. in expr_to_ast
35
0
  }
36
0
  explicit AssertionError(const char* s) {
37
0
  }
38
0
  explicit AssertionError(Str* s) {
39
0
  }
40
};
41
42
// Python's RuntimeError looks like this.  . libc::regex_match and other
43
// bindings raise it.
44
class RuntimeError {
45
 public:
46
0
  explicit RuntimeError(Str* message) : message(message) {
47
0
  }
48
  Str* message;
49
};
50
51
// TODO: remove this.  cmd_eval.py RunOilProc uses it, which we probably
52
// don't need
53
class TypeError {
54
 public:
55
0
  explicit TypeError(Str* arg) {
56
0
    assert(0);
57
0
  }
58
};
59
60
class KeyboardInterrupt {};
61
62
Str* AllocStr(int len);
63
64
void print(Str* s);
65
66
void println_stderr(Str* s);
67
68
Str* repr(Str* s);
69
70
// For hnode::External in asdl/format.py.  TODO: Remove this when that is removed.
71
0
inline Str* repr(void* obj) {
72
0
  InvalidCodePath();
73
0
}
Unexecuted instantiation: _Z4reprPv
Unexecuted instantiation: _Z4reprPv
74
75
0
inline Str* str(double f) {
76
0
  NotImplemented();
77
0
}
78
79
Str* str(int i);
80
81
bool _str_to_int(Str* s, int* result, int base);  // for testing only
82
int to_int(Str* s);
83
int to_int(Str* s, int base);
84
85
Str* chr(int i);
86
int ord(Str* s);
87
88
0
inline int to_int(bool b) {
89
0
  return b;
90
0
}
91
92
bool to_bool(Str* s);
93
double to_float(Str* s);
94
95
1
inline bool to_bool(int i) {
96
1
  return i != 0;
97
1
}
98
99
bool str_contains(Str* haystack, Str* needle);
100
101
// mycpp doesn't understand dynamic format strings yet
102
0
inline Str* dynamic_fmt_dummy() {
103
0
  Str* Result = AllocStr(1);
104
0
  return Result;
105
0
}
106
107
#endif  // GC_BUILTINS_H