GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
UsedExtensionsFinder.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 
7 #pragma once
8 
9 #include <set>
10 #include <vector>
11 
12 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
13 #include "GDCore/Extensions/Metadata/SourceFileMetadata.h"
14 #include "GDCore/Extensions/Metadata/InGameEditorResourceMetadata.h"
15 #include "GDCore/Extensions/PlatformExtension.h"
16 #include "GDCore/IDE/Events/ArbitraryEventsWorker.h"
17 #include "GDCore/IDE/Project/ArbitraryObjectsWorker.h"
18 #include "GDCore/String.h"
19 
20 namespace gd {
21 class Project;
22 class Object;
23 class Behavior;
24 } // namespace gd
25 
26 namespace gd {
27 
28 class GD_CORE_API UsedExtensionsResult {
29 public:
33  const std::set<gd::String> &GetUsedExtensions() const {
34  return usedExtensions;
35  }
36 
40  const std::set<gd::String> &GetUsedIncludeFiles() const {
41  return usedIncludeFiles;
42  }
43 
47  const std::set<gd::String> &GetUsedRequiredFiles() const {
48  return usedRequiredFiles;
49  }
50 
51  const std::vector<gd::SourceFileMetadata>& GetUsedSourceFiles() const {
52  return usedSourceFiles;
53  }
54 
55  const std::vector<gd::InGameEditorResourceMetadata>& GetUsedInGameEditorResources() const {
56  return usedInGameEditorResources;
57  }
58 
62  bool Has3DObjects() const {
63  return has3DObjects;
64  }
65 
66  void AddUsedExtension(const gd::PlatformExtension& extension);
67  void AddUsedBuiltinExtension(const gd::Project& project, const gd::String& extensionName);
68  void AddUsedIncludeFiles(const gd::String& includeFile) { usedIncludeFiles.insert(includeFile); }
69  void AddUsedRequiredFiles(const gd::String& requiredFile) { usedRequiredFiles.insert(requiredFile); }
70  void AddUsedInGameEditorResource(const gd::InGameEditorResourceMetadata& inGameEditorResource) {
71  usedInGameEditorResources.push_back(inGameEditorResource);
72  }
73 
74  void MarkAsHaving3DObjects() {
75  has3DObjects = true;
76  }
77 
78 private:
79  std::set<gd::String> usedExtensions;
80  std::set<gd::String> usedIncludeFiles;
81  std::set<gd::String> usedRequiredFiles;
82  std::vector<gd::SourceFileMetadata> usedSourceFiles;
83  std::vector<gd::InGameEditorResourceMetadata> usedInGameEditorResources;
84  bool has3DObjects = false;
85 };
86 
87 class GD_CORE_API UsedExtensionsFinder
88  : public ArbitraryObjectsWorker,
91  public:
92  static const UsedExtensionsResult ScanProject(gd::Project& project);
93  static const UsedExtensionsResult ScanEventsFunctionsExtension(
94  gd::Project &project,
95  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
96  static const std::vector<gd::String> FindExtensionsDependentOn(
97  gd::Project &project,
98  const gd::EventsFunctionsExtension &eventsFunctionsExtension);
99 
100 private:
101  UsedExtensionsFinder(gd::Project& project_) : project(project_){};
102  gd::Project& project;
103  gd::String rootType;
104  UsedExtensionsResult result;
105 
106  // Object Visitor
107  void DoVisitObject(gd::Object& object) override;
108 
109  // Behavior Visitor
110  void DoVisitBehavior(gd::Behavior& behavior) override;
111 
112  // Instructions Visitor
113  bool DoVisitInstruction(gd::Instruction& instruction,
114  bool isCondition) override;
115 
116  // Expression Visitor
117  void OnVisitSubExpressionNode(SubExpressionNode& node) override;
118  void OnVisitOperatorNode(OperatorNode& node) override;
119  void OnVisitUnaryOperatorNode(UnaryOperatorNode& node) override;
120  void OnVisitNumberNode(NumberNode& node) override;
121  void OnVisitTextNode(TextNode& node) override;
122  void OnVisitVariableNode(VariableNode& node) override;
123  void OnVisitVariableAccessorNode(VariableAccessorNode& node) override;
124  void OnVisitVariableBracketAccessorNode(
125  VariableBracketAccessorNode& node) override;
126  void OnVisitIdentifierNode(IdentifierNode& node) override;
127  void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node) override;
128  void OnVisitFunctionCallNode(FunctionCallNode& node) override;
129  void OnVisitEmptyNode(EmptyNode& node) override;
130 };
131 
132 }; // namespace gd
An events worker that will know about the context (the objects container). Useful for workers working...
Definition: ArbitraryEventsWorker.h:136
ArbitraryObjectsWorker is an abstract class used to browse objects (and behaviors) and do some work o...
Definition: ArbitraryObjectsWorker.h:30
Base class used to represents a behavior that can be applied to an object. It stores the content (i....
Definition: Behavior.h:23
Hold a list of Events Functions (gd::EventsFunction) and Events Based Behaviors.
Definition: EventsFunctionsExtension.h:41
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
Describe a resource to be used in the in-game editor.
Definition: InGameEditorResourceMetadata.h:14
An instruction is a member of an event: It can be a condition or an action.
Definition: Instruction.h:30
Represent an object of a platform.
Definition: Object.h:37
Base class for implementing platform's extensions.
Definition: PlatformExtension.h:84
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: UsedExtensionsFinder.h:90
Definition: UsedExtensionsFinder.h:28
const std::set< gd::String > & GetUsedExtensions() const
Definition: UsedExtensionsFinder.h:33
const std::set< gd::String > & GetUsedRequiredFiles() const
Definition: UsedExtensionsFinder.h:47
bool Has3DObjects() const
Return true when at least 1 object uses the 3D renderer.
Definition: UsedExtensionsFinder.h:62
const std::set< gd::String > & GetUsedIncludeFiles() const
Definition: UsedExtensionsFinder.h:40
Definition: CommonTools.h:24
An empty node, used when parsing failed/a syntax error was encountered and any other node could not m...
Definition: ExpressionParser2Node.h:423
A function call node (either free function, object function or object behavior function)....
Definition: ExpressionParser2Node.h:371
An identifier node, usually representing an object or a variable with an optional function name or ch...
Definition: ExpressionParser2Node.h:204
A number node. For example: "123". Its type is always "number".
Definition: ExpressionParser2Node.h:161
The name of a function to call on an object or the behavior For example: "MyObject....
Definition: ExpressionParser2Node.h:321
An operator node. For example: "lhs + rhs".
Definition: ExpressionParser2Node.h:129
Definition: ExpressionParser2Node.h:115
A text node. For example: "Hello World". Its type is always "string".
Definition: ExpressionParser2Node.h:177
A unary operator node. For example: "-2".
Definition: ExpressionParser2Node.h:145
A direct accessor to a child variable. Example: MyChild in MyVariable.MyChild.
Definition: ExpressionParser2Node.h:282
A bracket accessor to a child variable. Example: ["MyChild"] (in MyVariable["MyChild"]).
Definition: ExpressionParser2Node.h:300
A variable, or object variable, with bracket accessor or at least 2 "dot" accessors.
Definition: ExpressionParser2Node.h:261