-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshader.cpp
More file actions
66 lines (55 loc) · 1.59 KB
/
shader.cpp
File metadata and controls
66 lines (55 loc) · 1.59 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
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
#include "shader.hpp"
FloatConst* floatc(double value) {
return new FloatConst(value);
}
FloatConst* floatc(const char *value) {
return new FloatConst(value);
}
IntConst* intc(int value) {
return new IntConst(value);
}
Reference* ref(std::string name) {
return new Reference(name);
}
BracedExpr* braced(Expression* expr) {
return new BracedExpr(expr);
}
TypeConstructor* vec2(std::initializer_list<Expression*> args) {
return new TypeConstructor(Vec2, new std::vector<Expression*>(args));
}
TypeConstructor* vec3(std::initializer_list<Expression*> args) {
return new TypeConstructor(Vec3, new std::vector<Expression*>(args));
}
TypeConstructor* vec4(std::initializer_list<Expression*> args) {
return new TypeConstructor(Vec4, new std::vector<Expression*>(args));
}
FunctionCall* fcall(std::string name, std::initializer_list<Expression*> args) {
return new FunctionCall(name, new std::vector<Expression*>(args));
}
AstNode* parseFile(std::string fileName) {
FILE *sourceFile;
errno = 0;
#ifdef _WIN32
fopen_s(&sourceFile, fileName.c_str(), "r");
#else
sourceFile = fopen(fileName.c_str(), "r");
#endif
if (!sourceFile) {
printf("Can't open file %d", errno);
exit(1);
}
yyin = sourceFile;
do {
yyparse();
} while (!feof(yyin));
//std::string str;
//result->toStringF(&str, new FormatState());
//fprintf(stdout, str.c_str());
return result;
}
std::string getFileStr(std::string fileName) {
AstNode *result = parseFile(fileName);
std::string str;
result->toStringF(&str, new FormatState());
return str;
}