Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT_LINKER_REFERENCELINKER_H |
| 18 | #define AAPT_LINKER_REFERENCELINKER_H |
| 19 | |
| 20 | #include "Resource.h" |
| 21 | #include "ResourceValues.h" |
| 22 | #include "ValueVisitor.h" |
| 23 | #include "link/Linkers.h" |
| 24 | #include "process/IResourceTableConsumer.h" |
| 25 | #include "process/SymbolTable.h" |
| 26 | #include "xml/XmlDom.h" |
| 27 | |
| 28 | #include <cassert> |
| 29 | |
| 30 | namespace aapt { |
| 31 | |
| 32 | /** |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 33 | * Resolves all references to resources in the ResourceTable and assigns them |
| 34 | * IDs. |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 35 | * The ResourceTable must already have IDs assigned to each resource. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 36 | * Once the ResourceTable is processed by this linker, it is ready to be |
| 37 | * flattened. |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 38 | */ |
| 39 | struct ReferenceLinker : public IResourceTableConsumer { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 40 | /** |
| 41 | * Returns true if the symbol is visible by the reference and from the |
| 42 | * callsite. |
| 43 | */ |
| 44 | static bool isSymbolVisible(const SymbolTable::Symbol& symbol, |
| 45 | const Reference& ref, const CallSite& callSite); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 46 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 47 | /** |
| 48 | * Performs name mangling and looks up the resource in the symbol table. |
| 49 | * Returns nullptr |
| 50 | * if the symbol was not found. |
| 51 | */ |
| 52 | static const SymbolTable::Symbol* resolveSymbol(const Reference& reference, |
| 53 | NameMangler* mangler, |
| 54 | SymbolTable* symbols); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 55 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 56 | /** |
| 57 | * Performs name mangling and looks up the resource in the symbol table. If |
| 58 | * the symbol is |
| 59 | * not visible by the reference at the callsite, nullptr is returned. outError |
| 60 | * holds |
| 61 | * the error message. |
| 62 | */ |
| 63 | static const SymbolTable::Symbol* resolveSymbolCheckVisibility( |
| 64 | const Reference& reference, NameMangler* nameMangler, |
| 65 | SymbolTable* symbols, CallSite* callSite, std::string* outError); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 66 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 67 | /** |
| 68 | * Same as resolveSymbolCheckVisibility(), but also makes sure the symbol is |
| 69 | * an attribute. |
| 70 | * That is, the return value will have a non-null value for |
| 71 | * ISymbolTable::Symbol::attribute. |
| 72 | */ |
| 73 | static const SymbolTable::Symbol* resolveAttributeCheckVisibility( |
| 74 | const Reference& reference, NameMangler* nameMangler, |
| 75 | SymbolTable* symbols, CallSite* callSite, std::string* outError); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 76 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 77 | /** |
| 78 | * Resolves the attribute reference and returns an xml::AaptAttribute if |
| 79 | * successful. |
| 80 | * If resolution fails, outError holds the error message. |
| 81 | */ |
| 82 | static Maybe<xml::AaptAttribute> compileXmlAttribute( |
| 83 | const Reference& reference, NameMangler* nameMangler, |
| 84 | SymbolTable* symbols, CallSite* callSite, std::string* outError); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 85 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 86 | /** |
| 87 | * Writes the resource name to the DiagMessage, using the "orig_name (aka |
| 88 | * <transformed_name>)" |
| 89 | * syntax. |
| 90 | */ |
| 91 | static void writeResourceName(DiagMessage* outMsg, const Reference& orig, |
| 92 | const Reference& transformed); |
Adam Lesinski | 28cacf0 | 2015-11-23 14:22:47 -0800 | [diff] [blame] | 93 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 94 | /** |
| 95 | * Transforms the package name of the reference to the fully qualified package |
| 96 | * name using |
| 97 | * the xml::IPackageDeclStack, then mangles and looks up the symbol. If the |
| 98 | * symbol is visible |
| 99 | * to the reference at the callsite, the reference is updated with an ID. |
| 100 | * Returns false on failure, and an error message is logged to the |
| 101 | * IDiagnostics in the context. |
| 102 | */ |
| 103 | static bool linkReference(Reference* reference, IAaptContext* context, |
| 104 | SymbolTable* symbols, xml::IPackageDeclStack* decls, |
| 105 | CallSite* callSite); |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 106 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 107 | /** |
| 108 | * Links all references in the ResourceTable. |
| 109 | */ |
| 110 | bool consume(IAaptContext* context, ResourceTable* table) override; |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame^] | 113 | } // namespace aapt |
Adam Lesinski | 467f171 | 2015-11-16 17:35:44 -0800 | [diff] [blame] | 114 | |
| 115 | #endif /* AAPT_LINKER_REFERENCELINKER_H */ |