summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gd_compiler.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /modules/gdscript/gd_compiler.h
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
downloadredot-engine-5dbf1809c6e3e905b94b8764e99491e608122261.tar.gz
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'modules/gdscript/gd_compiler.h')
-rw-r--r--modules/gdscript/gd_compiler.h144
1 files changed, 72 insertions, 72 deletions
diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gd_compiler.h
index eb6079e8e0..c84bd97246 100644
--- a/modules/gdscript/gd_compiler.h
+++ b/modules/gdscript/gd_compiler.h
@@ -32,7 +32,6 @@
#include "gd_parser.h"
#include "gd_script.h"
-
class GDCompiler {
const GDParser *parser;
@@ -43,83 +42,86 @@ class GDCompiler {
const GDParser::FunctionNode *function_node;
bool debug_stack;
- List< Map<StringName,int> > stack_id_stack;
- Map<StringName,int> stack_identifiers;
-
- List<GDFunction::StackDebug> stack_debug;
- List< Map<StringName,int> > block_identifier_stack;
- Map<StringName,int> block_identifiers;
-
- void add_stack_identifier(const StringName& p_id,int p_stackpos) {
- stack_identifiers[p_id]=p_stackpos;
- if (debug_stack) {
- block_identifiers[p_id]=p_stackpos;
- GDFunction::StackDebug sd;
- sd.added=true;
- sd.line=current_line;
- sd.identifier=p_id;
- sd.pos=p_stackpos;
- stack_debug.push_back(sd);
- }
- }
-
- void push_stack_identifiers() {
- stack_id_stack.push_back( stack_identifiers );
- if (debug_stack) {
-
- block_identifier_stack.push_back(block_identifiers);
- block_identifiers.clear();
- }
- }
-
- void pop_stack_identifiers() {
- stack_identifiers = stack_id_stack.back()->get();
- stack_id_stack.pop_back();
-
- if (debug_stack) {
- for (Map<StringName,int>::Element *E=block_identifiers.front();E;E=E->next()) {
-
- GDFunction::StackDebug sd;
- sd.added=false;
- sd.identifier=E->key();
- sd.line=current_line;
- sd.pos=E->get();
- stack_debug.push_back(sd);
- }
- block_identifiers=block_identifier_stack.back()->get();
- block_identifier_stack.pop_back();
- }
- }
+ List<Map<StringName, int> > stack_id_stack;
+ Map<StringName, int> stack_identifiers;
+
+ List<GDFunction::StackDebug> stack_debug;
+ List<Map<StringName, int> > block_identifier_stack;
+ Map<StringName, int> block_identifiers;
+
+ void add_stack_identifier(const StringName &p_id, int p_stackpos) {
+ stack_identifiers[p_id] = p_stackpos;
+ if (debug_stack) {
+ block_identifiers[p_id] = p_stackpos;
+ GDFunction::StackDebug sd;
+ sd.added = true;
+ sd.line = current_line;
+ sd.identifier = p_id;
+ sd.pos = p_stackpos;
+ stack_debug.push_back(sd);
+ }
+ }
+ void push_stack_identifiers() {
+ stack_id_stack.push_back(stack_identifiers);
+ if (debug_stack) {
+
+ block_identifier_stack.push_back(block_identifiers);
+ block_identifiers.clear();
+ }
+ }
+
+ void pop_stack_identifiers() {
+ stack_identifiers = stack_id_stack.back()->get();
+ stack_id_stack.pop_back();
+
+ if (debug_stack) {
+ for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) {
+
+ GDFunction::StackDebug sd;
+ sd.added = false;
+ sd.identifier = E->key();
+ sd.line = current_line;
+ sd.pos = E->get();
+ stack_debug.push_back(sd);
+ }
+ block_identifiers = block_identifier_stack.back()->get();
+ block_identifier_stack.pop_back();
+ }
+ }
//int get_identifier_pos(const StringName& p_dentifier) const;
- HashMap<Variant,int,VariantHasher,VariantComparator> constant_map;
- Map<StringName,int> name_map;
+ HashMap<Variant, int, VariantHasher, VariantComparator> constant_map;
+ Map<StringName, int> name_map;
- int get_name_map_pos(const StringName& p_identifier) {
+ int get_name_map_pos(const StringName &p_identifier) {
int ret;
if (!name_map.has(p_identifier)) {
- ret=name_map.size();
- name_map[p_identifier]=ret;
+ ret = name_map.size();
+ name_map[p_identifier] = ret;
} else {
- ret=name_map[p_identifier];
+ ret = name_map[p_identifier];
}
return ret;
}
- int get_constant_pos(const Variant& p_constant) {
+ int get_constant_pos(const Variant &p_constant) {
if (constant_map.has(p_constant))
return constant_map[p_constant];
int pos = constant_map.size();
- constant_map[p_constant]=pos;
+ constant_map[p_constant] = pos;
return pos;
}
Vector<int> opcodes;
- void alloc_stack(int p_level) { if (p_level >= stack_max) stack_max=p_level+1; }
- void alloc_call(int p_params) { if (p_params >= call_max) call_max=p_params; }
+ void alloc_stack(int p_level) {
+ if (p_level >= stack_max) stack_max = p_level + 1;
+ }
+ void alloc_call(int p_params) {
+ if (p_params >= call_max) call_max = p_params;
+ }
- int current_line;
+ int current_line;
int stack_max;
int call_max;
};
@@ -135,28 +137,27 @@ class GDCompiler {
Ref<GDScript> _parse_class(GDParser::ClassNode *p_class);
#endif
- bool _is_class_member_property(CodeGen & codegen, const StringName & p_name);
- bool _is_class_member_property(GDScript *owner, const StringName & p_name);
+ bool _is_class_member_property(CodeGen &codegen, const StringName &p_name);
+ bool _is_class_member_property(GDScript *owner, const StringName &p_name);
- void _set_error(const String& p_error,const GDParser::Node *p_node);
+ void _set_error(const String &p_error, const GDParser::Node *p_node);
- bool _create_unary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level);
- bool _create_binary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level,bool p_initializer=false);
+ bool _create_unary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level);
+ bool _create_binary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer = false);
//int _parse_subexpression(CodeGen& codegen,const GDParser::BlockNode *p_block,const GDParser::Node *p_expression);
- int _parse_assign_right_expression(CodeGen& codegen,const GDParser::OperatorNode *p_expression, int p_stack_level);
- int _parse_expression(CodeGen& codegen,const GDParser::Node *p_expression, int p_stack_level,bool p_root=false,bool p_initializer=false);
- Error _parse_block(CodeGen& codegen,const GDParser::BlockNode *p_block,int p_stack_level=0,int p_break_addr=-1,int p_continue_addr=-1);
- Error _parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func,bool p_for_ready=false);
- Error _parse_class(GDScript *p_script,GDScript *p_owner,const GDParser::ClassNode *p_class,bool p_keep_state);
+ int _parse_assign_right_expression(CodeGen &codegen, const GDParser::OperatorNode *p_expression, int p_stack_level);
+ int _parse_expression(CodeGen &codegen, const GDParser::Node *p_expression, int p_stack_level, bool p_root = false, bool p_initializer = false);
+ Error _parse_block(CodeGen &codegen, const GDParser::BlockNode *p_block, int p_stack_level = 0, int p_break_addr = -1, int p_continue_addr = -1);
+ Error _parse_function(GDScript *p_script, const GDParser::ClassNode *p_class, const GDParser::FunctionNode *p_func, bool p_for_ready = false);
+ Error _parse_class(GDScript *p_script, GDScript *p_owner, const GDParser::ClassNode *p_class, bool p_keep_state);
int err_line;
int err_column;
StringName source;
String error;
public:
-
- Error compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state=false);
+ Error compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state = false);
String get_error() const;
int get_error_line() const;
@@ -165,5 +166,4 @@ public:
GDCompiler();
};
-
#endif // COMPILER_H