From 5d6e8538065050d5f5579ec03cfa9e241811e062 Mon Sep 17 00:00:00 2001 From: George Marques Date: Fri, 1 May 2020 19:14:56 -0300 Subject: New GDScript tokenizer and parser Sometimes to fix something you have to break it first. This get GDScript mostly working with the new tokenizer and parser but a lot of things isn't working yet. It compiles and it's usable, and that should be enough for now. Don't worry: other huge commits will come after this. --- modules/gdscript/gdscript_parser.h | 1321 ++++++++++++++++++++++-------------- 1 file changed, 829 insertions(+), 492 deletions(-) (limited to 'modules/gdscript/gdscript_parser.h') diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 7dedb6d6f9..09cb17f010 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -31,665 +31,1002 @@ #ifndef GDSCRIPT_PARSER_H #define GDSCRIPT_PARSER_H +#include "core/hash_map.h" +#include "core/io/multiplayer_api.h" +#include "core/list.h" #include "core/map.h" -#include "core/object.h" +#include "core/reference.h" +#include "core/resource.h" #include "core/script_language.h" +#include "core/string_name.h" +#include "core/ustring.h" +#include "core/variant.h" +#include "core/vector.h" #include "gdscript_functions.h" #include "gdscript_tokenizer.h" -struct GDScriptDataType; -struct GDScriptWarning; +#ifdef DEBUG_ENABLED +#include "core/string_builder.h" +#endif // DEBUG_ENABLED class GDScriptParser { + struct AnnotationInfo; + public: + // Forward-declare all parser nodes, to avoid ordering issues. + struct AnnotationNode; + struct ArrayNode; + struct AssertNode; + struct AssignmentNode; + struct AwaitNode; + struct BinaryOpNode; + struct BreakNode; + struct BreakpointNode; + struct CallNode; + struct CastNode; struct ClassNode; + struct ConstantNode; + struct ContinueNode; + struct DictionaryNode; + struct EnumNode; + struct ExpressionNode; + struct ForNode; + struct FunctionNode; + struct GetNodeNode; + struct IdentifierNode; + struct IfNode; + struct LiteralNode; + struct MatchNode; + struct MatchBranchNode; + struct ParameterNode; + struct PassNode; + struct PatternNode; + struct PreloadNode; + struct ReturnNode; + struct SelfNode; + struct SignalNode; + struct SubscriptNode; + struct SuiteNode; + struct TernaryOpNode; + struct TypeNode; + struct UnaryOpNode; + struct VariableNode; + struct WhileNode; struct DataType { enum Kind { BUILTIN, NATIVE, SCRIPT, - GDSCRIPT, - CLASS, - UNRESOLVED + CLASS, // GDScript. + UNRESOLVED, }; - Kind kind = UNRESOLVED; - bool has_type = false; + enum TypeSource { + UNDETECTED, // Can be any type. + INFERRED, // Has inferred type, but still dynamic. + ANNOTATED_EXPLICIT, // Has a specific type annotated. + ANNOTATED_INFERRED, // Has a static type but comes from the assigned value. + }; + TypeSource type_source = UNDETECTED; + bool is_constant = false; - bool is_meta_type = false; // Whether the value can be used as a type + bool is_meta_type = false; bool infer_type = false; - bool may_yield = false; // For function calls Variant::Type builtin_type = Variant::NIL; StringName native_type; Ref