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):
|
def __init__(self, translation_units):
|
||||||
# type: (List[cindex.TranslationUnit]) -> None
|
# type: (List[cindex.TranslationUnit]) -> None
|
||||||
"""Initialize Generator.
|
"""Initializes the generator.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
translation_units: list of translation_units for analyzed files,
|
translation_units: list of translation_units for analyzed files,
|
||||||
|
@ -876,20 +876,17 @@ class Generator(object):
|
||||||
if embed_dir and embed_name:
|
if embed_dir and embed_name:
|
||||||
result.append(Generator.EMBED_INCLUDE.format(embed_dir, embed_name))
|
result.append(Generator.EMBED_INCLUDE.format(embed_dir, embed_name))
|
||||||
|
|
||||||
result.append('')
|
|
||||||
if namespaces:
|
if namespaces:
|
||||||
|
result.append('')
|
||||||
for n in namespaces:
|
for n in namespaces:
|
||||||
result.append('namespace {} {{'.format(n))
|
result.append('namespace {} {{'.format(n))
|
||||||
|
|
||||||
result.append('')
|
|
||||||
result.append('')
|
|
||||||
|
|
||||||
if related_types:
|
if related_types:
|
||||||
|
result.append('')
|
||||||
for t in related_types:
|
for t in related_types:
|
||||||
result.append(t)
|
result.append(t)
|
||||||
|
|
||||||
result.append('')
|
result.append('')
|
||||||
result.append('')
|
|
||||||
|
|
||||||
if embed_dir and embed_name:
|
if embed_dir and embed_name:
|
||||||
result.append(
|
result.append(
|
||||||
|
@ -899,15 +896,13 @@ class Generator(object):
|
||||||
result.append(' public:')
|
result.append(' public:')
|
||||||
result.append(' explicit {}Api(::sapi::Sandbox* sandbox)'
|
result.append(' explicit {}Api(::sapi::Sandbox* sandbox)'
|
||||||
' : sandbox_(sandbox) {{}}'.format(name))
|
' : sandbox_(sandbox) {{}}'.format(name))
|
||||||
result.append(' ::sapi::Sandbox* GetSandbox() {')
|
result.append(' // Deprecated')
|
||||||
result.append(' return sandbox_;')
|
result.append(' ::sapi::Sandbox* GetSandbox() const { return sandbox(); }')
|
||||||
result.append(' }')
|
result.append(' ::sapi::Sandbox* sandbox() const { return sandbox_; }')
|
||||||
result.append('')
|
|
||||||
result.append('')
|
|
||||||
|
|
||||||
for f in functions:
|
for f in functions:
|
||||||
result.append(self._format_function(f))
|
|
||||||
result.append('')
|
result.append('')
|
||||||
|
result.append(self._format_function(f))
|
||||||
|
|
||||||
result.append('')
|
result.append('')
|
||||||
result.append(' private:')
|
result.append(' private:')
|
||||||
|
@ -923,7 +918,5 @@ class Generator(object):
|
||||||
result.append(Generator.GUARD_END.format(header_guard))
|
result.append(Generator.GUARD_END.format(header_guard))
|
||||||
|
|
||||||
result.append('')
|
result.append('')
|
||||||
result.append('')
|
|
||||||
result.append('')
|
|
||||||
|
|
||||||
return '\n'.join(result)
|
return '\n'.join(result)
|
||||||
|
|
|
@ -24,16 +24,12 @@ CODE_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
|
||||||
namespace sapi {
|
namespace sapi {
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestApi {
|
class TestApi {
|
||||||
public:
|
public:
|
||||||
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
||||||
::sapi::Sandbox* GetSandbox() {
|
// Deprecated
|
||||||
return sandbox_;
|
::sapi::Sandbox* GetSandbox() const { return sandbox(); }
|
||||||
}
|
::sapi::Sandbox* sandbox() const { return sandbox_; }
|
||||||
|
|
||||||
|
|
||||||
// int function_a(int, int)
|
// int function_a(int, int)
|
||||||
::sapi::StatusOr<int> function_a(int x, int y) {
|
::sapi::StatusOr<int> function_a(int x, int y) {
|
||||||
|
@ -112,15 +108,12 @@ class TestApi {
|
||||||
return ::sapi::OkStatus();
|
return ::sapi::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
::sapi::Sandbox* sandbox_;
|
::sapi::Sandbox* sandbox_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace sapi
|
} // namespace sapi
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CODE_GOLD_MAPPED = """// AUTO-GENERATED by the Sandboxed API generator.
|
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 sapi {
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|
||||||
|
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef uint * uintp;
|
typedef uint * uintp;
|
||||||
|
|
||||||
|
|
||||||
class TestApi {
|
class TestApi {
|
||||||
public:
|
public:
|
||||||
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
||||||
::sapi::Sandbox* GetSandbox() {
|
// Deprecated
|
||||||
return sandbox_;
|
::sapi::Sandbox* GetSandbox() const { return sandbox(); }
|
||||||
}
|
::sapi::Sandbox* sandbox() const { return sandbox_; }
|
||||||
|
|
||||||
|
|
||||||
// uint function(uintp)
|
// uint function(uintp)
|
||||||
::sapi::StatusOr<uint> function(::sapi::v::Ptr* a) {
|
::sapi::StatusOr<uint> function(::sapi::v::Ptr* a) {
|
||||||
|
@ -153,15 +143,12 @@ class TestApi {
|
||||||
return ret.GetValue();
|
return ret.GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
::sapi::Sandbox* sandbox_;
|
::sapi::Sandbox* sandbox_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace sapi
|
} // namespace sapi
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CODE_ENUM_GOLD = """// AUTO-GENERATED by the Sandboxed API generator.
|
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 sapi {
|
||||||
namespace Tests {
|
namespace Tests {
|
||||||
|
|
||||||
|
|
||||||
enum ProcessStatus {
|
enum ProcessStatus {
|
||||||
\tOK = 0 ,
|
\tOK = 0 ,
|
||||||
\tERROR = 1 ,
|
\tERROR = 1 ,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class TestApi {
|
class TestApi {
|
||||||
public:
|
public:
|
||||||
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
explicit TestApi(::sapi::Sandbox* sandbox) : sandbox_(sandbox) {}
|
||||||
::sapi::Sandbox* GetSandbox() {
|
// Deprecated
|
||||||
return sandbox_;
|
::sapi::Sandbox* GetSandbox() const { return sandbox(); }
|
||||||
}
|
::sapi::Sandbox* sandbox() const { return sandbox_; }
|
||||||
|
|
||||||
|
|
||||||
// ProcessStatus ProcessDatapoint(ProcessStatus)
|
// ProcessStatus ProcessDatapoint(ProcessStatus)
|
||||||
::sapi::StatusOr<ProcessStatus> ProcessDatapoint(ProcessStatus status) {
|
::sapi::StatusOr<ProcessStatus> ProcessDatapoint(ProcessStatus status) {
|
||||||
|
@ -197,13 +181,10 @@ class TestApi {
|
||||||
return static_cast<ProcessStatus>(ret.GetValue());
|
return static_cast<ProcessStatus>(ret.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
::sapi::Sandbox* sandbox_;
|
::sapi::Sandbox* sandbox_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Tests
|
} // namespace Tests
|
||||||
} // namespace sapi
|
} // namespace sapi
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user