mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Improve formatting of the generated code
PiperOrigin-RevId: 260142999 Change-Id: Id170e212012c7e10e3525d031d620a01f90fb388
This commit is contained in:
parent
3c51348aaf
commit
1be24d945c
|
@ -666,7 +666,7 @@ class Generator(object):
|
|||
|
||||
def __init__(self, translation_units):
|
||||
# type: (List[cindex.TranslationUnit]) -> None
|
||||
"""Initialize Generator.
|
||||
"""Initializes the generator.
|
||||
|
||||
Args:
|
||||
translation_units: list of translation_units for analyzed files,
|
||||
|
@ -876,20 +876,17 @@ class Generator(object):
|
|||
if embed_dir and embed_name:
|
||||
result.append(Generator.EMBED_INCLUDE.format(embed_dir, embed_name))
|
||||
|
||||
result.append('')
|
||||
if namespaces:
|
||||
result.append('')
|
||||
for n in namespaces:
|
||||
result.append('namespace {} {{'.format(n))
|
||||
|
||||
result.append('')
|
||||
result.append('')
|
||||
|
||||
if related_types:
|
||||
result.append('')
|
||||
for t in related_types:
|
||||
result.append(t)
|
||||
|
||||
result.append('')
|
||||
result.append('')
|
||||
|
||||
if embed_dir and embed_name:
|
||||
result.append(
|
||||
|
@ -899,15 +896,13 @@ class Generator(object):
|
|||
result.append(' public:')
|
||||
result.append(' explicit {}Api(::sapi::Sandbox* sandbox)'
|
||||
' : sandbox_(sandbox) {{}}'.format(name))
|
||||
result.append(' ::sapi::Sandbox* GetSandbox() {')
|
||||
result.append(' return sandbox_;')
|
||||
result.append(' }')
|
||||
result.append('')
|
||||
result.append('')
|
||||
result.append(' // Deprecated')
|
||||
result.append(' ::sapi::Sandbox* GetSandbox() const { return sandbox(); }')
|
||||
result.append(' ::sapi::Sandbox* sandbox() const { return sandbox_; }')
|
||||
|
||||
for f in functions:
|
||||
result.append(self._format_function(f))
|
||||
result.append('')
|
||||
result.append(self._format_function(f))
|
||||
|
||||
result.append('')
|
||||
result.append(' private:')
|
||||
|
@ -923,7 +918,5 @@ class Generator(object):
|
|||
result.append(Generator.GUARD_END.format(header_guard))
|
||||
|
||||
result.append('')
|
||||
result.append('')
|
||||
result.append('')
|
||||
|
||||
return '\n'.join(result)
|
||||
|
|
|
@ -24,16 +24,12 @@ CODE_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
|
|||
namespace sapi {
|
||||
namespace Tests {
|
||||
|
||||
|
||||
|
||||
|
||||
class TestApi {
|
||||
public:
|
||||
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
||||
::sapi::Sandbox* GetSandbox() {
|
||||
return sandbox_;
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
::sapi::Sandbox* GetSandbox() const { return sandbox(); }
|
||||
::sapi::Sandbox* sandbox() const { return sandbox_; }
|
||||
|
||||
// int function_a(int, int)
|
||||
::sapi::StatusOr<int> function_a(int x, int y) {
|
||||
|
@ -112,15 +108,12 @@ class TestApi {
|
|||
return ::sapi::OkStatus();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
::sapi::Sandbox* sandbox_;
|
||||
};
|
||||
|
||||
} // namespace Tests
|
||||
} // namespace sapi
|
||||
|
||||
|
||||
"""
|
||||
|
||||
CODE_GOLD_MAPPED = """// AUTO-GENERATED by the Sandboxed API generator.
|
||||
|
@ -132,18 +125,15 @@ CODE_GOLD_MAPPED = """// AUTO-GENERATED by the Sandboxed API generator.
|
|||
namespace sapi {
|
||||
namespace Tests {
|
||||
|
||||
|
||||
typedef unsigned int uint;
|
||||
typedef uint * uintp;
|
||||
|
||||
|
||||
class TestApi {
|
||||
public:
|
||||
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
||||
::sapi::Sandbox* GetSandbox() {
|
||||
return sandbox_;
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
::sapi::Sandbox* GetSandbox() const { return sandbox(); }
|
||||
::sapi::Sandbox* sandbox() const { return sandbox_; }
|
||||
|
||||
// uint function(uintp)
|
||||
::sapi::StatusOr<uint> function(::sapi::v::Ptr* a) {
|
||||
|
@ -153,15 +143,12 @@ class TestApi {
|
|||
return ret.GetValue();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
::sapi::Sandbox* sandbox_;
|
||||
};
|
||||
|
||||
} // namespace Tests
|
||||
} // namespace sapi
|
||||
|
||||
|
||||
"""
|
||||
|
||||
CODE_ENUM_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
|
||||
|
@ -173,20 +160,17 @@ CODE_ENUM_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
|
|||
namespace sapi {
|
||||
namespace Tests {
|
||||
|
||||
|
||||
enum ProcessStatus {
|
||||
\tOK = 0 ,
|
||||
\tERROR = 1 ,
|
||||
};
|
||||
|
||||
|
||||
class TestApi {
|
||||
public:
|
||||
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
||||
::sapi::Sandbox* GetSandbox() {
|
||||
return sandbox_;
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
::sapi::Sandbox* GetSandbox() const { return sandbox(); }
|
||||
::sapi::Sandbox* sandbox() const { return sandbox_; }
|
||||
|
||||
// ProcessStatus ProcessDatapoint(ProcessStatus)
|
||||
::sapi::StatusOr<ProcessStatus> ProcessDatapoint(ProcessStatus status) {
|
||||
|
@ -197,13 +181,10 @@ class TestApi {
|
|||
return static_cast<ProcessStatus>(ret.GetValue());
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
::sapi::Sandbox* sandbox_;
|
||||
};
|
||||
|
||||
} // namespace Tests
|
||||
} // namespace sapi
|
||||
|
||||
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user