VapourSynth-llvmexpr
Loading...
Searching...
No Matches
analysis::PropWriteTypeSafetyPass Class Reference

#include <llvmexpr/analysis/passes/PropWriteTypeSafetyPass.hpp>

Inheritance diagram for analysis::PropWriteTypeSafetyPass:
Collaboration diagram for analysis::PropWriteTypeSafetyPass:

Public Types

using Result = PropWriteTypeSafetyResult
Public Types inherited from analysis::AnalysisPass< PropWriteTypeSafetyPass, PropWriteTypeSafetyResult >
using Result

Public Member Functions

const char * getName () const override
Result run (const std::vector< Token > &tokens, AnalysisManager &am) override
Public Member Functions inherited from analysis::Pass
 Pass ()=default
virtual ~Pass ()=default
 Pass (const Pass &)=delete
Passoperator= (const Pass &)=delete
 Pass (Pass &&)=delete
Passoperator= (Pass &&)=delete

Detailed Description

Ensures that all writes to the same property use a consistent type. For example, using both prop$f and prop$i on the same property prop is disallowed. This pass will raise an AnalysisError if such an inconsistency is detected.

Depends on: None

Definition at line 37 of file PropWriteTypeSafetyPass.hpp.

Member Typedef Documentation

◆ Result

Member Function Documentation

◆ getName()

const char * analysis::PropWriteTypeSafetyPass::getName ( ) const
inlinenodiscardoverridevirtual

Implements analysis::Pass.

Definition at line 42 of file PropWriteTypeSafetyPass.hpp.

42 {
43 return "Prop Write Type Safety Pass";
44 }

◆ run()

PropWriteTypeSafetyPass::Result analysis::PropWriteTypeSafetyPass::run ( const std::vector< Token > & tokens,
AnalysisManager & am )
overridevirtual

Implements analysis::AnalysisPass< PropWriteTypeSafetyPass, PropWriteTypeSafetyResult >.

Definition at line 33 of file PropWriteTypeSafetyPass.cpp.

34 {
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}
consteval std::string_view enum_name()
Definition EnumName.hpp:57

References Delete, enum_name(), and PropStore.


The documentation for this class was generated from the following files: