-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppvariable.py
More file actions
36 lines (30 loc) · 1.2 KB
/
Copy pathcppvariable.py
File metadata and controls
36 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class CPPVariable():
"""
This class represents a variable, holding information about it to be used
while outputting to the C++ file
"""
# Using redundant mapping to allow for changes to mapped type
types = {
"int": "int ", "float": "double ", "str": "std::string ",
"bool": "bool ", "None": "NULL", "char **": "char **",
"void": "void ", "auto": "auto ", "NoneType": "void "
}
# Python uses capital letters while C++ uses lowercase
bool_map = {"True": "true", "False": "false"}
def __init__(self, name, line_num, py_var_type):
"""
Constructs a C++ variable object representation converted from python
Parameters
----------
name : str
The name of the variable
line_num : int
The line number this variable was declared on in python
py_var_type : list of str
The type of the variable in python
"""
self.name = name
self.line_num = line_num
# We use a list here to get a mutable type so that a change to one
# linked variable will reflect the change across all objects
self.py_var_type = py_var_type