| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #pragma once
- #include <Atomic/Core/Object.h>
- #include "JSBHeader.h"
- #include "JSBModule.h"
- using namespace Atomic;
- namespace ToolCore
- {
- class JSBPackage;
- class JSBFunction;
- 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_;
- };
- 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
- String GetCasePropertyName()
- {
- if (!name_.Length())
- return name_;
- bool allUpper = true;
- 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 JSBClassWriter;
- OBJECT(JSBClass)
- public:
- JSBClass(Context* context, JSBModule* module, const String& name, const String& nativeName);
- virtual ~JSBClass();
- const String& GetName() { return name_; }
- const String& GetNativeName() { return nativeName_; }
- JSBClass* GetBaseClass();
- PODVector<JSBClass*>& GetBaseClasses() {return baseClasses_; }
- PODVector<JSBFunction*>& GetFunctions() { return functions_; }
- bool IsAbstract() { return isAbstract_; }
- /// 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];
- }
- JSBHeader* GetHeader() { return header_; }
- JSBModule* GetModule() { return module_; }
- JSBPackage* GetPackage() { return module_->GetPackage(); }
- bool IsNumberArray() { return numberArrayElements_ != 0; }
- int GetNumberArrayElements() { return numberArrayElements_;}
- const String& GetArrayElementType() const { return arrayElementType_; }
- JSBFunction* GetConstructor();
- void SetAbstract(bool value = true) { isAbstract_ = value; }
- void SetObject(bool value = true) { isObject_ = value; }
- void SetHeader(JSBHeader* header) { header_ = header; }
- 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 AddTypeScriptDecl(const String& decl) { typeScriptDecls_.Push(decl); }
- unsigned GetNumTypeScriptDecl() { return typeScriptDecls_.Size(); }
- const String& GetTypeScriptDecl(unsigned idx) { return typeScriptDecls_[idx]; }
- void Preprocess();
- void Process();
- void PostProcess();
- void Dump();
- private:
- void RecursiveAddBaseClass(PODVector<JSBClass *> &baseClasses);
- String name_;
- String nativeName_;
- SharedPtr<JSBHeader> header_;
- SharedPtr<JSBModule> module_;
- PODVector<JSBFunction*> functions_;
- PODVector<JSBClass*> baseClasses_;
- PODVector<JSBFunctionSignature*> overrides_;
- PODVector<JSBFunctionSignature*> excludes_;
- Vector<String> typeScriptDecls_;
- bool isAbstract_;
- bool isObject_;
- // Vector3, Color, etc are marshalled via arrays
- int numberArrayElements_;
- String arrayElementType_;
- bool hasProperties_;
- HashMap<String, JSBProperty*> properties_;
- };
- }
|