-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.h
116 lines (91 loc) · 3.13 KB
/
Function.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
//
// Created by ki11errabbit on 9/9/22.
//
#ifndef CWITHCLASSES_FUNCTION_H
#define CWITHCLASSES_FUNCTION_H
#include <string>
#include <vector>
#include <iostream>
#include "Token.h"
#include "Parameter.h"
#include "CodeBlock.h"
class Function {
private:
string returnType, functionName;
vector<Parameter> parameters;
CodeBlock body;
public:
Function() {
returnType = "";
functionName = "";
vector<string> temp = {""};
body = CodeBlock(temp);
}
Function(string returnType, string functionName, vector<Parameter> parameters,CodeBlock body)
: returnType(returnType),functionName(functionName),parameters(parameters), body(body) {}
Function(string returnType, string functionName,CodeBlock body)
: returnType(returnType),functionName(functionName), body(body) {}
string getFunctionName() {
return functionName;
}
string getName() {
return functionName;
}
string pointerForm(){
stringstream out;
out << returnType << " (*" << functionName << ")(";
for (size_t i = 0; i < parameters.size(); i++) {
string param = parameters.at(i).getType() + parameters.at(i).getPointer();
out << param;
if (i < parameters.size()-1)
out << ", ";
}
out << ");";
return out.str();
}
string functionFormPlain() {
stringstream out;
out << returnType << " " << functionName << "(";
for (size_t i = 0; i < parameters.size(); i++) {
out << parameters.at(i).getType() << " " << parameters.at(i).getPointer() << parameters.at(i).getName();
if (i < parameters.size()-1)
out << ", ";
}
out << ") " << body;
return out.str();
}
string functionForm(string nameSpace) {
stringstream out;
out << returnType << " " << nameSpace << "_" <<functionName << "(";
for (size_t i = 0; i < parameters.size(); i++) {
out << parameters.at(i).getType() << " " << parameters.at(i).getPointer() << parameters.at(i).getName();
if (i < parameters.size()-1)
out << ", ";
}
out << ") " << body;
return out.str();
}
string definitionForm(string nameSpace) {
stringstream out;
out << returnType << " " << nameSpace << "_" <<functionName << "(";
for (size_t i = 0; i < parameters.size(); i++) {
out << parameters.at(i).getType() << " " << parameters.at(i).getPointer() << parameters.at(i).getName();
if (i < parameters.size()-1)
out << ", ";
}
out << ");";
return out.str();
}
string definitionFormPlain() {
stringstream out;
out << returnType << " " << functionName << "(";
for (size_t i = 0; i < parameters.size(); i++) {
out << parameters.at(i).getType() << " " << parameters.at(i).getPointer() << parameters.at(i).getName();
if (i < parameters.size()-1)
out << ", ";
}
out << ");";
return out.str();
}
};
#endif //CWITHCLASSES_FUNCTION_H