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 #ifndef GDCORE_USED_EXTENSIONS_FINDER_H
8 #define GDCORE_USED_EXTENSIONS_FINDER_H
9 #include <set>
10 
11 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
12 #include "GDCore/Extensions/Metadata/SourceFileMetadata.h"
13 #include "GDCore/Extensions/PlatformExtension.h"
14 #include "GDCore/IDE/Events/ArbitraryEventsWorker.h"
15 #include "GDCore/IDE/Project/ArbitraryObjectsWorker.h"
16 #include "GDCore/String.h"
17 
18 namespace gd {
19 class Project;
20 class Object;
21 class Behavior;
22 } // namespace gd
23 
24 namespace gd {
25 
26 class GD_CORE_API UsedExtensionsResult {
27 public:
31  const std::set<gd::String> &GetUsedExtensions() const {
32  return usedExtensions;
33  }
34 
38  const std::set<gd::String> &GetUsedIncludeFiles() const {
39  return usedIncludeFiles;
40  }
41 
45  const std::set<gd::String> &GetUsedRequiredFiles() const {
46  return usedRequiredFiles;
47  }
48 
49  const std::vector<gd::SourceFileMetadata>& GetUsedSourceFiles() const {
50  return usedSourceFiles;
51  }
52 
56  bool Has3DObjects() const {
57  return has3DObjects;
58  }
59 
60  void AddUsedExtension(const gd::PlatformExtension& extension);
61  void AddUsedBuiltinExtension(const gd::String& extensionName);
62  void AddUsedIncludeFiles(const gd::String& includeFile) { usedIncludeFiles.insert(includeFile); }
63  void AddUsedRequiredFiles(const gd::String& requiredFile) { usedRequiredFiles.insert(requiredFile); }
64 
65  void MarkAsHaving3DObjects() {
66  has3DObjects = true;
67  }
68 
69 private:
70  std::set<gd::String> usedExtensions;
71  std::set<gd::String> usedIncludeFiles;
72  std::set<gd::String> usedRequiredFiles;
73  std::vector<gd::SourceFileMetadata> usedSourceFiles;
74  bool has3DObjects = false;
75 };
76 
77 class GD_CORE_API UsedExtensionsFinder
78  : public ArbitraryObjectsWorker,
81  public:
82  static const UsedExtensionsResult ScanProject(gd::Project& project);
83 
84  private:
85  UsedExtensionsFinder(gd::Project& project_) : project(project_){};
86  gd::Project& project;
87  gd::String rootType;
88  UsedExtensionsResult result;
89 
90  // Object Visitor
91  void DoVisitObject(gd::Object& object) override;
92 
93  // Behavior Visitor
94  void DoVisitBehavior(gd::Behavior& behavior) override;
95 
96  // Instructions Visitor
97  bool DoVisitInstruction(gd::Instruction& instruction,
98  bool isCondition) override;
99 
100  // Expression Visitor
101  void OnVisitSubExpressionNode(SubExpressionNode& node) override;
102  void OnVisitOperatorNode(OperatorNode& node) override;
103  void OnVisitUnaryOperatorNode(UnaryOperatorNode& node) override;
104  void OnVisitNumberNode(NumberNode& node) override;
105  void OnVisitTextNode(TextNode& node) override;
106  void OnVisitVariableNode(VariableNode& node) override;
107  void OnVisitVariableAccessorNode(VariableAccessorNode& node) override;
108  void OnVisitVariableBracketAccessorNode(
109  VariableBracketAccessorNode& node) override;
110  void OnVisitIdentifierNode(IdentifierNode& node) override;
111  void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node) override;
112  void OnVisitFunctionCallNode(FunctionCallNode& node) override;
113  void OnVisitEmptyNode(EmptyNode& node) override;
114 };
115 
116 }; // namespace gd
117 
118 #endif
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
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
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:80
Definition: UsedExtensionsFinder.h:26
const std::set< gd::String > & GetUsedExtensions() const
Definition: UsedExtensionsFinder.h:31
const std::set< gd::String > & GetUsedRequiredFiles() const
Definition: UsedExtensionsFinder.h:45
bool Has3DObjects() const
Return true when at least 1 object uses the 3D renderer.
Definition: UsedExtensionsFinder.h:56
const std::set< gd::String > & GetUsedIncludeFiles() const
Definition: UsedExtensionsFinder.h:38
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