diff --git a/tools/aapt2/.clang-format b/tools/aapt2/.clang-format new file mode 100644 index 0000000000000..71c5ef2fcda08 --- /dev/null +++ b/tools/aapt2/.clang-format @@ -0,0 +1,3 @@ +BasedOnStyle: Google +ColumnLimit: 100 + diff --git a/tools/aapt2/AppInfo.h b/tools/aapt2/AppInfo.h index a9794a419ca2c..2cbe117974406 100644 --- a/tools/aapt2/AppInfo.h +++ b/tools/aapt2/AppInfo.h @@ -28,27 +28,27 @@ namespace aapt { * will come from the app's AndroidManifest. */ struct AppInfo { - /** - * App's package name. - */ - std::string package; + /** + * App's package name. + */ + std::string package; - /** - * The App's minimum SDK version. - */ - Maybe minSdkVersion; + /** + * The App's minimum SDK version. + */ + Maybe minSdkVersion; - /** - * The Version code of the app. - */ - Maybe versionCode; + /** + * The Version code of the app. + */ + Maybe versionCode; - /** - * The revision code of the app. - */ - Maybe revisionCode; + /** + * The revision code of the app. + */ + Maybe revisionCode; }; -} // namespace aapt +} // namespace aapt -#endif // AAPT_APP_INFO_H +#endif // AAPT_APP_INFO_H diff --git a/tools/aapt2/ConfigDescription.cpp b/tools/aapt2/ConfigDescription.cpp index 1812d96a2ea37..6598d63882001 100644 --- a/tools/aapt2/ConfigDescription.cpp +++ b/tools/aapt2/ConfigDescription.cpp @@ -31,854 +31,869 @@ using android::ResTable_config; static const char* kWildcardName = "any"; const ConfigDescription& ConfigDescription::defaultConfig() { - static ConfigDescription config = {}; - return config; + static ConfigDescription config = {}; + return config; } static bool parseMcc(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->mcc = 0; - return true; - } - const char* c = name; - if (tolower(*c) != 'm') return false; - c++; - if (tolower(*c) != 'c') return false; - c++; - if (tolower(*c) != 'c') return false; + if (strcmp(name, kWildcardName) == 0) { + if (out) out->mcc = 0; + return true; + } + const char* c = name; + if (tolower(*c) != 'm') return false; + c++; + if (tolower(*c) != 'c') return false; + c++; + if (tolower(*c) != 'c') return false; + c++; + + const char* val = c; + + while (*c >= '0' && *c <= '9') { c++; + } + if (*c != 0) return false; + if (c - val != 3) return false; - const char* val = c; + int d = atoi(val); + if (d != 0) { + if (out) out->mcc = d; + return true; + } - while (*c >= '0' && *c <= '9') { - c++; - } - if (*c != 0) return false; - if (c-val != 3) return false; - - int d = atoi(val); - if (d != 0) { - if (out) out->mcc = d; - return true; - } - - return false; + return false; } static bool parseMnc(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->mcc = 0; - return true; - } - const char* c = name; - if (tolower(*c) != 'm') return false; - c++; - if (tolower(*c) != 'n') return false; - c++; - if (tolower(*c) != 'c') return false; - c++; - - const char* val = c; - - while (*c >= '0' && *c <= '9') { - c++; - } - if (*c != 0) return false; - if (c-val == 0 || c-val > 3) return false; - - if (out) { - out->mnc = atoi(val); - if (out->mnc == 0) { - out->mnc = ACONFIGURATION_MNC_ZERO; - } - } - + if (strcmp(name, kWildcardName) == 0) { + if (out) out->mcc = 0; return true; + } + const char* c = name; + if (tolower(*c) != 'm') return false; + c++; + if (tolower(*c) != 'n') return false; + c++; + if (tolower(*c) != 'c') return false; + c++; + + const char* val = c; + + while (*c >= '0' && *c <= '9') { + c++; + } + if (*c != 0) return false; + if (c - val == 0 || c - val > 3) return false; + + if (out) { + out->mnc = atoi(val); + if (out->mnc == 0) { + out->mnc = ACONFIGURATION_MNC_ZERO; + } + } + + return true; } static bool parseLayoutDirection(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_LAYOUTDIR) - | ResTable_config::LAYOUTDIR_ANY; - return true; - } else if (strcmp(name, "ldltr") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_LAYOUTDIR) - | ResTable_config::LAYOUTDIR_LTR; - return true; - } else if (strcmp(name, "ldrtl") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_LAYOUTDIR) - | ResTable_config::LAYOUTDIR_RTL; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_LAYOUTDIR) | + ResTable_config::LAYOUTDIR_ANY; + return true; + } else if (strcmp(name, "ldltr") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_LAYOUTDIR) | + ResTable_config::LAYOUTDIR_LTR; + return true; + } else if (strcmp(name, "ldrtl") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_LAYOUTDIR) | + ResTable_config::LAYOUTDIR_RTL; + return true; + } - return false; + return false; } static bool parseScreenLayoutSize(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENSIZE) - | ResTable_config::SCREENSIZE_ANY; - return true; - } else if (strcmp(name, "small") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENSIZE) - | ResTable_config::SCREENSIZE_SMALL; - return true; - } else if (strcmp(name, "normal") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENSIZE) - | ResTable_config::SCREENSIZE_NORMAL; - return true; - } else if (strcmp(name, "large") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENSIZE) - | ResTable_config::SCREENSIZE_LARGE; - return true; - } else if (strcmp(name, "xlarge") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENSIZE) - | ResTable_config::SCREENSIZE_XLARGE; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENSIZE) | + ResTable_config::SCREENSIZE_ANY; + return true; + } else if (strcmp(name, "small") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENSIZE) | + ResTable_config::SCREENSIZE_SMALL; + return true; + } else if (strcmp(name, "normal") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENSIZE) | + ResTable_config::SCREENSIZE_NORMAL; + return true; + } else if (strcmp(name, "large") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENSIZE) | + ResTable_config::SCREENSIZE_LARGE; + return true; + } else if (strcmp(name, "xlarge") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENSIZE) | + ResTable_config::SCREENSIZE_XLARGE; + return true; + } - return false; + return false; } static bool parseScreenLayoutLong(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENLONG) - | ResTable_config::SCREENLONG_ANY; - return true; - } else if (strcmp(name, "long") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENLONG) - | ResTable_config::SCREENLONG_YES; - return true; - } else if (strcmp(name, "notlong") == 0) { - if (out) out->screenLayout = - (out->screenLayout&~ResTable_config::MASK_SCREENLONG) - | ResTable_config::SCREENLONG_NO; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENLONG) | + ResTable_config::SCREENLONG_ANY; + return true; + } else if (strcmp(name, "long") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENLONG) | + ResTable_config::SCREENLONG_YES; + return true; + } else if (strcmp(name, "notlong") == 0) { + if (out) + out->screenLayout = + (out->screenLayout & ~ResTable_config::MASK_SCREENLONG) | + ResTable_config::SCREENLONG_NO; + return true; + } - return false; + return false; } static bool parseScreenRound(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->screenLayout2 = - (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) - | ResTable_config::SCREENROUND_ANY; - return true; - } else if (strcmp(name, "round") == 0) { - if (out) out->screenLayout2 = - (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) - | ResTable_config::SCREENROUND_YES; - return true; - } else if (strcmp(name, "notround") == 0) { - if (out) out->screenLayout2 = - (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) - | ResTable_config::SCREENROUND_NO; - return true; - } - return false; + if (strcmp(name, kWildcardName) == 0) { + if (out) + out->screenLayout2 = + (out->screenLayout2 & ~ResTable_config::MASK_SCREENROUND) | + ResTable_config::SCREENROUND_ANY; + return true; + } else if (strcmp(name, "round") == 0) { + if (out) + out->screenLayout2 = + (out->screenLayout2 & ~ResTable_config::MASK_SCREENROUND) | + ResTable_config::SCREENROUND_YES; + return true; + } else if (strcmp(name, "notround") == 0) { + if (out) + out->screenLayout2 = + (out->screenLayout2 & ~ResTable_config::MASK_SCREENROUND) | + ResTable_config::SCREENROUND_NO; + return true; + } + return false; } static bool parseOrientation(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->orientation = out->ORIENTATION_ANY; - return true; - } else if (strcmp(name, "port") == 0) { - if (out) out->orientation = out->ORIENTATION_PORT; - return true; - } else if (strcmp(name, "land") == 0) { - if (out) out->orientation = out->ORIENTATION_LAND; - return true; - } else if (strcmp(name, "square") == 0) { - if (out) out->orientation = out->ORIENTATION_SQUARE; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) out->orientation = out->ORIENTATION_ANY; + return true; + } else if (strcmp(name, "port") == 0) { + if (out) out->orientation = out->ORIENTATION_PORT; + return true; + } else if (strcmp(name, "land") == 0) { + if (out) out->orientation = out->ORIENTATION_LAND; + return true; + } else if (strcmp(name, "square") == 0) { + if (out) out->orientation = out->ORIENTATION_SQUARE; + return true; + } - return false; + return false; } static bool parseUiModeType(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE) - | ResTable_config::UI_MODE_TYPE_ANY; - return true; - } else if (strcmp(name, "desk") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE) - | ResTable_config::UI_MODE_TYPE_DESK; - return true; - } else if (strcmp(name, "car") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE) - | ResTable_config::UI_MODE_TYPE_CAR; - return true; - } else if (strcmp(name, "television") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE) - | ResTable_config::UI_MODE_TYPE_TELEVISION; - return true; - } else if (strcmp(name, "appliance") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE) - | ResTable_config::UI_MODE_TYPE_APPLIANCE; - return true; - } else if (strcmp(name, "watch") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_TYPE) - | ResTable_config::UI_MODE_TYPE_WATCH; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) | + ResTable_config::UI_MODE_TYPE_ANY; + return true; + } else if (strcmp(name, "desk") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) | + ResTable_config::UI_MODE_TYPE_DESK; + return true; + } else if (strcmp(name, "car") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) | + ResTable_config::UI_MODE_TYPE_CAR; + return true; + } else if (strcmp(name, "television") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) | + ResTable_config::UI_MODE_TYPE_TELEVISION; + return true; + } else if (strcmp(name, "appliance") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) | + ResTable_config::UI_MODE_TYPE_APPLIANCE; + return true; + } else if (strcmp(name, "watch") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_TYPE) | + ResTable_config::UI_MODE_TYPE_WATCH; + return true; + } - return false; + return false; } static bool parseUiModeNight(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_NIGHT) - | ResTable_config::UI_MODE_NIGHT_ANY; - return true; - } else if (strcmp(name, "night") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_NIGHT) - | ResTable_config::UI_MODE_NIGHT_YES; - return true; - } else if (strcmp(name, "notnight") == 0) { - if (out) out->uiMode = - (out->uiMode&~ResTable_config::MASK_UI_MODE_NIGHT) - | ResTable_config::UI_MODE_NIGHT_NO; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_NIGHT) | + ResTable_config::UI_MODE_NIGHT_ANY; + return true; + } else if (strcmp(name, "night") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_NIGHT) | + ResTable_config::UI_MODE_NIGHT_YES; + return true; + } else if (strcmp(name, "notnight") == 0) { + if (out) + out->uiMode = (out->uiMode & ~ResTable_config::MASK_UI_MODE_NIGHT) | + ResTable_config::UI_MODE_NIGHT_NO; + return true; + } - return false; + return false; } static bool parseDensity(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->density = ResTable_config::DENSITY_DEFAULT; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) out->density = ResTable_config::DENSITY_DEFAULT; + return true; + } - if (strcmp(name, "anydpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_ANY; - return true; - } + if (strcmp(name, "anydpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_ANY; + return true; + } - if (strcmp(name, "nodpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_NONE; - return true; - } + if (strcmp(name, "nodpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_NONE; + return true; + } - if (strcmp(name, "ldpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_LOW; - return true; - } + if (strcmp(name, "ldpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_LOW; + return true; + } - if (strcmp(name, "mdpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_MEDIUM; - return true; - } + if (strcmp(name, "mdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_MEDIUM; + return true; + } - if (strcmp(name, "tvdpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_TV; - return true; - } + if (strcmp(name, "tvdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_TV; + return true; + } - if (strcmp(name, "hdpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_HIGH; - return true; - } + if (strcmp(name, "hdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_HIGH; + return true; + } - if (strcmp(name, "xhdpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_XHIGH; - return true; - } + if (strcmp(name, "xhdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_XHIGH; + return true; + } - if (strcmp(name, "xxhdpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_XXHIGH; - return true; - } + if (strcmp(name, "xxhdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_XXHIGH; + return true; + } - if (strcmp(name, "xxxhdpi") == 0) { - if (out) out->density = ResTable_config::DENSITY_XXXHIGH; - return true; - } + if (strcmp(name, "xxxhdpi") == 0) { + if (out) out->density = ResTable_config::DENSITY_XXXHIGH; + return true; + } - char* c = (char*)name; - while (*c >= '0' && *c <= '9') { - c++; - } - - // check that we have 'dpi' after the last digit. - if (toupper(c[0]) != 'D' || - toupper(c[1]) != 'P' || - toupper(c[2]) != 'I' || - c[3] != 0) { - return false; - } - - // temporarily replace the first letter with \0 to - // use atoi. - char tmp = c[0]; - c[0] = '\0'; - - int d = atoi(name); - c[0] = tmp; - - if (d != 0) { - if (out) out->density = d; - return true; - } + char* c = (char*)name; + while (*c >= '0' && *c <= '9') { + c++; + } + // check that we have 'dpi' after the last digit. + if (toupper(c[0]) != 'D' || toupper(c[1]) != 'P' || toupper(c[2]) != 'I' || + c[3] != 0) { return false; + } + + // temporarily replace the first letter with \0 to + // use atoi. + char tmp = c[0]; + c[0] = '\0'; + + int d = atoi(name); + c[0] = tmp; + + if (d != 0) { + if (out) out->density = d; + return true; + } + + return false; } static bool parseTouchscreen(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->touchscreen = out->TOUCHSCREEN_ANY; - return true; - } else if (strcmp(name, "notouch") == 0) { - if (out) out->touchscreen = out->TOUCHSCREEN_NOTOUCH; - return true; - } else if (strcmp(name, "stylus") == 0) { - if (out) out->touchscreen = out->TOUCHSCREEN_STYLUS; - return true; - } else if (strcmp(name, "finger") == 0) { - if (out) out->touchscreen = out->TOUCHSCREEN_FINGER; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) out->touchscreen = out->TOUCHSCREEN_ANY; + return true; + } else if (strcmp(name, "notouch") == 0) { + if (out) out->touchscreen = out->TOUCHSCREEN_NOTOUCH; + return true; + } else if (strcmp(name, "stylus") == 0) { + if (out) out->touchscreen = out->TOUCHSCREEN_STYLUS; + return true; + } else if (strcmp(name, "finger") == 0) { + if (out) out->touchscreen = out->TOUCHSCREEN_FINGER; + return true; + } - return false; + return false; } static bool parseKeysHidden(const char* name, ResTable_config* out) { - uint8_t mask = 0; - uint8_t value = 0; - if (strcmp(name, kWildcardName) == 0) { - mask = ResTable_config::MASK_KEYSHIDDEN; - value = ResTable_config::KEYSHIDDEN_ANY; - } else if (strcmp(name, "keysexposed") == 0) { - mask = ResTable_config::MASK_KEYSHIDDEN; - value = ResTable_config::KEYSHIDDEN_NO; - } else if (strcmp(name, "keyshidden") == 0) { - mask = ResTable_config::MASK_KEYSHIDDEN; - value = ResTable_config::KEYSHIDDEN_YES; - } else if (strcmp(name, "keyssoft") == 0) { - mask = ResTable_config::MASK_KEYSHIDDEN; - value = ResTable_config::KEYSHIDDEN_SOFT; - } + uint8_t mask = 0; + uint8_t value = 0; + if (strcmp(name, kWildcardName) == 0) { + mask = ResTable_config::MASK_KEYSHIDDEN; + value = ResTable_config::KEYSHIDDEN_ANY; + } else if (strcmp(name, "keysexposed") == 0) { + mask = ResTable_config::MASK_KEYSHIDDEN; + value = ResTable_config::KEYSHIDDEN_NO; + } else if (strcmp(name, "keyshidden") == 0) { + mask = ResTable_config::MASK_KEYSHIDDEN; + value = ResTable_config::KEYSHIDDEN_YES; + } else if (strcmp(name, "keyssoft") == 0) { + mask = ResTable_config::MASK_KEYSHIDDEN; + value = ResTable_config::KEYSHIDDEN_SOFT; + } - if (mask != 0) { - if (out) out->inputFlags = (out->inputFlags&~mask) | value; - return true; - } + if (mask != 0) { + if (out) out->inputFlags = (out->inputFlags & ~mask) | value; + return true; + } - return false; + return false; } static bool parseKeyboard(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->keyboard = out->KEYBOARD_ANY; - return true; - } else if (strcmp(name, "nokeys") == 0) { - if (out) out->keyboard = out->KEYBOARD_NOKEYS; - return true; - } else if (strcmp(name, "qwerty") == 0) { - if (out) out->keyboard = out->KEYBOARD_QWERTY; - return true; - } else if (strcmp(name, "12key") == 0) { - if (out) out->keyboard = out->KEYBOARD_12KEY; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) out->keyboard = out->KEYBOARD_ANY; + return true; + } else if (strcmp(name, "nokeys") == 0) { + if (out) out->keyboard = out->KEYBOARD_NOKEYS; + return true; + } else if (strcmp(name, "qwerty") == 0) { + if (out) out->keyboard = out->KEYBOARD_QWERTY; + return true; + } else if (strcmp(name, "12key") == 0) { + if (out) out->keyboard = out->KEYBOARD_12KEY; + return true; + } - return false; + return false; } static bool parseNavHidden(const char* name, ResTable_config* out) { - uint8_t mask = 0; - uint8_t value = 0; - if (strcmp(name, kWildcardName) == 0) { - mask = ResTable_config::MASK_NAVHIDDEN; - value = ResTable_config::NAVHIDDEN_ANY; - } else if (strcmp(name, "navexposed") == 0) { - mask = ResTable_config::MASK_NAVHIDDEN; - value = ResTable_config::NAVHIDDEN_NO; - } else if (strcmp(name, "navhidden") == 0) { - mask = ResTable_config::MASK_NAVHIDDEN; - value = ResTable_config::NAVHIDDEN_YES; - } + uint8_t mask = 0; + uint8_t value = 0; + if (strcmp(name, kWildcardName) == 0) { + mask = ResTable_config::MASK_NAVHIDDEN; + value = ResTable_config::NAVHIDDEN_ANY; + } else if (strcmp(name, "navexposed") == 0) { + mask = ResTable_config::MASK_NAVHIDDEN; + value = ResTable_config::NAVHIDDEN_NO; + } else if (strcmp(name, "navhidden") == 0) { + mask = ResTable_config::MASK_NAVHIDDEN; + value = ResTable_config::NAVHIDDEN_YES; + } - if (mask != 0) { - if (out) out->inputFlags = (out->inputFlags&~mask) | value; - return true; - } + if (mask != 0) { + if (out) out->inputFlags = (out->inputFlags & ~mask) | value; + return true; + } - return false; + return false; } static bool parseNavigation(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) out->navigation = out->NAVIGATION_ANY; - return true; - } else if (strcmp(name, "nonav") == 0) { - if (out) out->navigation = out->NAVIGATION_NONAV; - return true; - } else if (strcmp(name, "dpad") == 0) { - if (out) out->navigation = out->NAVIGATION_DPAD; - return true; - } else if (strcmp(name, "trackball") == 0) { - if (out) out->navigation = out->NAVIGATION_TRACKBALL; - return true; - } else if (strcmp(name, "wheel") == 0) { - if (out) out->navigation = out->NAVIGATION_WHEEL; - return true; - } + if (strcmp(name, kWildcardName) == 0) { + if (out) out->navigation = out->NAVIGATION_ANY; + return true; + } else if (strcmp(name, "nonav") == 0) { + if (out) out->navigation = out->NAVIGATION_NONAV; + return true; + } else if (strcmp(name, "dpad") == 0) { + if (out) out->navigation = out->NAVIGATION_DPAD; + return true; + } else if (strcmp(name, "trackball") == 0) { + if (out) out->navigation = out->NAVIGATION_TRACKBALL; + return true; + } else if (strcmp(name, "wheel") == 0) { + if (out) out->navigation = out->NAVIGATION_WHEEL; + return true; + } - return false; + return false; } static bool parseScreenSize(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) { - out->screenWidth = out->SCREENWIDTH_ANY; - out->screenHeight = out->SCREENHEIGHT_ANY; - } - return true; - } - - const char* x = name; - while (*x >= '0' && *x <= '9') x++; - if (x == name || *x != 'x') return false; - std::string xName(name, x-name); - x++; - - const char* y = x; - while (*y >= '0' && *y <= '9') y++; - if (y == name || *y != 0) return false; - std::string yName(x, y-x); - - uint16_t w = (uint16_t)atoi(xName.c_str()); - uint16_t h = (uint16_t)atoi(yName.c_str()); - if (w < h) { - return false; - } - + if (strcmp(name, kWildcardName) == 0) { if (out) { - out->screenWidth = w; - out->screenHeight = h; + out->screenWidth = out->SCREENWIDTH_ANY; + out->screenHeight = out->SCREENHEIGHT_ANY; } - return true; + } + + const char* x = name; + while (*x >= '0' && *x <= '9') x++; + if (x == name || *x != 'x') return false; + std::string xName(name, x - name); + x++; + + const char* y = x; + while (*y >= '0' && *y <= '9') y++; + if (y == name || *y != 0) return false; + std::string yName(x, y - x); + + uint16_t w = (uint16_t)atoi(xName.c_str()); + uint16_t h = (uint16_t)atoi(yName.c_str()); + if (w < h) { + return false; + } + + if (out) { + out->screenWidth = w; + out->screenHeight = h; + } + + return true; } static bool parseSmallestScreenWidthDp(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) { - out->smallestScreenWidthDp = out->SCREENWIDTH_ANY; - } - return true; - } - - if (*name != 's') return false; - name++; - if (*name != 'w') return false; - name++; - const char* x = name; - while (*x >= '0' && *x <= '9') x++; - if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false; - std::string xName(name, x-name); - + if (strcmp(name, kWildcardName) == 0) { if (out) { - out->smallestScreenWidthDp = (uint16_t)atoi(xName.c_str()); + out->smallestScreenWidthDp = out->SCREENWIDTH_ANY; } - return true; + } + + if (*name != 's') return false; + name++; + if (*name != 'w') return false; + name++; + const char* x = name; + while (*x >= '0' && *x <= '9') x++; + if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false; + std::string xName(name, x - name); + + if (out) { + out->smallestScreenWidthDp = (uint16_t)atoi(xName.c_str()); + } + + return true; } static bool parseScreenWidthDp(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) { - out->screenWidthDp = out->SCREENWIDTH_ANY; - } - return true; - } - - if (*name != 'w') return false; - name++; - const char* x = name; - while (*x >= '0' && *x <= '9') x++; - if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false; - std::string xName(name, x-name); - + if (strcmp(name, kWildcardName) == 0) { if (out) { - out->screenWidthDp = (uint16_t)atoi(xName.c_str()); + out->screenWidthDp = out->SCREENWIDTH_ANY; } - return true; + } + + if (*name != 'w') return false; + name++; + const char* x = name; + while (*x >= '0' && *x <= '9') x++; + if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false; + std::string xName(name, x - name); + + if (out) { + out->screenWidthDp = (uint16_t)atoi(xName.c_str()); + } + + return true; } static bool parseScreenHeightDp(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) { - out->screenHeightDp = out->SCREENWIDTH_ANY; - } - return true; - } - - if (*name != 'h') return false; - name++; - const char* x = name; - while (*x >= '0' && *x <= '9') x++; - if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false; - std::string xName(name, x-name); - + if (strcmp(name, kWildcardName) == 0) { if (out) { - out->screenHeightDp = (uint16_t)atoi(xName.c_str()); + out->screenHeightDp = out->SCREENWIDTH_ANY; } - return true; + } + + if (*name != 'h') return false; + name++; + const char* x = name; + while (*x >= '0' && *x <= '9') x++; + if (x == name || x[0] != 'd' || x[1] != 'p' || x[2] != 0) return false; + std::string xName(name, x - name); + + if (out) { + out->screenHeightDp = (uint16_t)atoi(xName.c_str()); + } + + return true; } static bool parseVersion(const char* name, ResTable_config* out) { - if (strcmp(name, kWildcardName) == 0) { - if (out) { - out->sdkVersion = out->SDKVERSION_ANY; - out->minorVersion = out->MINORVERSION_ANY; - } - return true; - } - - if (*name != 'v') { - return false; - } - - name++; - const char* s = name; - while (*s >= '0' && *s <= '9') s++; - if (s == name || *s != 0) return false; - std::string sdkName(name, s-name); - + if (strcmp(name, kWildcardName) == 0) { if (out) { - out->sdkVersion = (uint16_t)atoi(sdkName.c_str()); - out->minorVersion = 0; + out->sdkVersion = out->SDKVERSION_ANY; + out->minorVersion = out->MINORVERSION_ANY; } - return true; + } + + if (*name != 'v') { + return false; + } + + name++; + const char* s = name; + while (*s >= '0' && *s <= '9') s++; + if (s == name || *s != 0) return false; + std::string sdkName(name, s - name); + + if (out) { + out->sdkVersion = (uint16_t)atoi(sdkName.c_str()); + out->minorVersion = 0; + } + + return true; } bool ConfigDescription::parse(const StringPiece& str, ConfigDescription* out) { - std::vector parts = util::splitAndLowercase(str, '-'); + std::vector parts = util::splitAndLowercase(str, '-'); - ConfigDescription config; - ssize_t partsConsumed = 0; - LocaleValue locale; + ConfigDescription config; + ssize_t partsConsumed = 0; + LocaleValue locale; - const auto partsEnd = parts.end(); - auto partIter = parts.begin(); + const auto partsEnd = parts.end(); + auto partIter = parts.begin(); - if (str.size() == 0) { - goto success; + if (str.size() == 0) { + goto success; + } + + if (parseMcc(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; } + } - if (parseMcc(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } + if (parseMnc(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; } + } - if (parseMnc(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - // Locale spans a few '-' separators, so we let it - // control the index. - partsConsumed = locale.initFromParts(partIter, partsEnd); - if (partsConsumed < 0) { - return false; - } else { - locale.writeTo(&config); - partIter += partsConsumed; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseLayoutDirection(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseSmallestScreenWidthDp(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseScreenWidthDp(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseScreenHeightDp(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseScreenLayoutSize(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseScreenLayoutLong(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseScreenRound(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseOrientation(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseUiModeType(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseUiModeNight(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseDensity(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseTouchscreen(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseKeysHidden(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseKeyboard(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseNavHidden(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseNavigation(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseScreenSize(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - if (parseVersion(partIter->c_str(), &config)) { - ++partIter; - if (partIter == partsEnd) { - goto success; - } - } - - // Unrecognized. + // Locale spans a few '-' separators, so we let it + // control the index. + partsConsumed = locale.initFromParts(partIter, partsEnd); + if (partsConsumed < 0) { return false; + } else { + locale.writeTo(&config); + partIter += partsConsumed; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseLayoutDirection(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseSmallestScreenWidthDp(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseScreenWidthDp(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseScreenHeightDp(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseScreenLayoutSize(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseScreenLayoutLong(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseScreenRound(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseOrientation(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseUiModeType(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseUiModeNight(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseDensity(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseTouchscreen(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseKeysHidden(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseKeyboard(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseNavHidden(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseNavigation(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseScreenSize(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + if (parseVersion(partIter->c_str(), &config)) { + ++partIter; + if (partIter == partsEnd) { + goto success; + } + } + + // Unrecognized. + return false; success: - if (out != NULL) { - applyVersionForCompatibility(&config); - *out = config; - } - return true; + if (out != NULL) { + applyVersionForCompatibility(&config); + *out = config; + } + return true; } -void ConfigDescription::applyVersionForCompatibility(ConfigDescription* config) { - uint16_t minSdk = 0; - if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) { - minSdk = SDK_MARSHMALLOW; - } else if (config->density == ResTable_config::DENSITY_ANY) { - minSdk = SDK_LOLLIPOP; - } else if (config->smallestScreenWidthDp != ResTable_config::SCREENWIDTH_ANY - || config->screenWidthDp != ResTable_config::SCREENWIDTH_ANY - || config->screenHeightDp != ResTable_config::SCREENHEIGHT_ANY) { - minSdk = SDK_HONEYCOMB_MR2; - } else if ((config->uiMode & ResTable_config::MASK_UI_MODE_TYPE) - != ResTable_config::UI_MODE_TYPE_ANY - || (config->uiMode & ResTable_config::MASK_UI_MODE_NIGHT) - != ResTable_config::UI_MODE_NIGHT_ANY) { - minSdk = SDK_FROYO; - } else if ((config->screenLayout & ResTable_config::MASK_SCREENSIZE) - != ResTable_config::SCREENSIZE_ANY - || (config->screenLayout & ResTable_config::MASK_SCREENLONG) - != ResTable_config::SCREENLONG_ANY - || config->density != ResTable_config::DENSITY_DEFAULT) { - minSdk = SDK_DONUT; - } +void ConfigDescription::applyVersionForCompatibility( + ConfigDescription* config) { + uint16_t minSdk = 0; + if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) { + minSdk = SDK_MARSHMALLOW; + } else if (config->density == ResTable_config::DENSITY_ANY) { + minSdk = SDK_LOLLIPOP; + } else if (config->smallestScreenWidthDp != + ResTable_config::SCREENWIDTH_ANY || + config->screenWidthDp != ResTable_config::SCREENWIDTH_ANY || + config->screenHeightDp != ResTable_config::SCREENHEIGHT_ANY) { + minSdk = SDK_HONEYCOMB_MR2; + } else if ((config->uiMode & ResTable_config::MASK_UI_MODE_TYPE) != + ResTable_config::UI_MODE_TYPE_ANY || + (config->uiMode & ResTable_config::MASK_UI_MODE_NIGHT) != + ResTable_config::UI_MODE_NIGHT_ANY) { + minSdk = SDK_FROYO; + } else if ((config->screenLayout & ResTable_config::MASK_SCREENSIZE) != + ResTable_config::SCREENSIZE_ANY || + (config->screenLayout & ResTable_config::MASK_SCREENLONG) != + ResTable_config::SCREENLONG_ANY || + config->density != ResTable_config::DENSITY_DEFAULT) { + minSdk = SDK_DONUT; + } - if (minSdk > config->sdkVersion) { - config->sdkVersion = minSdk; - } + if (minSdk > config->sdkVersion) { + config->sdkVersion = minSdk; + } } ConfigDescription ConfigDescription::copyWithoutSdkVersion() const { - ConfigDescription copy = *this; - copy.sdkVersion = 0; - return copy; + ConfigDescription copy = *this; + copy.sdkVersion = 0; + return copy; } bool ConfigDescription::dominates(const ConfigDescription& o) const { - if (*this == defaultConfig() || *this == o) { - return true; - } - return matchWithDensity(o) - && !o.matchWithDensity(*this) - && !isMoreSpecificThan(o) - && !o.hasHigherPrecedenceThan(*this); + if (*this == defaultConfig() || *this == o) { + return true; + } + return matchWithDensity(o) && !o.matchWithDensity(*this) && + !isMoreSpecificThan(o) && !o.hasHigherPrecedenceThan(*this); } -bool ConfigDescription::hasHigherPrecedenceThan(const ConfigDescription& o) const { - // The order of the following tests defines the importance of one - // configuration parameter over another. Those tests first are more - // important, trumping any values in those following them. - // The ordering should be the same as ResTable_config#isBetterThan. - if (mcc || o.mcc) return (!o.mcc); - if (mnc || o.mnc) return (!o.mnc); - if (language[0] || o.language[0]) return (!o.language[0]); - if (country[0] || o.country[0]) return (!o.country[0]); - // Script and variant require either a language or country, both of which - // have higher precedence. - if ((screenLayout | o.screenLayout) & MASK_LAYOUTDIR) { - return !(o.screenLayout & MASK_LAYOUTDIR); - } - if (smallestScreenWidthDp || o.smallestScreenWidthDp) return (!o.smallestScreenWidthDp); - if (screenWidthDp || o.screenWidthDp) return (!o.screenWidthDp); - if (screenHeightDp || o.screenHeightDp) return (!o.screenHeightDp); - if ((screenLayout | o.screenLayout) & MASK_SCREENSIZE) { - return !(o.screenLayout & MASK_SCREENSIZE); - } - if ((screenLayout | o.screenLayout) & MASK_SCREENLONG) { - return !(o.screenLayout & MASK_SCREENLONG); - } - if ((screenLayout2 | o.screenLayout2) & MASK_SCREENROUND) { - return !(o.screenLayout2 & MASK_SCREENROUND); - } - if (orientation || o.orientation) return (!o.orientation); - if ((uiMode | o.uiMode) & MASK_UI_MODE_TYPE) { - return !(o.uiMode & MASK_UI_MODE_TYPE); - } - if ((uiMode | o.uiMode) & MASK_UI_MODE_NIGHT) { - return !(o.uiMode & MASK_UI_MODE_NIGHT); - } - if (density || o.density) return (!o.density); - if (touchscreen || o.touchscreen) return (!o.touchscreen); - if ((inputFlags | o.inputFlags) & MASK_KEYSHIDDEN) { - return !(o.inputFlags & MASK_KEYSHIDDEN); - } - if ((inputFlags | o.inputFlags) & MASK_NAVHIDDEN) { - return !(o.inputFlags & MASK_NAVHIDDEN); - } - if (keyboard || o.keyboard) return (!o.keyboard); - if (navigation || o.navigation) return (!o.navigation); - if (screenWidth || o.screenWidth) return (!o.screenWidth); - if (screenHeight || o.screenHeight) return (!o.screenHeight); - if (sdkVersion || o.sdkVersion) return (!o.sdkVersion); - if (minorVersion || o.minorVersion) return (!o.minorVersion); - // Both configurations have nothing defined except some possible future - // value. Returning the comparison of the two configurations is a - // "best effort" at this point to protect against incorrect dominations. - return *this != o; +bool ConfigDescription::hasHigherPrecedenceThan( + const ConfigDescription& o) const { + // The order of the following tests defines the importance of one + // configuration parameter over another. Those tests first are more + // important, trumping any values in those following them. + // The ordering should be the same as ResTable_config#isBetterThan. + if (mcc || o.mcc) return (!o.mcc); + if (mnc || o.mnc) return (!o.mnc); + if (language[0] || o.language[0]) return (!o.language[0]); + if (country[0] || o.country[0]) return (!o.country[0]); + // Script and variant require either a language or country, both of which + // have higher precedence. + if ((screenLayout | o.screenLayout) & MASK_LAYOUTDIR) { + return !(o.screenLayout & MASK_LAYOUTDIR); + } + if (smallestScreenWidthDp || o.smallestScreenWidthDp) + return (!o.smallestScreenWidthDp); + if (screenWidthDp || o.screenWidthDp) return (!o.screenWidthDp); + if (screenHeightDp || o.screenHeightDp) return (!o.screenHeightDp); + if ((screenLayout | o.screenLayout) & MASK_SCREENSIZE) { + return !(o.screenLayout & MASK_SCREENSIZE); + } + if ((screenLayout | o.screenLayout) & MASK_SCREENLONG) { + return !(o.screenLayout & MASK_SCREENLONG); + } + if ((screenLayout2 | o.screenLayout2) & MASK_SCREENROUND) { + return !(o.screenLayout2 & MASK_SCREENROUND); + } + if (orientation || o.orientation) return (!o.orientation); + if ((uiMode | o.uiMode) & MASK_UI_MODE_TYPE) { + return !(o.uiMode & MASK_UI_MODE_TYPE); + } + if ((uiMode | o.uiMode) & MASK_UI_MODE_NIGHT) { + return !(o.uiMode & MASK_UI_MODE_NIGHT); + } + if (density || o.density) return (!o.density); + if (touchscreen || o.touchscreen) return (!o.touchscreen); + if ((inputFlags | o.inputFlags) & MASK_KEYSHIDDEN) { + return !(o.inputFlags & MASK_KEYSHIDDEN); + } + if ((inputFlags | o.inputFlags) & MASK_NAVHIDDEN) { + return !(o.inputFlags & MASK_NAVHIDDEN); + } + if (keyboard || o.keyboard) return (!o.keyboard); + if (navigation || o.navigation) return (!o.navigation); + if (screenWidth || o.screenWidth) return (!o.screenWidth); + if (screenHeight || o.screenHeight) return (!o.screenHeight); + if (sdkVersion || o.sdkVersion) return (!o.sdkVersion); + if (minorVersion || o.minorVersion) return (!o.minorVersion); + // Both configurations have nothing defined except some possible future + // value. Returning the comparison of the two configurations is a + // "best effort" at this point to protect against incorrect dominations. + return *this != o; } bool ConfigDescription::conflictsWith(const ConfigDescription& o) const { - // This method should be updated as new configuration parameters are - // introduced (e.g. screenConfig2). - auto pred = [](const uint32_t a, const uint32_t b) -> bool { - return a == 0 || b == 0 || a == b; - }; - // The values here can be found in ResTable_config#match. Density and range - // values can't lead to conflicts, and are ignored. - return !pred(mcc, o.mcc) - || !pred(mnc, o.mnc) - || !pred(locale, o.locale) - || !pred(screenLayout & MASK_LAYOUTDIR, o.screenLayout & MASK_LAYOUTDIR) - || !pred(screenLayout & MASK_SCREENLONG, o.screenLayout & MASK_SCREENLONG) - || !pred(screenLayout & MASK_UI_MODE_TYPE, o.screenLayout & MASK_UI_MODE_TYPE) - || !pred(uiMode & MASK_UI_MODE_TYPE, o.uiMode & MASK_UI_MODE_TYPE) - || !pred(uiMode & MASK_UI_MODE_NIGHT, o.uiMode & MASK_UI_MODE_NIGHT) - || !pred(screenLayout2 & MASK_SCREENROUND, o.screenLayout2 & MASK_SCREENROUND) - || !pred(orientation, o.orientation) - || !pred(touchscreen, o.touchscreen) - || !pred(inputFlags & MASK_KEYSHIDDEN, o.inputFlags & MASK_KEYSHIDDEN) - || !pred(inputFlags & MASK_NAVHIDDEN, o.inputFlags & MASK_NAVHIDDEN) - || !pred(keyboard, o.keyboard) - || !pred(navigation, o.navigation); + // This method should be updated as new configuration parameters are + // introduced (e.g. screenConfig2). + auto pred = [](const uint32_t a, const uint32_t b) -> bool { + return a == 0 || b == 0 || a == b; + }; + // The values here can be found in ResTable_config#match. Density and range + // values can't lead to conflicts, and are ignored. + return !pred(mcc, o.mcc) || !pred(mnc, o.mnc) || !pred(locale, o.locale) || + !pred(screenLayout & MASK_LAYOUTDIR, + o.screenLayout & MASK_LAYOUTDIR) || + !pred(screenLayout & MASK_SCREENLONG, + o.screenLayout & MASK_SCREENLONG) || + !pred(screenLayout & MASK_UI_MODE_TYPE, + o.screenLayout & MASK_UI_MODE_TYPE) || + !pred(uiMode & MASK_UI_MODE_TYPE, o.uiMode & MASK_UI_MODE_TYPE) || + !pred(uiMode & MASK_UI_MODE_NIGHT, o.uiMode & MASK_UI_MODE_NIGHT) || + !pred(screenLayout2 & MASK_SCREENROUND, + o.screenLayout2 & MASK_SCREENROUND) || + !pred(orientation, o.orientation) || + !pred(touchscreen, o.touchscreen) || + !pred(inputFlags & MASK_KEYSHIDDEN, o.inputFlags & MASK_KEYSHIDDEN) || + !pred(inputFlags & MASK_NAVHIDDEN, o.inputFlags & MASK_NAVHIDDEN) || + !pred(keyboard, o.keyboard) || !pred(navigation, o.navigation); } bool ConfigDescription::isCompatibleWith(const ConfigDescription& o) const { - return !conflictsWith(o) && !dominates(o) && !o.dominates(*this); + return !conflictsWith(o) && !dominates(o) && !o.dominates(*this); } -} // namespace aapt +} // namespace aapt diff --git a/tools/aapt2/ConfigDescription.h b/tools/aapt2/ConfigDescription.h index d8016210d4a7b..bb54886739753 100644 --- a/tools/aapt2/ConfigDescription.h +++ b/tools/aapt2/ConfigDescription.h @@ -29,148 +29,152 @@ namespace aapt { * initialization and comparison methods. */ struct ConfigDescription : public android::ResTable_config { - /** - * Returns an immutable default config. - */ - static const ConfigDescription& defaultConfig(); + /** + * Returns an immutable default config. + */ + static const ConfigDescription& defaultConfig(); - /* - * Parse a string of the form 'fr-sw600dp-land' and fill in the - * given ResTable_config with resulting configuration parameters. - * - * The resulting configuration has the appropriate sdkVersion defined - * for backwards compatibility. - */ - static bool parse(const StringPiece& str, ConfigDescription* out = nullptr); + /* + * Parse a string of the form 'fr-sw600dp-land' and fill in the + * given ResTable_config with resulting configuration parameters. + * + * The resulting configuration has the appropriate sdkVersion defined + * for backwards compatibility. + */ + static bool parse(const StringPiece& str, ConfigDescription* out = nullptr); - /** - * If the configuration uses an axis that was added after - * the original Android release, make sure the SDK version - * is set accordingly. - */ - static void applyVersionForCompatibility(ConfigDescription* config); + /** + * If the configuration uses an axis that was added after + * the original Android release, make sure the SDK version + * is set accordingly. + */ + static void applyVersionForCompatibility(ConfigDescription* config); - ConfigDescription(); - ConfigDescription(const android::ResTable_config& o); // NOLINT(implicit) - ConfigDescription(const ConfigDescription& o); - ConfigDescription(ConfigDescription&& o); + ConfigDescription(); + ConfigDescription(const android::ResTable_config& o); // NOLINT(implicit) + ConfigDescription(const ConfigDescription& o); + ConfigDescription(ConfigDescription&& o); - ConfigDescription& operator=(const android::ResTable_config& o); - ConfigDescription& operator=(const ConfigDescription& o); - ConfigDescription& operator=(ConfigDescription&& o); + ConfigDescription& operator=(const android::ResTable_config& o); + ConfigDescription& operator=(const ConfigDescription& o); + ConfigDescription& operator=(ConfigDescription&& o); - ConfigDescription copyWithoutSdkVersion() const; + ConfigDescription copyWithoutSdkVersion() const; - /** - * A configuration X dominates another configuration Y, if X has at least the - * precedence of Y and X is strictly more general than Y: for any type defined - * by X, the same type is defined by Y with a value equal to or, in the case - * of ranges, more specific than that of X. - * - * For example, the configuration 'en-w800dp' dominates 'en-rGB-w1024dp'. It - * does not dominate 'fr', 'en-w720dp', or 'mcc001-en-w800dp'. - */ - bool dominates(const ConfigDescription& o) const; + /** + * A configuration X dominates another configuration Y, if X has at least the + * precedence of Y and X is strictly more general than Y: for any type defined + * by X, the same type is defined by Y with a value equal to or, in the case + * of ranges, more specific than that of X. + * + * For example, the configuration 'en-w800dp' dominates 'en-rGB-w1024dp'. It + * does not dominate 'fr', 'en-w720dp', or 'mcc001-en-w800dp'. + */ + bool dominates(const ConfigDescription& o) const; - /** - * Returns true if this configuration defines a more important configuration - * parameter than o. For example, "en" has higher precedence than "v23", - * whereas "en" has the same precedence as "en-v23". - */ - bool hasHigherPrecedenceThan(const ConfigDescription& o) const; + /** + * Returns true if this configuration defines a more important configuration + * parameter than o. For example, "en" has higher precedence than "v23", + * whereas "en" has the same precedence as "en-v23". + */ + bool hasHigherPrecedenceThan(const ConfigDescription& o) const; - /** - * A configuration conflicts with another configuration if both - * configurations define an incompatible configuration parameter. An - * incompatible configuration parameter is a non-range, non-density parameter - * that is defined in both configurations as a different, non-default value. - */ - bool conflictsWith(const ConfigDescription& o) const; + /** + * A configuration conflicts with another configuration if both + * configurations define an incompatible configuration parameter. An + * incompatible configuration parameter is a non-range, non-density parameter + * that is defined in both configurations as a different, non-default value. + */ + bool conflictsWith(const ConfigDescription& o) const; - /** - * A configuration is compatible with another configuration if both - * configurations can match a common concrete device configuration and are - * unrelated by domination. For example, land-v11 conflicts with port-v21 - * but is compatible with v21 (both land-v11 and v21 would match en-land-v23). - */ - bool isCompatibleWith(const ConfigDescription& o) const; + /** + * A configuration is compatible with another configuration if both + * configurations can match a common concrete device configuration and are + * unrelated by domination. For example, land-v11 conflicts with port-v21 + * but is compatible with v21 (both land-v11 and v21 would match en-land-v23). + */ + bool isCompatibleWith(const ConfigDescription& o) const; - bool matchWithDensity(const ConfigDescription& o) const; + bool matchWithDensity(const ConfigDescription& o) const; - bool operator<(const ConfigDescription& o) const; - bool operator<=(const ConfigDescription& o) const; - bool operator==(const ConfigDescription& o) const; - bool operator!=(const ConfigDescription& o) const; - bool operator>=(const ConfigDescription& o) const; - bool operator>(const ConfigDescription& o) const; + bool operator<(const ConfigDescription& o) const; + bool operator<=(const ConfigDescription& o) const; + bool operator==(const ConfigDescription& o) const; + bool operator!=(const ConfigDescription& o) const; + bool operator>=(const ConfigDescription& o) const; + bool operator>(const ConfigDescription& o) const; }; inline ConfigDescription::ConfigDescription() { - memset(this, 0, sizeof(*this)); - size = sizeof(android::ResTable_config); + memset(this, 0, sizeof(*this)); + size = sizeof(android::ResTable_config); } inline ConfigDescription::ConfigDescription(const android::ResTable_config& o) { - *static_cast(this) = o; - size = sizeof(android::ResTable_config); + *static_cast(this) = o; + size = sizeof(android::ResTable_config); } inline ConfigDescription::ConfigDescription(const ConfigDescription& o) { - *static_cast(this) = o; + *static_cast(this) = o; } inline ConfigDescription::ConfigDescription(ConfigDescription&& o) { - *this = o; + *this = o; } -inline ConfigDescription& ConfigDescription::operator=(const android::ResTable_config& o) { - *static_cast(this) = o; - size = sizeof(android::ResTable_config); - return *this; +inline ConfigDescription& ConfigDescription::operator=( + const android::ResTable_config& o) { + *static_cast(this) = o; + size = sizeof(android::ResTable_config); + return *this; } -inline ConfigDescription& ConfigDescription::operator=(const ConfigDescription& o) { - *static_cast(this) = o; - return *this; +inline ConfigDescription& ConfigDescription::operator=( + const ConfigDescription& o) { + *static_cast(this) = o; + return *this; } inline ConfigDescription& ConfigDescription::operator=(ConfigDescription&& o) { - *this = o; - return *this; + *this = o; + return *this; } -inline bool ConfigDescription::matchWithDensity(const ConfigDescription& o) const { - return match(o) && (density == 0 || density == o.density); +inline bool ConfigDescription::matchWithDensity( + const ConfigDescription& o) const { + return match(o) && (density == 0 || density == o.density); } inline bool ConfigDescription::operator<(const ConfigDescription& o) const { - return compare(o) < 0; + return compare(o) < 0; } inline bool ConfigDescription::operator<=(const ConfigDescription& o) const { - return compare(o) <= 0; + return compare(o) <= 0; } inline bool ConfigDescription::operator==(const ConfigDescription& o) const { - return compare(o) == 0; + return compare(o) == 0; } inline bool ConfigDescription::operator!=(const ConfigDescription& o) const { - return compare(o) != 0; + return compare(o) != 0; } inline bool ConfigDescription::operator>=(const ConfigDescription& o) const { - return compare(o) >= 0; + return compare(o) >= 0; } inline bool ConfigDescription::operator>(const ConfigDescription& o) const { - return compare(o) > 0; + return compare(o) > 0; } -inline ::std::ostream& operator<<(::std::ostream& out, const ConfigDescription& o) { - return out << o.toString().string(); +inline ::std::ostream& operator<<(::std::ostream& out, + const ConfigDescription& o) { + return out << o.toString().string(); } -} // namespace aapt +} // namespace aapt -#endif // AAPT_CONFIG_DESCRIPTION_H +#endif // AAPT_CONFIG_DESCRIPTION_H diff --git a/tools/aapt2/ConfigDescription_test.cpp b/tools/aapt2/ConfigDescription_test.cpp index 455a57f1a10dd..66b7d47761188 100644 --- a/tools/aapt2/ConfigDescription_test.cpp +++ b/tools/aapt2/ConfigDescription_test.cpp @@ -23,76 +23,79 @@ namespace aapt { -static ::testing::AssertionResult TestParse(const StringPiece& input, - ConfigDescription* config = nullptr) { - if (ConfigDescription::parse(input, config)) { - return ::testing::AssertionSuccess() << input << " was successfully parsed"; - } - return ::testing::AssertionFailure() << input << " could not be parsed"; +static ::testing::AssertionResult TestParse( + const StringPiece& input, ConfigDescription* config = nullptr) { + if (ConfigDescription::parse(input, config)) { + return ::testing::AssertionSuccess() << input << " was successfully parsed"; + } + return ::testing::AssertionFailure() << input << " could not be parsed"; } TEST(ConfigDescriptionTest, ParseFailWhenQualifiersAreOutOfOrder) { - EXPECT_FALSE(TestParse("en-sw600dp-ldrtl")); - EXPECT_FALSE(TestParse("land-en")); - EXPECT_FALSE(TestParse("hdpi-320dpi")); + EXPECT_FALSE(TestParse("en-sw600dp-ldrtl")); + EXPECT_FALSE(TestParse("land-en")); + EXPECT_FALSE(TestParse("hdpi-320dpi")); } TEST(ConfigDescriptionTest, ParseFailWhenQualifiersAreNotMatched) { - EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL")); + EXPECT_FALSE(TestParse("en-sw600dp-ILLEGAL")); } TEST(ConfigDescriptionTest, ParseFailWhenQualifiersHaveTrailingDash) { - EXPECT_FALSE(TestParse("en-sw600dp-land-")); + EXPECT_FALSE(TestParse("en-sw600dp-land-")); } TEST(ConfigDescriptionTest, ParseBasicQualifiers) { - ConfigDescription config; - EXPECT_TRUE(TestParse("", &config)); - EXPECT_EQ(std::string(""), config.toString().string()); + ConfigDescription config; + EXPECT_TRUE(TestParse("", &config)); + EXPECT_EQ(std::string(""), config.toString().string()); - EXPECT_TRUE(TestParse("fr-land", &config)); - EXPECT_EQ(std::string("fr-land"), config.toString().string()); + EXPECT_TRUE(TestParse("fr-land", &config)); + EXPECT_EQ(std::string("fr-land"), config.toString().string()); - EXPECT_TRUE(TestParse("mcc310-pl-sw720dp-normal-long-port-night-" - "xhdpi-keyssoft-qwerty-navexposed-nonav", &config)); - EXPECT_EQ(std::string("mcc310-pl-sw720dp-normal-long-port-night-" - "xhdpi-keyssoft-qwerty-navexposed-nonav-v13"), config.toString().string()); + EXPECT_TRUE( + TestParse("mcc310-pl-sw720dp-normal-long-port-night-" + "xhdpi-keyssoft-qwerty-navexposed-nonav", + &config)); + EXPECT_EQ(std::string("mcc310-pl-sw720dp-normal-long-port-night-" + "xhdpi-keyssoft-qwerty-navexposed-nonav-v13"), + config.toString().string()); } TEST(ConfigDescriptionTest, ParseLocales) { - ConfigDescription config; - EXPECT_TRUE(TestParse("en-rUS", &config)); - EXPECT_EQ(std::string("en-rUS"), config.toString().string()); + ConfigDescription config; + EXPECT_TRUE(TestParse("en-rUS", &config)); + EXPECT_EQ(std::string("en-rUS"), config.toString().string()); } TEST(ConfigDescriptionTest, ParseQualifierAddedInApi13) { - ConfigDescription config; - EXPECT_TRUE(TestParse("sw600dp", &config)); - EXPECT_EQ(std::string("sw600dp-v13"), config.toString().string()); + ConfigDescription config; + EXPECT_TRUE(TestParse("sw600dp", &config)); + EXPECT_EQ(std::string("sw600dp-v13"), config.toString().string()); - EXPECT_TRUE(TestParse("sw600dp-v8", &config)); - EXPECT_EQ(std::string("sw600dp-v13"), config.toString().string()); + EXPECT_TRUE(TestParse("sw600dp-v8", &config)); + EXPECT_EQ(std::string("sw600dp-v13"), config.toString().string()); } TEST(ConfigDescriptionTest, ParseCarAttribute) { - ConfigDescription config; - EXPECT_TRUE(TestParse("car", &config)); - EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode); + ConfigDescription config; + EXPECT_TRUE(TestParse("car", &config)); + EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode); } TEST(ConfigDescriptionTest, TestParsingRoundQualifier) { - ConfigDescription config; - EXPECT_TRUE(TestParse("round", &config)); - EXPECT_EQ(android::ResTable_config::SCREENROUND_YES, - config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); - EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); - EXPECT_EQ(std::string("round-v23"), config.toString().string()); + ConfigDescription config; + EXPECT_TRUE(TestParse("round", &config)); + EXPECT_EQ(android::ResTable_config::SCREENROUND_YES, + config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); + EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); + EXPECT_EQ(std::string("round-v23"), config.toString().string()); - EXPECT_TRUE(TestParse("notround", &config)); - EXPECT_EQ(android::ResTable_config::SCREENROUND_NO, - config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); - EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); - EXPECT_EQ(std::string("notround-v23"), config.toString().string()); + EXPECT_TRUE(TestParse("notround", &config)); + EXPECT_EQ(android::ResTable_config::SCREENROUND_NO, + config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); + EXPECT_EQ(SDK_MARSHMALLOW, config.sdkVersion); + EXPECT_EQ(std::string("notround-v23"), config.toString().string()); } -} // namespace aapt +} // namespace aapt diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp index 304e571832f4a..965db9ebc9c85 100644 --- a/tools/aapt2/Debug.cpp +++ b/tools/aapt2/Debug.cpp @@ -17,8 +17,8 @@ #include "Debug.h" #include "ResourceTable.h" #include "ResourceValues.h" -#include "util/Util.h" #include "ValueVisitor.h" +#include "util/Util.h" #include #include @@ -31,275 +31,279 @@ namespace aapt { class PrintVisitor : public ValueVisitor { -public: - using ValueVisitor::visit; + public: + using ValueVisitor::visit; - void visit(Attribute* attr) override { - std::cout << "(attr) type="; - attr->printMask(&std::cout); - static constexpr uint32_t kMask = android::ResTable_map::TYPE_ENUM | - android::ResTable_map::TYPE_FLAGS; - if (attr->typeMask & kMask) { - for (const auto& symbol : attr->symbols) { - std::cout << "\n " << symbol.symbol.name.value().entry; - if (symbol.symbol.id) { - std::cout << " (" << symbol.symbol.id.value() << ")"; - } - std::cout << " = " << symbol.value; - } + void visit(Attribute* attr) override { + std::cout << "(attr) type="; + attr->printMask(&std::cout); + static constexpr uint32_t kMask = + android::ResTable_map::TYPE_ENUM | android::ResTable_map::TYPE_FLAGS; + if (attr->typeMask & kMask) { + for (const auto& symbol : attr->symbols) { + std::cout << "\n " << symbol.symbol.name.value().entry; + if (symbol.symbol.id) { + std::cout << " (" << symbol.symbol.id.value() << ")"; } + std::cout << " = " << symbol.value; + } } + } - void visit(Style* style) override { - std::cout << "(style)"; - if (style->parent) { - const Reference& parentRef = style->parent.value(); - std::cout << " parent="; - if (parentRef.name) { - if (parentRef.privateReference) { - std::cout << "*"; - } - std::cout << parentRef.name.value() << " "; - } - - if (parentRef.id) { - std::cout << parentRef.id.value(); - } + void visit(Style* style) override { + std::cout << "(style)"; + if (style->parent) { + const Reference& parentRef = style->parent.value(); + std::cout << " parent="; + if (parentRef.name) { + if (parentRef.privateReference) { + std::cout << "*"; } + std::cout << parentRef.name.value() << " "; + } - for (const auto& entry : style->entries) { - std::cout << "\n "; - if (entry.key.name) { - const ResourceName& name = entry.key.name.value(); - if (!name.package.empty()) { - std::cout << name.package << ":"; - } - std::cout << name.entry; - } + if (parentRef.id) { + std::cout << parentRef.id.value(); + } + } - if (entry.key.id) { - std::cout << "(" << entry.key.id.value() << ")"; - } - - std::cout << "=" << *entry.value; + for (const auto& entry : style->entries) { + std::cout << "\n "; + if (entry.key.name) { + const ResourceName& name = entry.key.name.value(); + if (!name.package.empty()) { + std::cout << name.package << ":"; } + std::cout << name.entry; + } + + if (entry.key.id) { + std::cout << "(" << entry.key.id.value() << ")"; + } + + std::cout << "=" << *entry.value; } + } - void visit(Array* array) override { - array->print(&std::cout); - } + void visit(Array* array) override { array->print(&std::cout); } - void visit(Plural* plural) override { - plural->print(&std::cout); - } + void visit(Plural* plural) override { plural->print(&std::cout); } - void visit(Styleable* styleable) override { - std::cout << "(styleable)"; - for (const auto& attr : styleable->entries) { - std::cout << "\n "; - if (attr.name) { - const ResourceName& name = attr.name.value(); - if (!name.package.empty()) { - std::cout << name.package << ":"; - } - std::cout << name.entry; - } - - if (attr.id) { - std::cout << "(" << attr.id.value() << ")"; - } + void visit(Styleable* styleable) override { + std::cout << "(styleable)"; + for (const auto& attr : styleable->entries) { + std::cout << "\n "; + if (attr.name) { + const ResourceName& name = attr.name.value(); + if (!name.package.empty()) { + std::cout << name.package << ":"; } - } + std::cout << name.entry; + } - void visitItem(Item* item) override { - item->print(&std::cout); + if (attr.id) { + std::cout << "(" << attr.id.value() << ")"; + } } + } + + void visitItem(Item* item) override { item->print(&std::cout); } }; -void Debug::printTable(ResourceTable* table, const DebugPrintTableOptions& options) { - PrintVisitor visitor; +void Debug::printTable(ResourceTable* table, + const DebugPrintTableOptions& options) { + PrintVisitor visitor; - for (auto& package : table->packages) { - std::cout << "Package name=" << package->name; - if (package->id) { - std::cout << " id=" << std::hex << (int) package->id.value() << std::dec; + for (auto& package : table->packages) { + std::cout << "Package name=" << package->name; + if (package->id) { + std::cout << " id=" << std::hex << (int)package->id.value() << std::dec; + } + std::cout << std::endl; + + for (const auto& type : package->types) { + std::cout << "\n type " << type->type; + if (type->id) { + std::cout << " id=" << std::hex << (int)type->id.value() << std::dec; + } + std::cout << " entryCount=" << type->entries.size() << std::endl; + + std::vector sortedEntries; + for (const auto& entry : type->entries) { + auto iter = std::lower_bound( + sortedEntries.begin(), sortedEntries.end(), entry.get(), + [](const ResourceEntry* a, const ResourceEntry* b) -> bool { + if (a->id && b->id) { + return a->id.value() < b->id.value(); + } else if (a->id) { + return true; + } else { + return false; + } + }); + sortedEntries.insert(iter, entry.get()); + } + + for (const ResourceEntry* entry : sortedEntries) { + ResourceId id(package->id ? package->id.value() : uint8_t(0), + type->id ? type->id.value() : uint8_t(0), + entry->id ? entry->id.value() : uint16_t(0)); + ResourceName name(package->name, type->type, entry->name); + + std::cout << " spec resource " << id << " " << name; + switch (entry->symbolStatus.state) { + case SymbolState::kPublic: + std::cout << " PUBLIC"; + break; + case SymbolState::kPrivate: + std::cout << " _PRIVATE_"; + break; + default: + break; } + std::cout << std::endl; - for (const auto& type : package->types) { - std::cout << "\n type " << type->type; - if (type->id) { - std::cout << " id=" << std::hex << (int) type->id.value() << std::dec; - } - std::cout << " entryCount=" << type->entries.size() << std::endl; - - std::vector sortedEntries; - for (const auto& entry : type->entries) { - auto iter = std::lower_bound(sortedEntries.begin(), sortedEntries.end(), entry.get(), - [](const ResourceEntry* a, const ResourceEntry* b) -> bool { - if (a->id && b->id) { - return a->id.value() < b->id.value(); - } else if (a->id) { - return true; - } else { - return false; - } - }); - sortedEntries.insert(iter, entry.get()); - } - - for (const ResourceEntry* entry : sortedEntries) { - ResourceId id(package->id ? package->id.value() : uint8_t(0), - type->id ? type->id.value() : uint8_t(0), - entry->id ? entry->id.value() : uint16_t(0)); - ResourceName name(package->name, type->type, entry->name); - - std::cout << " spec resource " << id << " " << name; - switch (entry->symbolStatus.state) { - case SymbolState::kPublic: std::cout << " PUBLIC"; break; - case SymbolState::kPrivate: std::cout << " _PRIVATE_"; break; - default: break; - } - - std::cout << std::endl; - - for (const auto& value : entry->values) { - std::cout << " (" << value->config << ") "; - value->value->accept(&visitor); - if (options.showSources && !value->value->getSource().path.empty()) { - std::cout << " src=" << value->value->getSource(); - } - std::cout << std::endl; - } - } + for (const auto& value : entry->values) { + std::cout << " (" << value->config << ") "; + value->value->accept(&visitor); + if (options.showSources && !value->value->getSource().path.empty()) { + std::cout << " src=" << value->value->getSource(); + } + std::cout << std::endl; } + } } + } } -static size_t getNodeIndex(const std::vector& names, const ResourceName& name) { - auto iter = std::lower_bound(names.begin(), names.end(), name); - assert(iter != names.end() && *iter == name); - return std::distance(names.begin(), iter); +static size_t getNodeIndex(const std::vector& names, + const ResourceName& name) { + auto iter = std::lower_bound(names.begin(), names.end(), name); + assert(iter != names.end() && *iter == name); + return std::distance(names.begin(), iter); } -void Debug::printStyleGraph(ResourceTable* table, const ResourceName& targetStyle) { - std::map> graph; +void Debug::printStyleGraph(ResourceTable* table, + const ResourceName& targetStyle) { + std::map> graph; - std::queue stylesToVisit; - stylesToVisit.push(targetStyle); - for (; !stylesToVisit.empty(); stylesToVisit.pop()) { - const ResourceName& styleName = stylesToVisit.front(); - std::set& parents = graph[styleName]; - if (!parents.empty()) { - // We've already visited this style. - continue; - } - - Maybe result = table->findResource(styleName); - if (result) { - ResourceEntry* entry = result.value().entry; - for (const auto& value : entry->values) { - if (Style* style = valueCast"; - ASSERT_TRUE(testParse(input)); + std::string input = + ""; + ASSERT_TRUE(testParse(input)); - Style* style = test::getValue"; - ASSERT_TRUE(testParse(input)); + std::string input = + ""; + ASSERT_TRUE(testParse(input)); - Style* style = test::getValue