forked from metthal/IFJ-Projekt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuiltin.h
166 lines (145 loc) · 4.16 KB
/
builtin.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Project name:
* Implementace interpretu imperativního jazyka IFJ13.
*
* Codename:
* INI: Ni Interpreter
*
* Description:
* https://wis.fit.vutbr.cz/FIT/st/course-files-st.php/course/IFJ-IT/projects/ifj2013.pdf
*
* Project's GitHub repository:
* https://github.com/metthal/IFJ-Projekt
*
* Team:
* Marek Milkovič (xmilko01)
* Lukáš Vrabec (xvrabe07)
* Ján Spišiak (xspisi03)
* Ivan Ševčík (xsevci50)
* Marek Bertovič (xberto00)
*/
/**
* @file builtin.h
* @brief Declares built-in functions and their helpers.
*/
#ifndef BUILTIN_H
#define BUILTIN_H
#include "string.h"
#include "symbol.h"
/** Codes for identifying builtin functions */
typedef enum
{
BTI_None = 0, //!< BTI_None
BTI_BoolVal, //!< BTI_BoolVal
BTI_DoubleVal, //!< BTI_DoubleVal
BTI_FindString, //!< BTI_FindString
BTI_GetString, //!< BTI_GetString
BTI_GetSubstring,//!< BTI_GetSubstring
BTI_IntVal, //!< BTI_IntVal
BTI_PutString, //!< BTI_PutString
BTI_SortString, //!< BTI_SortString
BTI_StrLen, //!< BTI_StrLen
BTI_StrVal, //!< BTI_StrVal
} BuiltinCode;
/**
* Returns built-in code when string matches a name
* of built-in function. BTI_None otherwise.
* @param str String to be matched.
* @return Resulting built-in code.
*/
BuiltinCode getBuiltinCode(const String *str);
/**
* Returns number of parameters for a built-in function.
* @param code Built-in function code.
* @return Number of parameters.
*/
int64_t getBuiltinParamCount(BuiltinCode code);
/**
* @brief Converts value directly into boolean.
* @param val Value to convert.
* @return Resulting booelan.
*/
uint8_t valueToBool(const Value *val);
/**
* @brief Converts value directly into integer.
* @param val Value to convert.
* @return Resulting integer.
*/
int valueToInt(const Value *val);
/**
* @brief Converts value directly into double.
* @param val Value to convert.
* @return Resulting double.
*/
double valueToDouble(const Value *val);
/**
* @brief Converts value directly into string.
* @param val Value to convert.
* @param str Resulting string.
*/
void valueToString(const Value *val, String *str);
/**
* @brief Converts any value to boolean.
* @param val Value to be converted.
* @param ret Converted value.
*/
void boolval(const Value *val, Value *ret);
/**
* @brief Converts any value to double.
* @param val Value to be converted.
* @param ret Converted value.
*/
void doubleval(const Value *val, Value *ret);
/**
* Searches for a match of strings.
* @param ret Index of first index in match as integer.
* @param a String in which to search.
* @param b String to be searched.
*/
void findString(Value *ret, const Value *a, const Value *b);
/**
* Reads a string from the input.
* @param ret Read string.
*/
void getString(Value *ret);
/**
* @brief Cuts a substring out of original string.
* @param val Original string. If not string, it is converted.
* @param ret Resulting substring.
* @param start First index to be included in substring.
* @param end First index not to be included in substring.
*/
void getSubstring(const Value *val, Value *ret, int start, int end);
/**
* @brief Converts any value to integer.
* @param val Value to be converted.
* @param ret Converted value.
*/
void intval(const Value *val, Value *ret);
/**
* @brief Prints all passed values using predefined formating.
* @param base Base stack address for offsetting.
* @param constBase Base constants address for offsetting.
* @param ret Number of printed values.
* @param count Number of values passed.
*/
void putString(const Value *base, const Value *constBase, Value *ret, int count);
/**
* @brief Sorts the passsed string.
* @param val String to sort. If not string, it is converted.
* @param ret Sorted string.
*/
void sortString(const Value *val, Value *ret);
/**
* @brief Returns length of passed string.
* @param val String to querry. If not string, it is converted.
* @param ret Length of string as integer.
*/
void strLen(const Value *val, Value *ret);
/**
* @brief Converts any value to string.
* @param val Value to be converted.
* @param ret Converted value.
*/
void strval(const Value *val, Value *ret);
#endif