| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- //
- // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
- // LICENSE: Atomic Game Engine Editor and Tools EULA
- // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
- // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
- //
- #include <Atomic/IO/FileSystem.h>
- #include "../JSBind.h"
- #include "../JSBPackage.h"
- #include "../JSBModule.h"
- #include "../JSBEnum.h"
- #include "../JSBClass.h"
- #include "../JSBFunction.h"
- #include "CSBClassWriter.h"
- #include "CSBModuleWriter.h"
- namespace ToolCore
- {
- CSBModuleWriter::CSBModuleWriter(JSBModule *module) : module_(module)
- {
- }
- void CSBModuleWriter::WriteIncludes(String& source)
- {
- Vector<String>& includes = module_->includes_;
- for (unsigned i = 0; i < includes.Size(); i++)
- {
- if (includes[i].StartsWith("<"))
- source.AppendWithFormat("#include %s\n", includes[i].CString());
- else
- source.AppendWithFormat("#include \"%s\"\n", includes[i].CString());
- }
- Vector<JSBHeader*> allheaders;
- HashMap<StringHash, SharedPtr<JSBEnum> >::Iterator eitr = module_->enums_.Begin();
- while (eitr != module_->enums_.End())
- {
- allheaders.Push(eitr->second_->GetHeader());
- eitr++;
- }
- HashMap<StringHash, SharedPtr<JSBClass> >::Iterator citr = module_->classes_.Begin();
- while (citr != module_->classes_.End())
- {
- allheaders.Push(citr->second_->GetHeader());
- citr++;
- }
- Vector<JSBHeader*> included;
- for (unsigned i = 0; i < allheaders.Size(); i++)
- {
- JSBHeader* header = allheaders.At(i);
- if (included.Contains(header))
- continue;
- String headerPath = GetPath(header->GetFilePath());
- String headerfile = GetFileNameAndExtension(header->GetFilePath());
- JSBind* jsbind = header->GetSubsystem<JSBind>();
- headerPath.Replace(jsbind->GetSourceRootFolder() + "Source/", "");
- source.AppendWithFormat("#include <%s%s>\n", headerPath.CString(), headerfile.CString());
- included.Push(header);
- }
- }
- void CSBModuleWriter::GenerateSource(String& sourceOut)
- {
- source_ = "// This file was autogenerated by JSBind, changes will be lost\n";
- source_ += "#ifdef ATOMIC_PLATFORM_WINDOWS\n";
- source_ += "#pragma warning(disable: 4244) // possible loss of data\n";
- source_ += "#endif\n";
- if (module_->Requires("3D"))
- {
- source_ += "#ifdef ATOMIC_3D\n";
- }
- source_ += "#include <Duktape/duktape.h>\n";
- source_ += "#include <AtomicJS/Javascript/JSVM.h>\n";
- source_ += "#include <AtomicJS/Javascript/JSAPI.h>\n";
- WriteIncludes(source_);
- String ns = module_->GetPackage()->GetNamespace();
- if (ns != "Atomic")
- {
- source_ += "\n\nusing namespace " + ns + ";\n\n";
- }
- source_ += "\n\nnamespace Atomic\n{\n \n";
- source_ += "// Begin Class Declarations\n";
- source_ += "// End Class Declarations\n\n";
- source_ += "// Begin Classes\n";
- Vector<SharedPtr<JSBClass>> classes = module_->classes_.Values();
- for (unsigned i = 0; i < classes.Size(); i++)
- {
- CSBClassWriter clsWriter(classes[i]);
- clsWriter.GenerateSource(source_);
- }
- source_ += "// End Classes\n\n";
- // end Atomic namespace
- source_ += "\n}\n";
- if (module_->Requires("3D"))
- {
- source_ += "#endif //ATOMIC_3D\n";
- }
- sourceOut = source_;
- }
- }
|