2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CC_PU_SCRIPT_COMPILER_H__
|
|
|
|
#define __CC_PU_SCRIPT_COMPILER_H__
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "extensions/Particle3D/PU/CCPUScriptParser.h"
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/** This enum holds the types of the possible abstract nodes */
|
|
|
|
enum PUAbstractNodeType
|
|
|
|
{
|
|
|
|
ANT_UNKNOWN,
|
|
|
|
ANT_ATOM,
|
|
|
|
ANT_OBJECT,
|
|
|
|
ANT_PROPERTY,
|
|
|
|
ANT_IMPORT,
|
|
|
|
ANT_VARIABLE_SET,
|
|
|
|
ANT_VARIABLE_ACCESS
|
|
|
|
};
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUAbstractNode;
|
2019-11-23 20:27:39 +08:00
|
|
|
typedef std::list<PUAbstractNode*> PUAbstractNodeList;
|
|
|
|
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUAbstractNode
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string file;
|
|
|
|
unsigned int line;
|
|
|
|
PUAbstractNodeType type;
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAbstractNode* parent;
|
|
|
|
Ref* context;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// contextd//
|
|
|
|
// Any context; // A holder for translation context data
|
|
|
|
public:
|
|
|
|
PUAbstractNode(PUAbstractNode* ptr) : line(0), type(ANT_UNKNOWN), parent(ptr), context(nullptr) {}
|
|
|
|
virtual ~PUAbstractNode() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
/// Returns a new AbstractNode which is a replica of this one.
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual PUAbstractNode* clone() const = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
/// Returns a string value depending on the type of the AbstractNode.
|
|
|
|
virtual std::string getValue() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** This specific abstract node represents a script object */
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUObjectAbstractNode : public PUAbstractNode
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
private:
|
2021-12-31 12:12:40 +08:00
|
|
|
hlookup::string_map<std::string> _env;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
|
|
|
std::string name, cls;
|
|
|
|
std::vector<std::string> bases;
|
|
|
|
unsigned int id;
|
|
|
|
bool abstract;
|
|
|
|
PUAbstractNodeList children;
|
|
|
|
PUAbstractNodeList values;
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAbstractNodeList overrides; // For use when processing object inheritance and overriding
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
PUObjectAbstractNode(PUAbstractNode* ptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUObjectAbstractNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAbstractNode* clone() const;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string getValue() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void addVariable(std::string_view name);
|
|
|
|
void setVariable(std::string_view name, std::string_view value);
|
|
|
|
std::pair<bool, std::string> getVariable(std::string_view name) const;
|
|
|
|
const hlookup::string_map<std::string>& getVariables() const;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** This abstract node represents a script property */
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUPropertyAbstractNode : public PUAbstractNode
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string name;
|
|
|
|
unsigned int id;
|
|
|
|
PUAbstractNodeList values;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
PUPropertyAbstractNode(PUAbstractNode* ptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUPropertyAbstractNode();
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAbstractNode* clone() const;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string getValue() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** This is an abstract node which cannot be broken down further */
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUAtomAbstractNode : public PUAbstractNode
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string value;
|
|
|
|
unsigned int id;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAtomAbstractNode(PUAbstractNode* ptr);
|
|
|
|
PUAbstractNode* clone() const;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string getValue() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
void parseNumber() const;
|
|
|
|
};
|
|
|
|
|
2020-10-07 00:15:11 +08:00
|
|
|
class CC_EX_DLL PUParticleSystem3D;
|
|
|
|
class CC_EX_DLL PUScriptCompiler
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
2021-12-31 12:12:40 +08:00
|
|
|
hlookup::string_map<PUAbstractNodeList>::iterator compile(const PUConcreteNodeList& nodes, std::string_view file);
|
2021-12-25 10:04:45 +08:00
|
|
|
// is it excluded?//
|
2021-12-31 12:12:40 +08:00
|
|
|
bool isNameExcluded(std::string_view cls, PUAbstractNode* parent);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
typedef std::unordered_map<std::string, unsigned int> IdMap;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
static PUScriptCompiler* Instance();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void setParticleSystem3D(PUParticleSystem3D* pu);
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
const PUAbstractNodeList* compile(std::string_view file, bool& isFirstCompile);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
void convertToAST(const PUConcreteNodeList& nodes, PUAbstractNodeList& aNodes);
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> env;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
PUScriptCompiler();
|
|
|
|
virtual ~PUScriptCompiler();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void visitList(const PUConcreteNodeList& nodes);
|
|
|
|
void visit(PUConcreteNode* node);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
2021-12-31 12:12:40 +08:00
|
|
|
hlookup::string_map<PUAbstractNodeList> _compiledScripts;
|
2021-12-25 10:04:45 +08:00
|
|
|
PUAbstractNode* _current;
|
|
|
|
PUAbstractNodeList* _nodes;
|
|
|
|
PUParticleSystem3D* _PUParticleSystem3D;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__ssaafsdf__CCScriptCompile__) */
|