summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceValues.h
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2021-04-12 07:50:42 -0700
committerRyan Mitchell <rtmitchell@google.com>2021-04-28 14:58:23 -0700
commit326e35ffaf0ee1e3d07c977217f4e600088fd9d5 (patch)
treec229a21641960bae0297e0b8bedb03305693024f /tools/aapt2/ResourceValues.h
parentff68a9adc3454b7cddb2501d8e82bd4b10b2037c (diff)
Add <macro> tag to aapt2
AAPT2 Macros are compile-time resources definitions that are expanded when referenced during the link phase. A macro must be defined in the res/values.xml directory. A macro definition for a macro named "foo" looks like the following: <macro name="foo">contents</macro> When "@macro/foo" is used in the res/values directory or in a compiled XML file, the contents of the macro replace the macro reference and then the substituted contents are compiled and linked. If the macro contents reference xml namespaces from its original definition, the namespaces of the original macro definition will be used to determine which package is being referenced. Macros can be used anywhere resources can be referenced using the @package:type/entry syntax. Macros are not included in the final resource table or the R.java since they are not actual resources. Bug: 175616308 Test: aapt2_tests Change-Id: I48b29ab6564357b32b4b4e32bff7ef06036382bc
Diffstat (limited to 'tools/aapt2/ResourceValues.h')
-rw-r--r--tools/aapt2/ResourceValues.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/aapt2/ResourceValues.h b/tools/aapt2/ResourceValues.h
index 025864d385cf..d11b013f14d5 100644
--- a/tools/aapt2/ResourceValues.h
+++ b/tools/aapt2/ResourceValues.h
@@ -164,6 +164,8 @@ struct Reference : public TransformableItem<Reference, BaseItem<Reference>> {
Reference::Type reference_type;
bool private_reference = false;
bool is_dynamic = false;
+ std::optional<uint32_t> type_flags;
+ bool allow_raw;
Reference();
explicit Reference(const ResourceNameRef& n, Type type = Type::kResource);
@@ -311,6 +313,8 @@ struct Attribute : public TransformableValue<Attribute, BaseValue<Attribute>> {
bool IsCompatibleWith(const Attribute& attr) const;
std::string MaskString() const;
+ static std::string MaskString(uint32_t type_mask);
+
void Print(std::ostream* out) const override;
bool Matches(const Item& item, DiagMessage* out_msg = nullptr) const;
};
@@ -362,6 +366,28 @@ struct Styleable : public TransformableValue<Styleable, BaseValue<Styleable>> {
void MergeWith(Styleable* styleable);
};
+struct Macro : public TransformableValue<Macro, BaseValue<Macro>> {
+ std::string raw_value;
+ StyleString style_string;
+ std::vector<UntranslatableSection> untranslatable_sections;
+
+ struct Namespace {
+ std::string alias;
+ std::string package_name;
+ bool is_private;
+
+ bool operator==(const Namespace& right) const {
+ return alias == right.alias && package_name == right.package_name &&
+ is_private == right.is_private;
+ }
+ };
+
+ std::vector<Namespace> alias_namespaces;
+
+ bool Equals(const Value* value) const override;
+ void Print(std::ostream* out) const override;
+};
+
template <typename T>
typename std::enable_if<std::is_base_of<Value, T>::value, std::ostream&>::type operator<<(
std::ostream& out, const std::unique_ptr<T>& value) {
@@ -388,6 +414,7 @@ struct CloningValueTransformer : public ValueTransformer {
std::unique_ptr<Array> TransformDerived(const Array* value) override;
std::unique_ptr<Plural> TransformDerived(const Plural* value) override;
std::unique_ptr<Styleable> TransformDerived(const Styleable* value) override;
+ std::unique_ptr<Macro> TransformDerived(const Macro* value) override;
};
} // namespace aapt