зеркало из https://github.com/github/codeql.git
Swift: use `#pragma once`
This commit is contained in:
Родитель
2374e6b401
Коммит
c4fae0806f
|
@ -22,7 +22,7 @@ class Renderer:
|
|||
self._r = pystache.Renderer(search_dirs=str(paths.templates_dir), escape=lambda u: u)
|
||||
self.written = set()
|
||||
|
||||
def render(self, data, output: pathlib.Path, guard_base: pathlib.Path = None):
|
||||
def render(self, data, output: pathlib.Path):
|
||||
""" Render `data` to `output`.
|
||||
|
||||
`data` must have a `template` attribute denoting which template to use from the template directory.
|
||||
|
@ -34,10 +34,7 @@ class Renderer:
|
|||
"""
|
||||
mnemonic = type(data).__name__
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
guard = None
|
||||
if guard_base is not None:
|
||||
guard = str(output.relative_to(guard_base)).replace("/", "_").replace(".", "_").upper()
|
||||
data = self._r.render_name(data.template, data, generator=paths.exe_file, guard=guard)
|
||||
data = self._r.render_name(data.template, data, generator=paths.exe_file)
|
||||
with open(output, "w") as out:
|
||||
out.write(data)
|
||||
log.debug(f"generated {mnemonic} {output.name}")
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// generated by {{generator}}
|
||||
// clang-format off
|
||||
#ifndef SWIFT_EXTRACTOR_TRAP_{{guard}}
|
||||
#define SWIFT_EXTRACTOR_TRAP_{{guard}}
|
||||
#pragma once
|
||||
|
||||
namespace codeql {
|
||||
{{#tags}}
|
||||
|
@ -12,4 +11,3 @@ struct {{name}}Tag {{#has_bases}}: {{#bases}}{{^first}}, {{/first}}{{base}}Tag{{
|
|||
};
|
||||
{{/tags}}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// generated by {{generator}}
|
||||
// clang-format off
|
||||
#ifndef SWIFT_EXTRACTOR_TRAP_{{guard}}
|
||||
#define SWIFT_EXTRACTOR_TRAP_{{guard}}
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
@ -32,4 +31,3 @@ inline std::ostream &operator<<(std::ostream &out, const {{name}}Trap &e) {
|
|||
{{/traps}}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -85,13 +85,16 @@ def test_class_db_id():
|
|||
cls = ql.Class("ThisIsMyClass")
|
||||
assert cls.db_id == "@this_is_my_class"
|
||||
|
||||
|
||||
def test_root_class():
|
||||
cls = ql.Class("Class")
|
||||
assert cls.root
|
||||
|
||||
|
||||
def test_non_root_class():
|
||||
cls = ql.Class("Class", bases=["A"])
|
||||
assert not cls.root
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(pytest.main())
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import sys
|
||||
import pathlib
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
@ -41,7 +40,7 @@ def test_render(pystache_renderer, sut):
|
|||
with mock.patch("builtins.open", mock.mock_open()) as output_stream:
|
||||
sut.render(data, output)
|
||||
assert pystache_renderer.mock_calls == [
|
||||
mock.call.render_name(data.template, data, generator=paths.exe_file, guard=None),
|
||||
mock.call.render_name(data.template, data, generator=paths.exe_file),
|
||||
]
|
||||
assert output_stream.mock_calls == [
|
||||
mock.call(output, 'w'),
|
||||
|
@ -52,17 +51,6 @@ def test_render(pystache_renderer, sut):
|
|||
assert sut.written == {output}
|
||||
|
||||
|
||||
def test_render_with_guard(pystache_renderer, sut):
|
||||
guard_base = pathlib.Path("test", "guard")
|
||||
data = mock.Mock()
|
||||
output = guard_base / "this" / "is" / "a" / "header.h"
|
||||
with mock.patch("builtins.open", mock.mock_open()) as output_stream:
|
||||
sut.render(data, output, guard_base=guard_base)
|
||||
assert pystache_renderer.mock_calls == [
|
||||
mock.call.render_name(data.template, data, generator=paths.exe_file, guard="THIS_IS_A_HEADER_H"),
|
||||
]
|
||||
|
||||
|
||||
def test_written(sut):
|
||||
data = [mock.Mock() for _ in range(4)]
|
||||
output = [mock.Mock() for _ in data]
|
||||
|
|
|
@ -117,7 +117,7 @@ def generate(opts, renderer):
|
|||
tag_graph[e.lhs]["derived"].append(d.type)
|
||||
tag_graph[d.type]["bases"].append(e.lhs)
|
||||
|
||||
renderer.render(cpp.TrapList(traps), out / "TrapEntries.h", guard_base=out)
|
||||
renderer.render(cpp.TrapList(traps), out / "TrapEntries.h")
|
||||
|
||||
tags = []
|
||||
for index, tag in enumerate(get_topologically_ordered_tags(tag_graph)):
|
||||
|
@ -127,7 +127,7 @@ def generate(opts, renderer):
|
|||
index=index,
|
||||
id=tag,
|
||||
))
|
||||
renderer.render(cpp.TagList(tags), out / "TrapTags.h", guard_base=out)
|
||||
renderer.render(cpp.TagList(tags), out / "TrapTags.h")
|
||||
|
||||
|
||||
tags = ("trap", "dbscheme")
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef SWIFT_EXTRACTOR_H_
|
||||
#define SWIFT_EXTRACTOR_H_
|
||||
#pragma once
|
||||
|
||||
#include "SwiftExtractorConfiguration.h"
|
||||
#include <swift/AST/SourceFile.h>
|
||||
|
@ -10,5 +9,3 @@ namespace codeql {
|
|||
void extractSwiftFiles(const SwiftExtractorConfiguration& config,
|
||||
swift::CompilerInstance& compiler);
|
||||
} // namespace codeql
|
||||
|
||||
#endif // SWIFT_EXTRACTOR_H_
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef SWIFT_EXTRACTOR_CONFIGURATION_H_
|
||||
#define SWIFT_EXTRACTOR_CONFIGURATION_H_
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -14,5 +13,3 @@ struct SwiftExtractorConfiguration {
|
|||
std::vector<std::string> frontendOptions;
|
||||
};
|
||||
} // namespace codeql
|
||||
|
||||
#endif // SWIFT_EXTRACTOR_CONFIGURATION_H_
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef SWIFT_EXTRACTOR_TRAP_LABEL_H
|
||||
#define SWIFT_EXTRACTOR_TRAP_LABEL_H
|
||||
#pragma once
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
@ -65,4 +64,3 @@ struct hash<codeql::UntypedTrapLabel> {
|
|||
}
|
||||
};
|
||||
} // namespace std
|
||||
#endif // SWIFT_EXTRACTOR_LIB_EXTRACTOR_CPP_TRAP_LABEL_H_
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#ifndef SWIFT_EXTRACTOR_INCLUDE_EXTRACTOR_TRAP_TAGTRAITS_H
|
||||
#define SWIFT_EXTRACTOR_INCLUDE_EXTRACTOR_TRAP_TAGTRAITS_H
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -14,5 +13,3 @@ template <typename T>
|
|||
using ToTag = typename ToTagOverride<std::remove_const_t<T>>::type;
|
||||
|
||||
} // namespace codeql::trap
|
||||
|
||||
#endif // SWIFT_EXTRACTOR_INCLUDE_EXTRACTOR_TRAP_TAGTRAITS_H
|
||||
|
|
Загрузка…
Ссылка в новой задаче