librime: config_compiler_impl.h Source File

| librime 1.2 Rime Input Method Engine, the core library

config_compiler_impl.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5#ifndef RIME_CONFIG_COMPILER_IMPL_H_
6#define RIME_CONFIG_COMPILER_IMPL_H_
7
8#include <ostream>
9#include <rime/common.h>
10#include <rime/config/config_compiler.h>
11#include <rime/config/config_types.h>
12
13namespace rime {
14
15 enum DependencyPriority {
16 kPendingChild = 0,
17 kInclude = 1,
18 kPatch = 2,
19};
20
21 struct Dependency {
22 an<ConfigItemRef> target;
23
24 virtual DependencyPriority priority() const = 0;
25 bool blocking() const { return priority() > kPendingChild; }
26 virtual string repr() const = 0;
27 Dependency& TargetedAt(an<ConfigItemRef> target) {
28 this->target = target;
29 return *this;
30 }
31 virtual bool Resolve(ConfigCompiler* compiler) = 0;
32};
33
34std::ostream& operator<<(std::ostream& stream, const Dependency& dependency);
35
36 struct PendingChild : Dependency {
37 string child_path;
38 an<ConfigItemRef> child_ref;
39
40 PendingChild(const string& path, const an<ConfigItemRef>& ref)
41 : child_path(path), child_ref(ref) {}
42 DependencyPriority priority() const override { return kPendingChild; }
43 string repr() const override { return "PendingChild(" + child_path + ")"; }
44 bool Resolve(ConfigCompiler* compiler) override;
45};
46
47 struct IncludeReference : Dependency {
48 Reference reference;
49
50 IncludeReference(const Reference& r) : reference(r) {}
51 DependencyPriority priority() const override { return kInclude; }
52 string repr() const override { return "Include(" + reference.repr() + ")"; }
53 bool Resolve(ConfigCompiler* compiler) override;
54};
55
56 struct PatchReference : Dependency {
57 Reference reference;
58
59 PatchReference(const Reference& r) : reference(r) {}
60 DependencyPriority priority() const override { return kPatch; }
61 string repr() const override { return "Patch(" + reference.repr() + ")"; }
62 bool Resolve(ConfigCompiler* compiler) override;
63};
64
65 struct PatchLiteral : Dependency {
66 an<ConfigMap> patch;
67
68 PatchLiteral(an<ConfigMap> map) : patch(map) {}
69 DependencyPriority priority() const override { return kPatch; }
70 string repr() const override { return "Patch(<literal>)"; }
71 bool Resolve(ConfigCompiler* compiler) override;
72};
73
74} // namespace rime
75
76#endif // RIME_CONFIG_COMPILER_IMPL_H_
common.h
config_compiler.h
config_types.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::DependencyPriority
DependencyPriority
Definition config_compiler_impl.h:15
rime::kInclude
@ kInclude
Definition config_compiler_impl.h:17
rime::kPendingChild
@ kPendingChild
Definition config_compiler_impl.h:16
rime::kPatch
@ kPatch
Definition config_compiler_impl.h:18
rime::operator<<
std::ostream & operator<<(std::ostream &stream, const Reference &reference)
Definition config_compiler.cc:12
rime::path
Definition common.h:84
rime::Reference
Definition config_compiler.h:26
rime::Reference::repr
string repr() const
Definition config_compiler.cc:49
rime::ConfigCompiler
Definition config_compiler.h:41
rime::Dependency
Definition config_compiler_impl.h:21
rime::Dependency::TargetedAt
Dependency & TargetedAt(an< ConfigItemRef > target)
Definition config_compiler_impl.h:27
rime::Dependency::target
an< ConfigItemRef > target
Definition config_compiler_impl.h:22
rime::Dependency::priority
virtual DependencyPriority priority() const =0
rime::Dependency::repr
virtual string repr() const =0
rime::Dependency::Resolve
virtual bool Resolve(ConfigCompiler *compiler)=0
rime::Dependency::blocking
bool blocking() const
Definition config_compiler_impl.h:25
rime::PendingChild::child_path
string child_path
Definition config_compiler_impl.h:37
rime::PendingChild::Resolve
bool Resolve(ConfigCompiler *compiler) override
Definition config_compiler.cc:53
rime::PendingChild::PendingChild
PendingChild(const string &path, const an< ConfigItemRef > &ref)
Definition config_compiler_impl.h:40
rime::PendingChild::child_ref
an< ConfigItemRef > child_ref
Definition config_compiler_impl.h:38
rime::PendingChild::priority
DependencyPriority priority() const override
Definition config_compiler_impl.h:42
rime::PendingChild::repr
string repr() const override
Definition config_compiler_impl.h:43
rime::IncludeReference::repr
string repr() const override
Definition config_compiler_impl.h:52
rime::IncludeReference::Resolve
bool Resolve(ConfigCompiler *compiler) override
Definition config_compiler.cc:62
rime::IncludeReference::IncludeReference
IncludeReference(const Reference &r)
Definition config_compiler_impl.h:50
rime::IncludeReference::reference
Reference reference
Definition config_compiler_impl.h:48
rime::IncludeReference::priority
DependencyPriority priority() const override
Definition config_compiler_impl.h:51
rime::PatchReference::PatchReference
PatchReference(const Reference &r)
Definition config_compiler_impl.h:59
rime::PatchReference::Resolve
bool Resolve(ConfigCompiler *compiler) override
Definition config_compiler.cc:78
rime::PatchReference::priority
DependencyPriority priority() const override
Definition config_compiler_impl.h:60
rime::PatchReference::reference
Reference reference
Definition config_compiler_impl.h:57
rime::PatchReference::repr
string repr() const override
Definition config_compiler_impl.h:61
rime::PatchLiteral::patch
an< ConfigMap > patch
Definition config_compiler_impl.h:66
rime::PatchLiteral::PatchLiteral
PatchLiteral(an< ConfigMap > map)
Definition config_compiler_impl.h:68
rime::PatchLiteral::repr
string repr() const override
Definition config_compiler_impl.h:70
rime::PatchLiteral::priority
DependencyPriority priority() const override
Definition config_compiler_impl.h:69
rime::PatchLiteral::Resolve
bool Resolve(ConfigCompiler *compiler) override
Definition config_compiler.cc:208