VapourSynth-llvmexpr
Loading...
Searching...
No Matches
PropWriteTypeSafetyPass.cpp
Go to the documentation of this file.
1
19
25
26#include <format>
27#include <map>
28#include <string>
29
30namespace analysis {
31
33PropWriteTypeSafetyPass::run(const std::vector<Token>& tokens,
34 [[maybe_unused]] AnalysisManager& am) {
35 std::map<std::string, std::pair<PropWriteType, int>> prop_types;
36
37 for (size_t i = 0; i < tokens.size(); ++i) {
38 const auto& token = tokens[i];
39 if (token.type == TokenType::PropStore) {
40 const auto& payload =
41 std::get<TokenPayloadPropStore>(token.payload);
42 const auto& prop_name = payload.prop_name;
43 const auto& prop_type = payload.type;
44
45 auto it = prop_types.find(prop_name);
46 if (it != prop_types.end()) {
47 auto& stored_type = it->second.first;
48 if (stored_type != prop_type) {
49 // DELETE can co-exist with other types.
50 if (stored_type == PropWriteType::Delete) {
51 stored_type = prop_type;
52 it->second.second = static_cast<int>(i);
53 } else if (prop_type != PropWriteType::Delete) {
54 throw AnalysisError(
55 std::format(
56 "Inconsistent types used for property '{}'. "
57 "Previous type: {} (idx: {}), current type: {} "
58 "(idx: {}).",
59 prop_name, enum_name(stored_type),
60 it->second.second,
61 enum_name(prop_type), static_cast<int>(i)),
62 static_cast<int>(i));
63 }
64 }
65 } else {
66 prop_types[prop_name] =
67 std::make_pair(prop_type, static_cast<int>(i));
68 }
69 }
70 }
71
72 return {};
73}
74
75} // namespace analysis
consteval std::string_view enum_name()
Definition EnumName.hpp:57
Result run(const std::vector< Token > &tokens, AnalysisManager &am) override