| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- //
- // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
- //
- // 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:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // 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.
- //
- #pragma once
- #include <Atomic/Core/Object.h>
- #include "JSBindTypes.h"
- #include "JSBHeader.h"
- #include "JSBModule.h"
- using namespace Atomic;
- namespace ToolCore
- {
- class JSBPackage;
- class JSBFunction;
- class JSBFunctionType;
- class JSBType;
- // chosen function overrides
- class JSBFunctionSignature
- {
- public:
- JSBFunctionSignature(const String& name, const Vector<String>& sig);
- String name_;
- Vector<String> sig_;
- Vector<JSBType*> types_;
- bool Match(JSBFunction* function);
- void Parse() ;
- bool parsed_;
- PODVector<BindingLanguage> associatedBindings_;
- };
- class JSBProperty
- {
- public:
- String name_;
- JSBFunction* getter_;
- JSBFunction* setter_;
- JSBProperty() : getter_(0), setter_(0)
- {
- }
- // returns proper case for property name
- // based on whether the Getter/Setter is all caps
- // GetMyValue -> myValue;
- // GetGUID -> guid
- // URLEnabled -> urlEnabled
- String GetCasePropertyName()
- {
- if (!name_.Length())
- return name_;
- bool allUpper = true;
- // TODO: https://github.com/AtomicGameEngine/AtomicGameEngine/issues/587
- if (name_ == "URLEnabled")
- {
- return "urlEnabled";
- }
- for (unsigned k = 0; k < name_.Length(); k++)
- {
- if (!isupper(name_[k]))
- {
- allUpper = false;
- break;
- }
- }
- if (allUpper)
- {
- return name_.ToLower();
- }
- String name = name_;
- name[0] = tolower(name[0]);
- return name;
- }
- };
- class JSBClass : public Object
- {
- friend class JSClassWriter;
- friend class CSClassWriter;
- ATOMIC_OBJECT(JSBClass, Object)
- public:
- JSBClass(Context* context, JSBModule* module, const String& name, const String& nativeName, bool interface);
- virtual ~JSBClass();
- const String& GetName() const { return name_; }
- const String& GetNativeName() { return nativeName_; }
- JSBClass* GetBaseClass();
- PODVector<JSBClass*>& GetBaseClasses() {return baseClasses_; }
- PODVector<JSBFunction*>& GetFunctions() { return functions_; }
- // Get all functions, including those in base classes
- void GetAllFunctions(PODVector<JSBFunction*>& functions);
- bool IsGeneric() const { return isGeneric_; }
- bool IsAbstract() const { return isAbstract_; }
- bool IsInterface() const { return isInterface_; }
- /// Note that if we at some point want to generate bindings for JSBClass
- /// this override will need to be addressed, as we'll need to know that JSBClass is
- /// itself an object
- bool IsObject() { return isObject_; }
- bool HasProperties() { return hasProperties_; }
- void GetPropertyNames(Vector<String>& names) { names = properties_.Keys(); }
- JSBProperty* GetProperty(const String& name)
- {
- if (!properties_.Contains(name))
- return 0;
- return properties_[name];
- }
- JSBFunction* MatchFunction(JSBFunction* function, bool includeBases = false);
- bool MatchProperty(JSBProperty* property, bool includeBases = false);
- JSBHeader* GetHeader() { return header_; }
- JSBModule* GetModule() { return module_; }
- JSBPackage* GetPackage() { return module_->GetPackage(); }
- const String& GetDocString() const { return docString_; }
- bool IsNumberArray() { return numberArrayElements_ != 0; }
- int GetNumberArrayElements() { return numberArrayElements_;}
- const String& GetArrayElementType() const { return arrayElementType_; }
- JSBFunction* GetConstructor(BindingLanguage bindingLanguage = BINDINGLANGUAGE_ANY );
- const PODVector<JSBClass*>& GetInterfaces() const { return interfaces_; }
- void SetAbstract(bool value = true) { isAbstract_ = value; }
- void SetObject(bool value = true) { isObject_ = value; }
- void SetGeneric(bool value = true) { isGeneric_ = value; }
- void SetHeader(JSBHeader* header) { header_ = header; }
- void SetDocString(const String& value) { docString_ = value; }
- void SetBaseClass(JSBClass* baseClass);
- void SetSkipFunction(const String& name, bool skip = true);
- void AddFunction(JSBFunction* function);
- void AddFunctionOverride(JSBFunctionSignature* override) { overrides_.Push(override); }
- void AddFunctionExclude(JSBFunctionSignature* exclude) { excludes_.Push(exclude); }
- void AddPropertyFunction(JSBFunction* function);
- void AddInterface(JSBClass* klass) { interfaces_.Push(klass); }
- void AddTypeScriptDecl(const String& decl) { typeScriptDecls_.Push(decl); }
- unsigned GetNumTypeScriptDecl() { return typeScriptDecls_.Size(); }
- const String& GetTypeScriptDecl(unsigned idx) { return typeScriptDecls_[idx]; }
- void AddHaxeDecl(const String& decl) { haxeDecls_.Push(decl); }
- unsigned GetNumHaxeDecl() { return haxeDecls_.Size(); }
- const String& GetHaxeDecl(unsigned idx) { return haxeDecls_[idx]; }
- /// CSharp bindings can add NET interfaces to native classes, for example IDisposable, IEquatable, etc
- void AddCSharpInterface(const String& interface) { csharpInterfacesDecls_.Push(interface); }
- /// Gets the C# interfaces implemented by this class
- const StringVector& GetCSharpInterfaces() const { return csharpInterfacesDecls_; }
- void Preprocess();
- void Process();
- void PostProcess();
- void Dump();
- private:
- void MergeInterface(JSBClass* interface);
- void RecursiveAddBaseClass(PODVector<JSBClass *> &baseClasses);
- String name_;
- String nativeName_;
- SharedPtr<JSBHeader> header_;
- SharedPtr<JSBModule> module_;
- PODVector<JSBFunction*> functions_;
- PODVector<JSBClass*> baseClasses_;
- PODVector<JSBClass*> interfaces_;
- PODVector<JSBFunctionSignature*> overrides_;
- PODVector<JSBFunctionSignature*> excludes_;
- Vector<String> typeScriptDecls_;
- Vector<String> haxeDecls_;
- Vector<String> csharpInterfacesDecls_;
- bool isAbstract_;
- bool isObject_;
- bool isGeneric_;
- bool isInterface_;
- String docString_;
- // Vector3, Color, etc are marshalled via arrays
- int numberArrayElements_;
- String arrayElementType_;
- bool hasProperties_;
- HashMap<String, JSBProperty*> properties_;
- };
- }
|