Gyoji Compiler
Loading...
Searching...
No Matches
jformat-toc.hpp
1/* Copyright 2025 Jonathan S. Arney
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://github.com/jarney/gyoji/blob/master/LICENSE
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#pragma once
16
17#include "jbackend.hpp"
18
24
33
34 class Statement {
35 };
36
37 enum TypeType {
38 TYPE_PRIMITIVE,
39 TYPE_STRUCT,
40 TYPE_POINTER
41 };
42
43 class Type;
44
45 class LValue {
46 public:
47 int id;
49 };
50
51 class RValue {
52 int id;
54 };
55
56 class Member {
57 public:
58 std::string name;
60 };
61
62 class Type {
63 public:
64 TypeType type;
65 std::string primitive; // PRIMITIVE TYPES
66 std::list<std::shared_ptr<Member>> members; // Member variables.
67 std::shared_ptr<Type> target; // Target type of the pointer.
68 };
69
70// Expressions propagate types
71// binary operations must all be same type.
72// & operator adds an indirection to a type.
73// * removes an indirection from a type.
74// Functions have return types.
75// Arithmetic is banned except for primitive types.
76 class Expression {
77 public:
79 };
80
81 class StatementDeclaration : public Statement {
82 public:
83 std::string variable_name;
84 std::shared_ptr<Type> type; // Type of variable being declared.
85 };
86
87 class StatementAssignment : public Statement {
88 public:
89 std::shared_ptr<LValue> lvalue; // Target of declaration
90 std::shared_ptr<Expression> rvalue; // Expression to assign value to.
91 };
92
93 class FunctionBody {
94 public:
95 std::list<Statement> statements;
96 };
97
98 class FunctionArgument {
99 public:
101 std::string name;
102 };
103
104// This is the definition
105// of a function.
106 class Function {
107 public:
108 std::shared_ptr<Type> return_type;
109 std::string name;
112 };
113
114 class FunctionTable {
115 public:
117 };
118
119 class TypeTable {
120 public:
122 };
123
129 class JBackendToC : public JBackend {
130 public:
131 JBackendToC();
132 ~JBackendToC();
133 virtual int process(ASTNode::ptr file);
134
135 std::string collect_comments(ASTNode::ptr node);
136 std::string break_multiline_comment(std::string str);
137
138 // void print_whitespace(ASTDataNonSyntax::ptr node);
139 // void print_comments(std::vector<ASTDataNonSyntax::ptr> &non_syntax_list);
140 // void print_comment_single_line(ASTDataNonSyntax::ptr node);
141 // void print_comment_multi_line(ASTDataNonSyntax::ptr node);
142 // void print_file_metadata(ASTDataNonSyntax::ptr node);
143 // void print_non_syntax(ASTDataNonSyntax::ptr node);
144
145 // void print_node_generic(ASTNode::ptr node);
146 // void print_node_plain(ASTNode::ptr node);
147 void print_scope_body(ASTNode::ptr node);
148 void newline();
149 void print_typedef(ASTNode::ptr node);
150 void print_import(ASTNode::ptr node);
151 void print_node_function_definition(ASTNode::ptr node);
152
153 void process_definition(ASTNode::ptr node);
154
155 void dump_types();
156 void dump_functions();
157
158 int indent_level;
159 int depth;
160
161 FunctionTable function_table;
162 TypeTable type_table;
163 };
164
165};
166
Definition jformat-toc.hpp:129
Backend formatting the output as C syntax.
Definition jformat-toc.hpp:32