Gyoji Compiler
Loading...
Searching...
No Matches
jformat-toc.hpp
1#pragma once
2
3#include "jbackend.hpp"
4
10
19
20 class Statement {
21 };
22
23 enum TypeType {
24 TYPE_PRIMITIVE,
25 TYPE_STRUCT,
26 TYPE_POINTER
27 };
28
29 class Type;
30
31 class LValue {
32 public:
33 int id;
35 };
36
37 class RValue {
38 int id;
40 };
41
42 class Member {
43 public:
44 std::string name;
46 };
47
48 class Type {
49 public:
50 TypeType type;
51 std::string primitive; // PRIMITIVE TYPES
52 std::list<std::shared_ptr<Member>> members; // Member variables.
53 std::shared_ptr<Type> target; // Target type of the pointer.
54 };
55
56// Expressions propagate types
57// binary operations must all be same type.
58// & operator adds an indirection to a type.
59// * removes an indirection from a type.
60// Functions have return types.
61// Arithmetic is banned except for primitive types.
62 class Expression {
63 public:
65 };
66
67 class StatementDeclaration : public Statement {
68 public:
69 std::string variable_name;
70 std::shared_ptr<Type> type; // Type of variable being declared.
71 };
72
73 class StatementAssignment : public Statement {
74 public:
75 std::shared_ptr<LValue> lvalue; // Target of declaration
76 std::shared_ptr<Expression> rvalue; // Expression to assign value to.
77 };
78
79 class FunctionBody {
80 public:
81 std::list<Statement> statements;
82 };
83
84 class FunctionArgument {
85 public:
87 std::string name;
88 };
89
90// This is the definition
91// of a function.
92 class Function {
93 public:
94 std::shared_ptr<Type> return_type;
95 std::string name;
98 };
99
100 class FunctionTable {
101 public:
103 };
104
105 class TypeTable {
106 public:
108 };
109
115 class JBackendToC : public JBackend {
116 public:
117 JBackendToC();
118 ~JBackendToC();
119 virtual int process(ASTNode::ptr file);
120
121 std::string collect_comments(ASTNode::ptr node);
122 std::string break_multiline_comment(std::string str);
123
124 // void print_whitespace(ASTDataNonSyntax::ptr node);
125 // void print_comments(std::vector<ASTDataNonSyntax::ptr> &non_syntax_list);
126 // void print_comment_single_line(ASTDataNonSyntax::ptr node);
127 // void print_comment_multi_line(ASTDataNonSyntax::ptr node);
128 // void print_file_metadata(ASTDataNonSyntax::ptr node);
129 // void print_non_syntax(ASTDataNonSyntax::ptr node);
130
131 // void print_node_generic(ASTNode::ptr node);
132 // void print_node_plain(ASTNode::ptr node);
133 void print_scope_body(ASTNode::ptr node);
134 void newline();
135 void print_typedef(ASTNode::ptr node);
136 void print_import(ASTNode::ptr node);
137 void print_node_function_definition(ASTNode::ptr node);
138
139 void process_definition(ASTNode::ptr node);
140
141 void dump_types();
142 void dump_functions();
143
144 int indent_level;
145 int depth;
146
147 FunctionTable function_table;
148 TypeTable type_table;
149 };
150
151};
152
Definition jformat-toc.hpp:115
Backend formatting the output as C syntax.
Definition jformat-toc.hpp:18