[DevTools] Generate all files in inspector_protocol.
BUG=637032
Review-Url: https://codereview.chromium.org/2238423002
Cr-Original-Commit-Position: refs/heads/master@{#411913}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0001c863a0d8b16183a8289f00f77089a7511b1e
diff --git a/Allocator.h b/Allocator_h.template
similarity index 100%
rename from Allocator.h
rename to Allocator_h.template
diff --git a/Array.h b/Array_h.template
similarity index 92%
rename from Array.h
rename to Array_h.template
index acdf4d2..40abb2d 100644
--- a/Array.h
+++ b/Array_h.template
@@ -5,11 +5,11 @@
#ifndef Array_h
#define Array_h
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/ValueConversions.h"
-#include "platform/inspector_protocol/Values.h"
+//#include "ErrorSupport.h"
+//#include "Platform.h"
+//#include "String16.h"
+//#include "ValueConversions.h"
+//#include "Values.h"
#include <vector>
diff --git a/BackendCallback.h b/BackendCallback_h.template
similarity index 75%
rename from BackendCallback.h
rename to BackendCallback_h.template
index 870fbb5..f301ede 100644
--- a/BackendCallback.h
+++ b/BackendCallback_h.template
@@ -5,13 +5,14 @@
#ifndef BackendCallback_h
#define BackendCallback_h
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/Platform.h"
+//#include "ErrorSupport.h"
+//#include "Platform.h"
+#include "{{export_macro_include}}"
namespace blink {
namespace protocol {
-class PLATFORM_EXPORT BackendCallback {
+class {{export_macro}} BackendCallback {
public:
virtual ~BackendCallback() { }
virtual void sendFailure(const ErrorString&) = 0;
diff --git a/CodeGenerator.py b/CodeGenerator.py
index 5743e16..128dde3 100644
--- a/CodeGenerator.py
+++ b/CodeGenerator.py
@@ -106,13 +106,34 @@
if not exported_package:
raise Exception("Config is missing export.package")
+ lib = False
+ if "lib" in config:
+ lib = True
+ lib_dirname = config["lib"]["output"]
+ if not lib_dirname:
+ raise Exception("Config is missing lib.output")
+ lib_dirname = os.path.join(output_base, lib_dirname)
+ lib_string16_include = config["lib"]["string16_impl_header_path"]
+ if not lib_string16_include:
+ raise Exception("Config is missing lib.string16_impl_header_path")
+ lib_platform_include = config["lib"]["platform_impl_header_path"]
+ if not lib_platform_include:
+ raise Exception("Config is missing lib.platform_impl_header_path")
+
string_type = config["string"]["class_name"]
if not string_type:
raise Exception("Config is missing string.class_name")
- export_macro = config["export_macro"]
+ export_macro = config["class_export"]["macro"]
if not export_macro:
- raise Exception("Config is missing export_macro")
+ raise Exception("Config is missing class_export.macro")
+ export_macro_include = config["class_export"]["header_path"]
+ if not export_macro_include:
+ raise Exception("Config is missing class_export.header_path")
+
+ lib_package = config["lib_package"]
+ if not lib_package:
+ raise Exception("Config is missing lib_package")
except Exception:
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
exc = sys.exc_info()[1]
@@ -404,12 +425,6 @@
return False
-def generate_with_context(template_context, template, file_name):
- out_file = output_file(file_name)
- out_file.write(template.render(template_context))
- out_file.close()
-
-
def generate(domain_object, template, file_name):
template_context = {
"domain": domain_object,
@@ -418,13 +433,17 @@
"type_definition": type_definition,
"has_disable": has_disable,
"export_macro": export_macro,
- "output_package": output_package
+ "export_macro_include": export_macro_include,
+ "output_package": output_package,
+ "lib_package": lib_package
}
if exporting:
template_context["exported_package"] = exported_package
if importing:
template_context["imported_package"] = imported_package
- generate_with_context(template_context, template, file_name)
+ out_file = output_file(file_name)
+ out_file.write(template.render(template_context))
+ out_file.close()
def read_protocol_file(file_name, all_domains):
@@ -438,6 +457,63 @@
return domains
+def generate_lib():
+ template_context = {
+ "string16_impl_h_include": lib_string16_include,
+ "platform_impl_h_include": lib_platform_include,
+ "lib_package": lib_package,
+ "export_macro": export_macro,
+ "export_macro_include": export_macro_include
+ }
+
+ def generate_file(file_name, template_files):
+ out_file = output_file(file_name)
+ for template_file in template_files:
+ template = jinja_env.get_template("/" + template_file)
+ out_file.write(template.render(template_context))
+ out_file.write("\n\n")
+ out_file.close()
+
+ # Note these should be sorted in the right order.
+ # TODO(dgozman): sort them programmatically based on commented includes.
+ lib_h_templates = [
+ "Allocator_h.template",
+ "Platform_h.template",
+ "Collections_h.template",
+ "String16_h.template",
+
+ "ErrorSupport_h.template",
+ "Values_h.template",
+ "Object_h.template",
+ "ValueConversions_h.template",
+ "Maybe_h.template",
+ "Array_h.template",
+
+ "FrontendChannel_h.template",
+ "BackendCallback_h.template",
+ "DispatcherBase_h.template",
+
+ "Parser_h.template",
+ ]
+
+ lib_cpp_templates = [
+ "InspectorProtocol_cpp.template",
+
+ "String16_cpp.template",
+
+ "ErrorSupport_cpp.template",
+ "Values_cpp.template",
+ "Object_cpp.template",
+
+ "DispatcherBase_cpp.template",
+
+ "Parser_cpp.template",
+ ]
+
+ generate_file(os.path.join(lib_dirname, "InspectorProtocol.h"), lib_h_templates)
+ generate_file(os.path.join(lib_dirname, "InspectorProtocol.cpp"), lib_cpp_templates)
+
+
json_api = {"domains": []}
generate_domains = read_protocol_file(protocol_file, json_api)
imported_domains = read_protocol_file(imported_file, json_api) if importing else []
@@ -467,3 +543,6 @@
generate(domain, exported_template, os.path.join(exported_dirname, class_name + ".h"))
if domain["domain"] in imported_domains and domain["has_exports"]:
generate(domain, imported_template, os.path.join(output_dirname, class_name + ".h"))
+
+if lib:
+ generate_lib()
diff --git a/Collections.h b/Collections_h.template
similarity index 100%
rename from Collections.h
rename to Collections_h.template
diff --git a/DispatcherBase.cpp b/DispatcherBase_cpp.template
similarity index 96%
rename from DispatcherBase.cpp
rename to DispatcherBase_cpp.template
index 86ac058..2f842e7 100644
--- a/DispatcherBase.cpp
+++ b/DispatcherBase_cpp.template
@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/DispatcherBase.h"
-
-#include "platform/inspector_protocol/FrontendChannel.h"
-#include "platform/inspector_protocol/Parser.h"
-
namespace blink {
namespace protocol {
diff --git a/DispatcherBase.h b/DispatcherBase_h.template
similarity index 83%
rename from DispatcherBase.h
rename to DispatcherBase_h.template
index 6e8ae28..76b7958 100644
--- a/DispatcherBase.h
+++ b/DispatcherBase_h.template
@@ -5,12 +5,13 @@
#ifndef DispatcherBase_h
#define DispatcherBase_h
-#include "platform/inspector_protocol/BackendCallback.h"
-#include "platform/inspector_protocol/Collections.h"
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/Values.h"
+//#include "BackendCallback.h"
+//#include "Collections.h"
+//#include "ErrorSupport.h"
+//#include "Platform.h"
+//#include "String16.h"
+//#include "Values.h"
+#include "{{export_macro_include}}"
namespace blink {
namespace protocol {
@@ -18,11 +19,11 @@
class FrontendChannel;
class WeakPtr;
-class PLATFORM_EXPORT DispatcherBase {
+class {{export_macro}} DispatcherBase {
PROTOCOL_DISALLOW_COPY(DispatcherBase);
public:
static const char kInvalidRequest[];
- class PLATFORM_EXPORT WeakPtr {
+ class {{export_macro}} WeakPtr {
public:
explicit WeakPtr(DispatcherBase*);
~WeakPtr();
@@ -33,7 +34,7 @@
DispatcherBase* m_dispatcher;
};
- class PLATFORM_EXPORT Callback : public protocol::BackendCallback {
+ class {{export_macro}} Callback : public protocol::BackendCallback {
public:
Callback(std::unique_ptr<WeakPtr> backendImpl, int callId);
virtual ~Callback();
@@ -77,7 +78,7 @@
protocol::HashSet<WeakPtr*> m_weakPtrs;
};
-class PLATFORM_EXPORT UberDispatcher {
+class {{export_macro}} UberDispatcher {
PROTOCOL_DISALLOW_COPY(UberDispatcher);
public:
explicit UberDispatcher(FrontendChannel*);
diff --git a/ErrorSupport.cpp b/ErrorSupport_cpp.template
similarity index 92%
rename from ErrorSupport.cpp
rename to ErrorSupport_cpp.template
index 0ad89ad..695cb58 100644
--- a/ErrorSupport.cpp
+++ b/ErrorSupport_cpp.template
@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/ErrorSupport.h"
-
-#include "platform/inspector_protocol/String16.h"
-
namespace blink {
namespace protocol {
diff --git a/ErrorSupport.h b/ErrorSupport_h.template
similarity index 84%
rename from ErrorSupport.h
rename to ErrorSupport_h.template
index 56ac442..50557c0 100644
--- a/ErrorSupport.h
+++ b/ErrorSupport_h.template
@@ -5,8 +5,9 @@
#ifndef ErrorSupport_h
#define ErrorSupport_h
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
+//#include "Platform.h"
+//#include "String16.h"
+#include "{{export_macro_include}}"
#include <vector>
@@ -15,7 +16,7 @@
using ErrorString = String16;
-class PLATFORM_EXPORT ErrorSupport {
+class {{export_macro}} ErrorSupport {
public:
ErrorSupport();
ErrorSupport(String16* errorString);
diff --git a/Exported_h.template b/Exported_h.template
index 5cfabc5..116a441 100644
--- a/Exported_h.template
+++ b/Exported_h.template
@@ -7,12 +7,8 @@
#ifndef protocol_{{domain.domain}}_api_h
#define protocol_{{domain.domain}}_api_h
-{% if export_macro == "PLATFORM_EXPORT" %}
-#include "platform/inspector_protocol/Platform.h"
-{% else %}
-#include "core/CoreExport.h"
-{% endif %}
-#include "platform/inspector_protocol/String16.h"
+#include "{{export_macro_include}}"
+#include "{{lib_package}}/InspectorProtocol.h"
namespace blink {
namespace protocol {
diff --git a/FrontendChannel.h b/FrontendChannel_h.template
similarity index 85%
rename from FrontendChannel.h
rename to FrontendChannel_h.template
index ee81e95..0b7025f 100644
--- a/FrontendChannel.h
+++ b/FrontendChannel_h.template
@@ -5,12 +5,13 @@
#ifndef FrontendChannel_h
#define FrontendChannel_h
-#include "platform/inspector_protocol/Values.h"
+//#include "String16.h"
+#include "{{export_macro_include}}"
namespace blink {
namespace protocol {
-class PLATFORM_EXPORT FrontendChannel {
+class {{export_macro}} FrontendChannel {
public:
virtual ~FrontendChannel() { }
virtual void sendProtocolResponse(int callId, const String16& message) = 0;
diff --git a/Imported_h.template b/Imported_h.template
index 3bfaef3..2dd30bc 100644
--- a/Imported_h.template
+++ b/Imported_h.template
@@ -7,9 +7,7 @@
#ifndef protocol_{{domain.domain}}_imported_h
#define protocol_{{domain.domain}}_imported_h
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/ValueConversions.h"
-#include "platform/inspector_protocol/Values.h"
+#include "{{lib_package}}/InspectorProtocol.h"
#include "{{imported_package}}/{{domain.domain}}.h"
namespace blink {
diff --git a/InspectorProtocol_cpp.template b/InspectorProtocol_cpp.template
new file mode 100644
index 0000000..153dbf0
--- /dev/null
+++ b/InspectorProtocol_cpp.template
@@ -0,0 +1,5 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "{{lib_package}}/InspectorProtocol.h"
diff --git a/Maybe.h b/Maybe_h.template
similarity index 94%
rename from Maybe.h
rename to Maybe_h.template
index 560e7da..e15ac07 100644
--- a/Maybe.h
+++ b/Maybe_h.template
@@ -5,10 +5,8 @@
#ifndef Maybe_h
#define Maybe_h
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
-
-#include <memory>
+//#include "Platform.h"
+//#include "String16.h"
namespace blink {
namespace protocol {
diff --git a/Object.cpp b/Object_cpp.template
similarity index 94%
rename from Object.cpp
rename to Object_cpp.template
index 7bb007d..4480d85 100644
--- a/Object.cpp
+++ b/Object_cpp.template
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/Object.h"
-
namespace blink {
namespace protocol {
diff --git a/Object.h b/Object_h.template
similarity index 78%
rename from Object.h
rename to Object_h.template
index 22506c0..8b3e3ec 100644
--- a/Object.h
+++ b/Object_h.template
@@ -5,14 +5,15 @@
#ifndef Object_h
#define Object_h
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/Values.h"
+//#include "ErrorSupport.h"
+//#include "Platform.h"
+//#include "Values.h"
+#include "{{export_macro_include}}"
namespace blink {
namespace protocol {
-class PLATFORM_EXPORT Object {
+class {{export_macro}} Object {
public:
static std::unique_ptr<Object> parse(protocol::Value*, ErrorSupport*);
~Object();
diff --git a/ParserTest.cpp b/ParserTest.cpp
index 1a8f442..40c6af7 100644
--- a/ParserTest.cpp
+++ b/ParserTest.cpp
@@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/Parser.h"
-
-#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/Values.h"
+#include "platform/inspector_protocol/InspectorProtocol.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
diff --git a/Parser.cpp b/Parser_cpp.template
similarity index 98%
rename from Parser.cpp
rename to Parser_cpp.template
index 1a8a10e..34d8ff0 100644
--- a/Parser.cpp
+++ b/Parser_cpp.template
@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/Parser.h"
-
-#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/Values.h"
-
namespace blink {
namespace protocol {
diff --git a/Parser.h b/Parser_h.template
similarity index 65%
rename from Parser.h
rename to Parser_h.template
index c6f700e..eab025f 100644
--- a/Parser.h
+++ b/Parser_h.template
@@ -5,15 +5,16 @@
#ifndef Parser_h
#define Parser_h
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
+//#include "Platform.h"
+//#include "String16.h"
+#include "{{export_macro_include}}"
namespace blink {
namespace protocol {
class Value;
-PLATFORM_EXPORT std::unique_ptr<Value> parseJSON(const String16& json);
+{{export_macro}} std::unique_ptr<Value> parseJSON(const String16& json);
} // namespace platform
} // namespace blink
diff --git a/PlatformSTL.h b/PlatformSTL.h
deleted file mode 100644
index 33ca199..0000000
--- a/PlatformSTL.h
+++ /dev/null
@@ -1,292 +0,0 @@
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef PlatformSTL_h
-#define PlatformSTL_h
-
-#include <memory>
-
-#define PLATFORM_EXPORT
-#ifndef CHECK
-#define CHECK(condition) ((void) 0)
-#endif
-#define DCHECK(condition) ((void) 0)
-#define NOTREACHED()
-#define DCHECK_EQ(i, j) DCHECK(i == j)
-#define DCHECK_GE(i, j) DCHECK(i >= j)
-#define DCHECK_LT(i, j) DCHECK(i < j)
-#define DCHECK_GT(i, j) DCHECK(i > j)
-template <typename T>
-inline void USE(T) { }
-
-#define DEFINE_STATIC_LOCAL(type, name, arguments) \
- static type name;
-
-#if defined(__APPLE__) && !defined(_LIBCPP_VERSION)
-
-namespace std {
-
-template <typename T1, typename T2>
-struct is_convertible {
-private:
- struct True_ {
- char x[2];
- };
- struct False_ {
- };
-
- static True_ helper(T2 const &);
- static False_ helper(...);
-
-public:
- static bool const value = (
- sizeof(True_) == sizeof(is_convertible::helper(T1()))
- );
-};
-
-template <bool, class T = void>
-struct enable_if {
-};
-
-template <class T>
-struct enable_if<true, T> {
- typedef T type;
-};
-
-template<class T>
-struct remove_extent {
- typedef T type;
-};
-
-template<class T>
-struct remove_extent<T[]> {
- typedef T type;
-};
-
-template<class T, std::size_t N>
-struct remove_extent<T[N]> {
- typedef T type;
-};
-
-typedef decltype(nullptr) nullptr_t;
-
-template<class T, T v>
-struct integral_constant {
- static constexpr T value = v;
- typedef T value_type;
- typedef integral_constant type;
- constexpr operator value_type() const noexcept { return value; }
- constexpr value_type operator()() const noexcept { return value; }
-};
-
-typedef integral_constant<bool, true> true_type;
-typedef integral_constant<bool, false> false_type;
-
-template<class T>
-struct is_array : false_type {};
-
-template<class T>
-struct is_array<T[]> : true_type {};
-
-template<class T, std::size_t N>
-struct is_array<T[N]> : true_type {};
-
-template <typename T>
-struct OwnedPtrDeleter {
- static void deletePtr(T* ptr)
- {
- static_assert(sizeof(T) > 0, "type must be complete");
- delete ptr;
- }
-};
-
-template <typename T>
-struct OwnedPtrDeleter<T[]> {
- static void deletePtr(T* ptr)
- {
- static_assert(sizeof(T) > 0, "type must be complete");
- delete[] ptr;
- }
-};
-
-template <class T, int n>
-struct OwnedPtrDeleter<T[n]> {
- static_assert(sizeof(T) < 0, "do not use array with size as type");
-};
-
-template <typename T> class unique_ptr {
-public:
- typedef typename remove_extent<T>::type ValueType;
- typedef ValueType* PtrType;
-
- unique_ptr() : m_ptr(nullptr) {}
- unique_ptr(std::nullptr_t) : m_ptr(nullptr) {}
- unique_ptr(const unique_ptr&);
- unique_ptr(unique_ptr&&);
- template <typename U, typename = typename enable_if<is_convertible<U*, T*>::value>::type> unique_ptr(unique_ptr<U>&&);
-
- ~unique_ptr()
- {
- OwnedPtrDeleter<T>::deletePtr(m_ptr);
- m_ptr = nullptr;
- }
-
- PtrType get() const { return m_ptr; }
-
- void reset(PtrType = nullptr);
- PtrType release()
- {
- return this->internalRelease();
- }
-
- ValueType& operator*() const { DCHECK(m_ptr); return *m_ptr; }
- PtrType operator->() const { DCHECK(m_ptr); return m_ptr; }
-
- ValueType& operator[](std::ptrdiff_t i) const;
-
- bool operator!() const { return !m_ptr; }
- explicit operator bool() const { return m_ptr; }
-
- unique_ptr& operator=(std::nullptr_t) { reset(); return *this; }
-
- unique_ptr& operator=(const unique_ptr&);
- unique_ptr& operator=(unique_ptr&&);
- template <typename U> unique_ptr& operator=(unique_ptr<U>&&);
-
- void swap(unique_ptr& o) { std::swap(m_ptr, o.m_ptr); }
-
- static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
-
- explicit unique_ptr(PtrType ptr) : m_ptr(ptr) {}
-
-private:
- PtrType internalRelease() const
- {
- PtrType ptr = m_ptr;
- m_ptr = nullptr;
- return ptr;
- }
-
- // We should never have two unique_ptrs for the same underlying object
- // (otherwise we'll get double-destruction), so these equality operators
- // should never be needed.
- template <typename U> bool operator==(const unique_ptr<U>&) const
- {
- static_assert(!sizeof(U*), "unique_ptrs should never be equal");
- return false;
- }
- template <typename U> bool operator!=(const unique_ptr<U>&) const
- {
- static_assert(!sizeof(U*), "unique_ptrs should never be equal");
- return false;
- }
-
- mutable PtrType m_ptr;
-};
-
-
-template <typename T> inline void unique_ptr<T>::reset(PtrType ptr)
-{
- PtrType p = m_ptr;
- m_ptr = ptr;
- DCHECK(!p || m_ptr != p);
- OwnedPtrDeleter<T>::deletePtr(p);
-}
-
-template <typename T> inline typename unique_ptr<T>::ValueType& unique_ptr<T>::operator[](std::ptrdiff_t i) const
-{
- static_assert(is_array<T>::value, "elements access is possible for arrays only");
- DCHECK(m_ptr);
- DCHECK_GE(i, 0);
- return m_ptr[i];
-}
-
-template <typename T> inline unique_ptr<T>::unique_ptr(const unique_ptr<T>& o)
- : m_ptr(o.internalRelease())
-{
-}
-
-template <typename T> inline unique_ptr<T>::unique_ptr(unique_ptr<T>&& o)
- : m_ptr(o.internalRelease())
-{
-}
-
-template <typename T>
-template <typename U, typename> inline unique_ptr<T>::unique_ptr(unique_ptr<U>&& o)
- : m_ptr(o.release())
-{
- static_assert(!is_array<T>::value, "pointers to array must never be converted");
-}
-
-template <typename T> inline unique_ptr<T>& unique_ptr<T>::operator=(const unique_ptr<T>& o)
-{
- reset(o.internalRelease());
- return *this;
-}
-
-template <typename T> inline unique_ptr<T>& unique_ptr<T>::operator=(unique_ptr<T>&& o)
-{
- reset(o.internalRelease());
- return *this;
-}
-
-template <typename T>
-template <typename U> inline unique_ptr<T>& unique_ptr<T>::operator=(unique_ptr<U>&& o)
-{
- static_assert(!is_array<T>::value, "pointers to array must never be converted");
- PtrType ptr = m_ptr;
- m_ptr = o.release();
- DCHECK(!ptr || m_ptr != ptr);
- OwnedPtrDeleter<T>::deletePtr(ptr);
-
- return *this;
-}
-
-template <typename T> inline void swap(unique_ptr<T>& a, unique_ptr<T>& b)
-{
- a.swap(b);
-}
-
-template <typename T, typename U> inline bool operator==(const unique_ptr<T>& a, U* b)
-{
- return a.get() == b;
-}
-
-template <typename T, typename U> inline bool operator==(T* a, const unique_ptr<U>& b)
-{
- return a == b.get();
-}
-
-template <typename T, typename U> inline bool operator!=(const unique_ptr<T>& a, U* b)
-{
- return a.get() != b;
-}
-
-template <typename T, typename U> inline bool operator!=(T* a, const unique_ptr<U>& b)
-{
- return a != b.get();
-}
-
-template <typename T> inline typename unique_ptr<T>::PtrType getPtr(const unique_ptr<T>& p)
-{
- return p.get();
-}
-
-template <typename T>
-unique_ptr<T> move(unique_ptr<T>& ptr)
-{
- return unique_ptr<T>(ptr.release());
-}
-
-}
-
-#endif // defined(__APPLE__) && !defined(_LIBCPP_VERSION)
-
-template <typename T>
-std::unique_ptr<T> wrapUnique(T* ptr)
-{
- return std::unique_ptr<T>(ptr);
-}
-
-#endif // PlatformSTL_h
diff --git a/PlatformWTF.h b/PlatformWTF.h
deleted file mode 100644
index 3cd659e..0000000
--- a/PlatformWTF.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef PlatformWTF_h
-#define PlatformWTF_h
-
-#include "platform/PlatformExport.h"
-#include "wtf/Assertions.h"
-#include "wtf/PtrUtil.h"
-
-#include <memory>
-
-#endif // PlatformWTF_h
diff --git a/Platform.h b/Platform_h.template
similarity index 60%
rename from Platform.h
rename to Platform_h.template
index 76ba930..f09f192 100644
--- a/Platform.h
+++ b/Platform_h.template
@@ -5,10 +5,6 @@
#ifndef protocol_Platform_h
#define protocol_Platform_h
-#if V8_INSPECTOR_USE_STL
-#include "platform/inspector_protocol/PlatformSTL.h"
-#else
-#include "platform/inspector_protocol/PlatformWTF.h"
-#endif // V8_INSPECTOR_USE_STL
+#include "{{platform_impl_h_include}}"
#endif // !defined(protocol_Platform_h)
diff --git a/String16STL.cpp b/String16STL.cpp
deleted file mode 100644
index 87d6b1c..0000000
--- a/String16STL.cpp
+++ /dev/null
@@ -1,405 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "platform/inspector_protocol/String16.h"
-
-#include <algorithm>
-#include <cctype>
-#include <cstdio>
-#include <locale>
-
-namespace blink {
-namespace protocol {
-
-const UChar replacementCharacter = 0xFFFD;
-using UChar32 = uint32_t;
-
-inline int inlineUTF8SequenceLengthNonASCII(char b0)
-{
- if ((b0 & 0xC0) != 0xC0)
- return 0;
- if ((b0 & 0xE0) == 0xC0)
- return 2;
- if ((b0 & 0xF0) == 0xE0)
- return 3;
- if ((b0 & 0xF8) == 0xF0)
- return 4;
- return 0;
-}
-
-inline int inlineUTF8SequenceLength(char b0)
-{
- return String16::isASCII(b0) ? 1 : inlineUTF8SequenceLengthNonASCII(b0);
-}
-
-// Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
-// into the first byte, depending on how many bytes follow. There are
-// as many entries in this table as there are UTF-8 sequence types.
-// (I.e., one byte sequence, two byte... etc.). Remember that sequences
-// for *legal* UTF-8 will be 4 or fewer bytes total.
-static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-
-typedef enum {
- conversionOK, // conversion successful
- sourceExhausted, // partial character in source, but hit end
- targetExhausted, // insuff. room in target for conversion
- sourceIllegal // source sequence is illegal/malformed
-} ConversionResult;
-
-ConversionResult convertUTF16ToUTF8(
- const UChar** sourceStart, const UChar* sourceEnd,
- char** targetStart, char* targetEnd, bool strict)
-{
- ConversionResult result = conversionOK;
- const UChar* source = *sourceStart;
- char* target = *targetStart;
- while (source < sourceEnd) {
- UChar32 ch;
- unsigned short bytesToWrite = 0;
- const UChar32 byteMask = 0xBF;
- const UChar32 byteMark = 0x80;
- const UChar* oldSource = source; // In case we have to back up because of target overflow.
- ch = static_cast<unsigned short>(*source++);
- // If we have a surrogate pair, convert to UChar32 first.
- if (ch >= 0xD800 && ch <= 0xDBFF) {
- // If the 16 bits following the high surrogate are in the source buffer...
- if (source < sourceEnd) {
- UChar32 ch2 = static_cast<unsigned short>(*source);
- // If it's a low surrogate, convert to UChar32.
- if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
- ch = ((ch - 0xD800) << 10) + (ch2 - 0xDC00) + 0x0010000;
- ++source;
- } else if (strict) { // it's an unpaired high surrogate
- --source; // return to the illegal value itself
- result = sourceIllegal;
- break;
- }
- } else { // We don't have the 16 bits following the high surrogate.
- --source; // return to the high surrogate
- result = sourceExhausted;
- break;
- }
- } else if (strict) {
- // UTF-16 surrogate values are illegal in UTF-32
- if (ch >= 0xDC00 && ch <= 0xDFFF) {
- --source; // return to the illegal value itself
- result = sourceIllegal;
- break;
- }
- }
- // Figure out how many bytes the result will require
- if (ch < (UChar32)0x80) {
- bytesToWrite = 1;
- } else if (ch < (UChar32)0x800) {
- bytesToWrite = 2;
- } else if (ch < (UChar32)0x10000) {
- bytesToWrite = 3;
- } else if (ch < (UChar32)0x110000) {
- bytesToWrite = 4;
- } else {
- bytesToWrite = 3;
- ch = replacementCharacter;
- }
-
- target += bytesToWrite;
- if (target > targetEnd) {
- source = oldSource; // Back up source pointer!
- target -= bytesToWrite;
- result = targetExhausted;
- break;
- }
- switch (bytesToWrite) { // note: everything falls through.
- case 4:
- *--target = (char)((ch | byteMark) & byteMask);
- ch >>= 6;
- case 3:
- *--target = (char)((ch | byteMark) & byteMask);
- ch >>= 6;
- case 2:
- *--target = (char)((ch | byteMark) & byteMask);
- ch >>= 6;
- case 1:
- *--target = (char)(ch | firstByteMark[bytesToWrite]);
- }
- target += bytesToWrite;
- }
- *sourceStart = source;
- *targetStart = target;
- return result;
-}
-
-/**
- * Is this code point a BMP code point (U+0000..U+ffff)?
- * @param c 32-bit code point
- * @return TRUE or FALSE
- * @stable ICU 2.8
- */
-#define U_IS_BMP(c) ((uint32_t)(c) <= 0xffff)
-
-/**
- * Is this code point a supplementary code point (U+10000..U+10ffff)?
- * @param c 32-bit code point
- * @return TRUE or FALSE
- * @stable ICU 2.8
- */
-#define U_IS_SUPPLEMENTARY(c) ((uint32_t)((c) - 0x10000) <= 0xfffff)
-
-/**
- * Is this code point a surrogate (U+d800..U+dfff)?
- * @param c 32-bit code point
- * @return TRUE or FALSE
- * @stable ICU 2.4
- */
-#define U_IS_SURROGATE(c) (((c) & 0xfffff800) == 0xd800)
-
-/**
- * Get the lead surrogate (0xd800..0xdbff) for a
- * supplementary code point (0x10000..0x10ffff).
- * @param supplementary 32-bit code point (U+10000..U+10ffff)
- * @return lead surrogate (U+d800..U+dbff) for supplementary
- * @stable ICU 2.4
- */
-#define U16_LEAD(supplementary) (UChar)(((supplementary) >> 10) + 0xd7c0)
-
-/**
- * Get the trail surrogate (0xdc00..0xdfff) for a
- * supplementary code point (0x10000..0x10ffff).
- * @param supplementary 32-bit code point (U+10000..U+10ffff)
- * @return trail surrogate (U+dc00..U+dfff) for supplementary
- * @stable ICU 2.4
- */
-#define U16_TRAIL(supplementary) (UChar)(((supplementary) & 0x3ff) | 0xdc00)
-
-// This must be called with the length pre-determined by the first byte.
-// If presented with a length > 4, this returns false. The Unicode
-// definition of UTF-8 goes up to 4-byte sequences.
-static bool isLegalUTF8(const unsigned char* source, int length)
-{
- unsigned char a;
- const unsigned char* srcptr = source + length;
- switch (length) {
- default:
- return false;
- // Everything else falls through when "true"...
- case 4:
- if ((a = (*--srcptr)) < 0x80 || a > 0xBF)
- return false;
- case 3:
- if ((a = (*--srcptr)) < 0x80 || a > 0xBF)
- return false;
- case 2:
- if ((a = (*--srcptr)) > 0xBF)
- return false;
-
- // no fall-through in this inner switch
- switch (*source) {
- case 0xE0:
- if (a < 0xA0)
- return false;
- break;
- case 0xED:
- if (a > 0x9F)
- return false;
- break;
- case 0xF0:
- if (a < 0x90)
- return false;
- break;
- case 0xF4:
- if (a > 0x8F)
- return false;
- break;
- default:
- if (a < 0x80)
- return false;
- }
-
- case 1:
- if (*source >= 0x80 && *source < 0xC2)
- return false;
- }
- if (*source > 0xF4)
- return false;
- return true;
-}
-
-// Magic values subtracted from a buffer value during UTF8 conversion.
-// This table contains as many values as there might be trailing bytes
-// in a UTF-8 sequence.
-static const UChar32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 0x03C82080UL, static_cast<UChar32>(0xFA082080UL), static_cast<UChar32>(0x82082080UL) };
-
-static inline UChar32 readUTF8Sequence(const char*& sequence, unsigned length)
-{
- UChar32 character = 0;
-
- // The cases all fall through.
- switch (length) {
- case 6:
- character += static_cast<unsigned char>(*sequence++);
- character <<= 6;
- case 5:
- character += static_cast<unsigned char>(*sequence++);
- character <<= 6;
- case 4:
- character += static_cast<unsigned char>(*sequence++);
- character <<= 6;
- case 3:
- character += static_cast<unsigned char>(*sequence++);
- character <<= 6;
- case 2:
- character += static_cast<unsigned char>(*sequence++);
- character <<= 6;
- case 1:
- character += static_cast<unsigned char>(*sequence++);
- }
-
- return character - offsetsFromUTF8[length - 1];
-}
-
-ConversionResult convertUTF8ToUTF16(
- const char** sourceStart, const char* sourceEnd,
- UChar** targetStart, UChar* targetEnd, bool* sourceAllASCII, bool strict)
-{
- ConversionResult result = conversionOK;
- const char* source = *sourceStart;
- UChar* target = *targetStart;
- UChar orAllData = 0;
- while (source < sourceEnd) {
- int utf8SequenceLength = inlineUTF8SequenceLength(*source);
- if (sourceEnd - source < utf8SequenceLength) {
- result = sourceExhausted;
- break;
- }
- // Do this check whether lenient or strict
- if (!isLegalUTF8(reinterpret_cast<const unsigned char*>(source), utf8SequenceLength)) {
- result = sourceIllegal;
- break;
- }
-
- UChar32 character = readUTF8Sequence(source, utf8SequenceLength);
-
- if (target >= targetEnd) {
- source -= utf8SequenceLength; // Back up source pointer!
- result = targetExhausted;
- break;
- }
-
- if (U_IS_BMP(character)) {
- // UTF-16 surrogate values are illegal in UTF-32
- if (U_IS_SURROGATE(character)) {
- if (strict) {
- source -= utf8SequenceLength; // return to the illegal value itself
- result = sourceIllegal;
- break;
- }
- *target++ = replacementCharacter;
- orAllData |= replacementCharacter;
- } else {
- *target++ = static_cast<UChar>(character); // normal case
- orAllData |= character;
- }
- } else if (U_IS_SUPPLEMENTARY(character)) {
- // target is a character in range 0xFFFF - 0x10FFFF
- if (target + 1 >= targetEnd) {
- source -= utf8SequenceLength; // Back up source pointer!
- result = targetExhausted;
- break;
- }
- *target++ = U16_LEAD(character);
- *target++ = U16_TRAIL(character);
- orAllData = 0xffff;
- } else {
- if (strict) {
- source -= utf8SequenceLength; // return to the start
- result = sourceIllegal;
- break; // Bail out; shouldn't continue
- } else {
- *target++ = replacementCharacter;
- orAllData |= replacementCharacter;
- }
- }
- }
- *sourceStart = source;
- *targetStart = target;
-
- if (sourceAllASCII)
- *sourceAllASCII = !(orAllData & ~0x7f);
-
- return result;
-}
-
-// Helper to write a three-byte UTF-8 code point to the buffer, caller must check room is available.
-static inline void putUTF8Triple(char*& buffer, UChar ch)
-{
- DCHECK_GE(ch, 0x0800);
- *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0);
- *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80);
- *buffer++ = static_cast<char>((ch & 0x3F) | 0x80);
-}
-
-String16 String16::fromUTF8(const char* stringStart, size_t length)
-{
- if (!stringStart || !length)
- return String16();
-
- std::vector<UChar> buffer(length);
- UChar* bufferStart = buffer.data();
-
- UChar* bufferCurrent = bufferStart;
- const char* stringCurrent = stringStart;
- if (convertUTF8ToUTF16(&stringCurrent, stringStart + length, &bufferCurrent, bufferCurrent + buffer.size(), 0, true) != conversionOK)
- return String16();
-
- unsigned utf16Length = bufferCurrent - bufferStart;
- return String16(bufferStart, utf16Length);
-}
-
-std::string String16::utf8() const
-{
- unsigned length = this->length();
-
- if (!length)
- return std::string("");
-
- // Allocate a buffer big enough to hold all the characters
- // (an individual UTF-16 UChar can only expand to 3 UTF-8 bytes).
- // Optimization ideas, if we find this function is hot:
- // * We could speculatively create a CStringBuffer to contain 'length'
- // characters, and resize if necessary (i.e. if the buffer contains
- // non-ascii characters). (Alternatively, scan the buffer first for
- // ascii characters, so we know this will be sufficient).
- // * We could allocate a CStringBuffer with an appropriate size to
- // have a good chance of being able to write the string into the
- // buffer without reallocing (say, 1.5 x length).
- if (length > std::numeric_limits<unsigned>::max() / 3)
- return std::string();
- std::vector<char> bufferVector(length * 3);
- char* buffer = bufferVector.data();
- const UChar* characters = m_impl.data();
-
- ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), false);
- DCHECK(result != targetExhausted); // (length * 3) should be sufficient for any conversion
-
- // Only produced from strict conversion.
- DCHECK(result != sourceIllegal);
-
- // Check for an unconverted high surrogate.
- if (result == sourceExhausted) {
- // This should be one unpaired high surrogate. Treat it the same
- // was as an unpaired high surrogate would have been handled in
- // the middle of a string with non-strict conversion - which is
- // to say, simply encode it to UTF-8.
- DCHECK((characters + 1) == (m_impl.data() + length));
- DCHECK((*characters >= 0xD800) && (*characters <= 0xDBFF));
- // There should be room left, since one UChar hasn't been
- // converted.
- DCHECK((buffer + 3) <= (buffer + bufferVector.size()));
- putUTF8Triple(buffer, *characters);
- }
-
- return std::string(bufferVector.data(), buffer - bufferVector.data());
-}
-
-} // namespace protocol
-} // namespace blink
diff --git a/String16STL.h b/String16STL.h
deleted file mode 100644
index 51da506..0000000
--- a/String16STL.h
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef String16STL_h
-#define String16STL_h
-
-#include <cctype>
-#include <cstdlib>
-#include <cstring>
-#include <stdint.h>
-#include <string>
-#include <vector>
-
-using UChar = uint16_t;
-
-namespace blink {
-namespace protocol {
-
-class String16 : public String16Base<String16, UChar> {
-public:
- static const size_t kNotFound = static_cast<size_t>(-1);
-
- String16() { }
- String16(const String16& other) : m_impl(other.m_impl) { }
- String16(const UChar* characters, size_t size) : m_impl(characters, size) { }
- String16(const UChar* characters) : m_impl(characters) { }
- String16(const char* characters) : String16(characters, std::strlen(characters)) { }
- String16(const char* characters, size_t size)
- {
- m_impl.resize(size);
- for (size_t i = 0; i < size; ++i)
- m_impl[i] = characters[i];
- }
-
- String16 isolatedCopy() const { return String16(m_impl); }
- const UChar* characters16() const { return m_impl.c_str(); }
- size_t length() const { return m_impl.length(); }
- bool isEmpty() const { return !m_impl.length(); }
- UChar operator[](unsigned index) const { return m_impl[index]; }
- String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return String16(m_impl.substr(pos, len)); }
- size_t find(const String16& str, unsigned start = 0) const { return m_impl.find(str.m_impl, start); }
- size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { return m_impl.rfind(str.m_impl, start); }
-
- // Convenience methods.
- std::string utf8() const;
- static String16 fromUTF8(const char* stringStart, size_t length);
-
- const std::basic_string<UChar>& impl() const { return m_impl; }
- explicit String16(const std::basic_string<UChar>& impl) : m_impl(impl) { }
-
- std::size_t hash() const
- {
- if (!has_hash) {
- size_t hash = 0;
- for (size_t i = 0; i < length(); ++i)
- hash = 31 * hash + m_impl[i];
- hash_code = hash;
- has_hash = true;
- }
- return hash_code;
- }
-
-private:
- std::basic_string<UChar> m_impl;
- mutable bool has_hash = false;
- mutable std::size_t hash_code = 0;
-};
-
-inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); }
-inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); }
-inline bool operator==(const String16& a, const char* b) { return a.impl() == String16(b).impl(); }
-inline String16 operator+(const String16& a, const char* b) { return String16(a.impl() + String16(b).impl()); }
-inline String16 operator+(const char* a, const String16& b) { return String16(String16(a).impl() + b.impl()); }
-inline String16 operator+(const String16& a, const String16& b) { return String16(a.impl() + b.impl()); }
-
-} // namespace protocol
-} // namespace blink
-
-#if !defined(__APPLE__) || defined(_LIBCPP_VERSION)
-
-namespace std {
-template<> struct hash<blink::protocol::String16> {
- std::size_t operator()(const blink::protocol::String16& string) const
- {
- return string.hash();
- }
-};
-
-} // namespace std
-
-#endif // !defined(__APPLE__) || defined(_LIBCPP_VERSION)
-
-class InspectorProtocolConvenienceStringType {
-public:
- // This class should not be ever instantiated, so we don't implement constructors.
- InspectorProtocolConvenienceStringType();
- InspectorProtocolConvenienceStringType(const blink::protocol::String16& other);
- operator blink::protocol::String16() const { return blink::protocol::String16(); };
-};
-
-#endif // !defined(String16STL_h)
diff --git a/String16WTF.h b/String16WTF.h
deleted file mode 100644
index b65383a..0000000
--- a/String16WTF.h
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef String16WTF_h
-#define String16WTF_h
-
-#include "platform/Decimal.h"
-#include "public/platform/WebString.h"
-#include "wtf/text/StringBuilder.h"
-#include "wtf/text/StringConcatenate.h"
-#include "wtf/text/StringHash.h"
-#include "wtf/text/StringToNumber.h"
-#include "wtf/text/StringView.h"
-#include "wtf/text/WTFString.h"
-
-namespace blink {
-namespace protocol {
-
-class PLATFORM_EXPORT String16 : public String16Base<String16, UChar> {
-public:
- static const size_t kNotFound = WTF::kNotFound;
-
- String16() { }
- String16(const String16& other) : m_impl(other.m_impl) { }
- String16(const UChar* characters, unsigned length) : m_impl(characters, length) { }
- String16(const char* characters) : String16(characters, strlen(characters)) { }
- String16(const char* characters, size_t length)
- {
- UChar* data;
- m_impl = WTF::String::createUninitialized(length, data);
- for (size_t i = 0; i < length; ++i)
- data[i] = characters[i];
- }
-
- ~String16() { }
-
- String16 isolatedCopy() const { return String16(m_impl.isolatedCopy()); }
- const UChar* characters16() const { return m_impl.isEmpty() ? nullptr : m_impl.characters16(); }
- size_t length() const { return m_impl.length(); }
- bool isEmpty() const { return m_impl.isEmpty(); }
- UChar operator[](unsigned index) const { return m_impl[index]; }
- String16 substring(unsigned pos, unsigned len = UINT_MAX) const { return m_impl.substring(pos, len); }
- size_t find(const String16& str, unsigned start = 0) const { return m_impl.find(str.impl(), start); }
- size_t reverseFind(const String16& str, unsigned start = UINT_MAX) const { return m_impl.reverseFind(str.impl(), start); }
-
- // WTF convenience constructors and helper methods.
- String16(const WebString& other) : String16(String(other)) { }
- template<typename StringType1, typename StringType2>
- String16(const WTF::StringAppend<StringType1, StringType2>& impl) : String16(String(impl)) { }
- String16(const WTF::AtomicString& impl) : String16(String(impl)) { }
- String16(const WTF::String& impl) : m_impl(impl) { m_impl.ensure16Bit(); }
- String16(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }
- bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); }
- operator WTF::String() const { return m_impl; }
- operator WTF::StringView() const { return StringView(m_impl); }
- operator WebString() { return m_impl; }
- const WTF::String& impl() const { return m_impl; }
-
-private:
- WTF::String m_impl;
-};
-
-inline bool operator==(const String16& a, const String16& b) { return a.impl() == b.impl(); }
-inline bool operator!=(const String16& a, const String16& b) { return a.impl() != b.impl(); }
-inline bool operator==(const String16& a, const char* b) { return a.impl() == b; }
-inline String16 operator+(const String16& a, const char* b) { return String16(a.impl() + b); }
-inline String16 operator+(const char* a, const String16& b) { return String16(a + b.impl()); }
-inline String16 operator+(const String16& a, const String16& b) { return String16(a.impl() + b.impl()); }
-
-} // namespace protocol
-} // namespace blink
-
-namespace std {
-template<> struct hash<blink::protocol::String16> {
- std::size_t operator()(const blink::protocol::String16& string) const
- {
- return StringHash::hash(string.impl());
- }
-};
-} // namespace std
-
-using InspectorProtocolConvenienceStringType = WTF::String;
-
-// WTF helpers below this line.
-
-namespace WTF {
-
-struct String16Hash {
- static unsigned hash(const blink::protocol::String16& key) { return StringHash::hash(key.impl()); }
- static bool equal(const blink::protocol::String16& a, const blink::protocol::String16& b)
- {
- return StringHash::equal(a.impl(), b.impl());
- }
- static const bool safeToCompareToEmptyOrDeleted = false;
-};
-
-template<typename T> struct DefaultHash;
-template<> struct DefaultHash<blink::protocol::String16> {
- typedef String16Hash Hash;
-};
-
-template<>
-struct HashTraits<blink::protocol::String16> : SimpleClassHashTraits<blink::protocol::String16> {
- static const bool hasIsEmptyValueFunction = true;
- static bool isEmptyValue(const blink::protocol::String16& a) { return a.impl().isNull(); }
-};
-
-} // namespace WTF
-
-#endif // !defined(String16WTF_h)
diff --git a/String16.cpp b/String16_cpp.template
similarity index 97%
rename from String16.cpp
rename to String16_cpp.template
index d9443fc..d795aef 100644
--- a/String16.cpp
+++ b/String16_cpp.template
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/String16.h"
-
#include <cstdlib>
#include <cstring>
#include <string>
diff --git a/String16.h b/String16_h.template
similarity index 86%
rename from String16.h
rename to String16_h.template
index 6713f69..005f349 100644
--- a/String16.h
+++ b/String16_h.template
@@ -5,8 +5,9 @@
#ifndef String16_h
#define String16_h
-#include "platform/inspector_protocol/Collections.h"
-#include "platform/inspector_protocol/Platform.h"
+//#include "Collections.h"
+//#include "Platform.h"
+#include "{{export_macro_include}}"
#include <vector>
@@ -14,16 +15,16 @@
namespace protocol {
namespace internal {
-PLATFORM_EXPORT void intToStr(int, char*, size_t);
-PLATFORM_EXPORT void doubleToStr(double, char*, size_t);
-PLATFORM_EXPORT void doubleToStr3(double, char*, size_t);
-PLATFORM_EXPORT void doubleToStr6(double, char*, size_t);
-PLATFORM_EXPORT double strToDouble(const char*, bool*);
-PLATFORM_EXPORT int strToInt(const char*, bool*);
+{{export_macro}} void intToStr(int, char*, size_t);
+{{export_macro}} void doubleToStr(double, char*, size_t);
+{{export_macro}} void doubleToStr3(double, char*, size_t);
+{{export_macro}} void doubleToStr6(double, char*, size_t);
+{{export_macro}} double strToDouble(const char*, bool*);
+{{export_macro}} int strToInt(const char*, bool*);
} // namespace internal
template <typename T, typename C>
-class PLATFORM_EXPORT String16Base {
+class {{export_macro}} String16Base {
public:
static bool isASCII(C c)
{
@@ -151,16 +152,12 @@
} // namespace protocol
} // namespace blink
-#if V8_INSPECTOR_USE_STL
-#include "platform/inspector_protocol/String16STL.h"
-#else
-#include "platform/inspector_protocol/String16WTF.h"
-#endif // V8_INSPECTOR_USE_STL
+#include "{{string16_impl_h_include}}"
namespace blink {
namespace protocol {
-class PLATFORM_EXPORT String16Builder {
+class {{export_macro}} String16Builder {
public:
String16Builder();
void append(const String16&);
diff --git a/TypeBuilder_cpp.template b/TypeBuilder_cpp.template
index e3c2fa1..1e76823 100644
--- a/TypeBuilder_cpp.template
+++ b/TypeBuilder_cpp.template
@@ -6,9 +6,6 @@
#include "{{output_package}}/{{domain.domain}}.h"
-#include "platform/inspector_protocol/DispatcherBase.h"
-#include "platform/inspector_protocol/Parser.h"
-
namespace blink {
namespace protocol {
namespace {{domain.domain}} {
diff --git a/TypeBuilder_h.template b/TypeBuilder_h.template
index 8331006..eb7fe2f 100644
--- a/TypeBuilder_h.template
+++ b/TypeBuilder_h.template
@@ -7,22 +7,8 @@
#ifndef protocol_{{domain.domain}}_h
#define protocol_{{domain.domain}}_h
-{% if export_macro == "PLATFORM_EXPORT" %}
-#include "platform/inspector_protocol/Platform.h"
-{% else %}
-#include "core/CoreExport.h"
-{% endif %}
-#include "platform/inspector_protocol/Array.h"
-#include "platform/inspector_protocol/BackendCallback.h"
-#include "platform/inspector_protocol/DispatcherBase.h"
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/FrontendChannel.h"
-#include "platform/inspector_protocol/Maybe.h"
-#include "platform/inspector_protocol/Object.h"
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/Values.h"
-#include "platform/inspector_protocol/ValueConversions.h"
+#include "{{export_macro_include}}"
+#include "{{lib_package}}/InspectorProtocol.h"
// For each imported domain we generate a ValueConversions struct instead of a full domain definition
// and include Domain::API version from there.
{% for name in domain.dependencies %}
diff --git a/ValueConversions.h b/ValueConversions_h.template
similarity index 95%
rename from ValueConversions.h
rename to ValueConversions_h.template
index fe30a4e..3b7eaa4 100644
--- a/ValueConversions.h
+++ b/ValueConversions_h.template
@@ -5,10 +5,10 @@
#ifndef ValueConversions_h
#define ValueConversions_h
-#include "platform/inspector_protocol/ErrorSupport.h"
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
-#include "platform/inspector_protocol/Values.h"
+//#include "ErrorSupport.h"
+//#include "Platform.h"
+//#include "String16.h"
+//#include "Values.h"
namespace blink {
namespace protocol {
diff --git a/Values.cpp b/Values_cpp.template
similarity index 95%
rename from Values.cpp
rename to Values_cpp.template
index 33a89da..482ec46 100644
--- a/Values.cpp
+++ b/Values_cpp.template
@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/inspector_protocol/Values.h"
-
-#include "platform/inspector_protocol/Parser.h"
-#include "platform/inspector_protocol/String16.h"
-
#include <algorithm>
#include <cmath>
@@ -15,9 +10,9 @@
namespace {
-const char* const nullString = "null";
-const char* const trueString = "true";
-const char* const falseString = "false";
+const char* const nullValueString = "null";
+const char* const trueValueString = "true";
+const char* const falseValueString = "false";
inline bool escapeChar(UChar c, String16Builder* dst)
{
@@ -109,7 +104,7 @@
void Value::writeJSON(String16Builder* output) const
{
DCHECK(m_type == TypeNull);
- output->append(nullString, 4);
+ output->append(nullValueString, 4);
}
std::unique_ptr<Value> Value::clone() const
@@ -151,12 +146,12 @@
DCHECK(type() == TypeBoolean || type() == TypeInteger || type() == TypeDouble);
if (type() == TypeBoolean) {
if (m_boolValue)
- output->append(trueString, 4);
+ output->append(trueValueString, 4);
else
- output->append(falseString, 5);
+ output->append(falseValueString, 5);
} else if (type() == TypeDouble) {
if (!std::isfinite(m_doubleValue)) {
- output->append(nullString, 4);
+ output->append(nullValueString, 4);
return;
}
output->append(String16::fromDouble(m_doubleValue));
diff --git a/Values.h b/Values_h.template
similarity index 92%
rename from Values.h
rename to Values_h.template
index 48a2012..840d119 100644
--- a/Values.h
+++ b/Values_h.template
@@ -5,10 +5,11 @@
#ifndef Values_h
#define Values_h
-#include "platform/inspector_protocol/Allocator.h"
-#include "platform/inspector_protocol/Collections.h"
-#include "platform/inspector_protocol/Platform.h"
-#include "platform/inspector_protocol/String16.h"
+//#include "Allocator.h"
+//#include "Collections.h"
+//#include "Platform.h"
+//#include "String16.h"
+#include "{{export_macro_include}}"
#include <vector>
@@ -19,7 +20,7 @@
class DictionaryValue;
class Value;
-class PLATFORM_EXPORT Value {
+class {{export_macro}} Value {
PROTOCOL_DISALLOW_COPY(Value);
public:
static const int maxDepth = 1000;
@@ -67,7 +68,7 @@
ValueType m_type;
};
-class PLATFORM_EXPORT FundamentalValue : public Value {
+class {{export_macro}} FundamentalValue : public Value {
public:
static std::unique_ptr<FundamentalValue> create(bool value)
{
@@ -102,7 +103,7 @@
};
};
-class PLATFORM_EXPORT StringValue : public Value {
+class {{export_macro}} StringValue : public Value {
public:
static std::unique_ptr<StringValue> create(const String16& value)
{
@@ -125,7 +126,7 @@
String16 m_stringValue;
};
-class PLATFORM_EXPORT SerializedValue : public Value {
+class {{export_macro}} SerializedValue : public Value {
public:
static std::unique_ptr<SerializedValue> create(const String16& value)
{
@@ -143,7 +144,7 @@
String16 m_serializedValue;
};
-class PLATFORM_EXPORT DictionaryValue : public Value {
+class {{export_macro}} DictionaryValue : public Value {
public:
using Entry = std::pair<String16, Value*>;
static std::unique_ptr<DictionaryValue> create()
@@ -210,7 +211,7 @@
std::vector<String16> m_order;
};
-class PLATFORM_EXPORT ListValue : public Value {
+class {{export_macro}} ListValue : public Value {
public:
static std::unique_ptr<ListValue> create()
{
diff --git a/sample_config.json b/sample_config.json
index 12d7e8b..48cad2e 100644
--- a/sample_config.json
+++ b/sample_config.json
@@ -19,5 +19,16 @@
"class_name": "String16"
},
- "export_macro": "PLATFORM_EXPORT"
+ "lib": {
+ "output": "place/generated/lib/files/here",
+ "string16_impl_header_path": "sting16/implementation.h",
+ "platform_impl_header_path": "platform/implementation.h"
+ },
+
+ "lib_package": "include/lib/files/like/this",
+
+ "class_export": {
+ "macro": "LIB_EXPORT",
+ "header_path": "lib/export.h"
+ }
}