70 , fSymbolTableStack({symbolBase})
73 static std::string FindShortNameForSymbol(
const Symbol*
sym,
75 const std::string& namePrefix) {
76 static constexpr std::string_view kLetters[] = {
77 "a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
78 "n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
79 "A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
80 "N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"};
83 for (std::string_view letter : kLetters) {
84 std::string
name = namePrefix + std::string(letter);
85 if (symbolTable->
find(
name) ==
nullptr) {
91 for (std::string_view letterA : kLetters) {
92 for (std::string_view letterB : kLetters) {
93 std::string
name = namePrefix + std::string(letterA) + std::string(letterB);
94 if (symbolTable->
find(
name) ==
nullptr) {
101 SkDEBUGFAILF(
"Unable to find unique name for '%s'", std::string(
sym->name()).c_str());
102 return std::string(
sym->name());
105 void minifyVariableName(
const Variable* var) {
109 if (var->
name().empty()) {
117 "symbol table missing '%.*s'", (
int)var->
name().size(), var->
name().data());
119 "wrong symbol found for '%.*s'", (
int)var->
name().size(), var->
name().data());
126 std::string shortName = FindShortNameForSymbol(var,
symbols,
"");
130 const std::string* ownedName =
symbols->takeOwnershipOfString(std::move(shortName));
138 std::string shortName = FindShortNameForSymbol(funcDecl,
symbols,
139 std::move(namePrefix));
142 if (shortName.size() < funcDecl->
name().size()) {
146 const std::string* ownedName =
symbols->takeOwnershipOfString(std::move(shortName));
154 return !funcDecl.
isMain();
165 if (this->functionNameCanBeMinifiedSafely(*funcDecl)) {
166 this->minifyFunctionName(funcDecl);
173 this->minifyVariableName(param);
193 switch (elem.
kind()) {
196 return INHERITED::visitProgramElement(elem);
198 case ProgramElement::Kind::kFunctionPrototype:
200 return INHERITED::visitProgramElement(elem);
207 bool visitStatementPtr(std::unique_ptr<Statement>& stmt)
override {
213 this->minifyVariableName(decl.
var());
216 return INHERITED::visitStatementPtr(stmt);
221 std::vector<SymbolTable*> fSymbolTableStack;
227 SymbolRenamer renamer{context,
usage, module.
fSymbols.get(), kind};
228 for (std::unique_ptr<ProgramElement>& pe : module.
fElements) {
229 renamer.visitProgramElement(*pe);
234 for (std::unique_ptr<ProgramElement>& pe : module.
fElements) {
#define SkDEBUGFAILF(fmt,...)
#define SkASSERTF(cond, fmt,...)
#define INHERITED(method,...)
FunctionDeclaration * mutableNextOverload() const
SkSpan< Variable *const > parameters() const
const FunctionDefinition * definition() const
ModifierFlags modifierFlags() const
void setModifierFlags(ModifierFlags m)
std::unique_ptr< Statement > & body()
const FunctionDeclaration & declaration() const
const FunctionDeclaration & declaration() const
const Symbol * find(std::string_view name) const
std::string_view name() const
void setName(std::string_view newName)
FlutterSemanticsFlag flags
static void strip_export_flag(Context &context, const FunctionDeclaration *funcDecl, SymbolTable *symbols)
DEF_SWITCHES_START aot vmservice shared library name
constexpr bool starts_with(std::string_view str, std::string_view prefix)
static void usage(char *argv0)
std::vector< std::unique_ptr< ProgramElement > > fElements
std::unique_ptr< SymbolTable > fSymbols
static bool IsRuntimeEffect(ProgramKind kind)