diff --git a/aot/main.cpp b/aot/main.cpp index 8dbd680977fa6e901ca1e41d7f6dbc8235458125..a647f00b6c5164bc50136adad2e072dd19077f69 100644 --- a/aot/main.cpp +++ b/aot/main.cpp @@ -130,7 +130,7 @@ int Run(int argc, const char **argv) return err.ErrorCode(); } - GenerateProgram(program, options->CompilerOutput(), options->OptLevel(), options->CompilerOptions().dumpAsm, + GenerateProgram(program, options->CompilerOutput(), options->OptLevel(), options->CompilerOptions().dump_asm_, options->SizeStat()); delete program; diff --git a/aot/options.cpp b/aot/options.cpp index 9be3f001c5b1f2f8a6c5e7e5cd796649fe38f70d..72b0a67863d579d1ff29b9004f4c9526a7be59af 100644 --- a/aot/options.cpp +++ b/aot/options.cpp @@ -96,29 +96,29 @@ bool Options::Parse(int argc, const char **argv) ss << "optional arguments:" << std::endl; ss << argparser_->GetHelpString() << std::endl; - errorMsg_ = ss.str(); + error_msg_ = ss.str(); return false; } - sourceFile_ = inputFile.GetValue(); - std::ifstream inputStream(sourceFile_.c_str()); + source_file_ = inputFile.GetValue(); + std::ifstream inputStream(source_file_.c_str()); if (inputStream.fail()) { - errorMsg_ = "Failed to open file: "; - errorMsg_.append(sourceFile_); + error_msg_ = "Failed to open file: "; + error_msg_.append(source_file_); return false; } std::stringstream ss; ss << inputStream.rdbuf(); - parserInput_ = ss.str(); + parser_input_ = ss.str(); - sourceFile_ = BaseName(sourceFile_); + source_file_ = BaseName(source_file_); if (!outputFile.GetValue().empty()) { - compilerOutput_ = outputFile.GetValue(); + compiler_output_ = outputFile.GetValue(); } else { - compilerOutput_ = RemoveExtension(sourceFile_).append(".abc"); + compiler_output_ = RemoveExtension(source_file_).append(".abc"); } std::string extension = inputExtension.GetValue(); @@ -131,13 +131,13 @@ bool Options::Parse(int argc, const char **argv) } else if (extension == "as") { extension_ = es2panda::ScriptExtension::AS; } else { - errorMsg_ = "Invalid extension (available options: js, ts, as)"; + error_msg_ = "Invalid extension (available options: js, ts, as)"; return false; } } - optLevel_ = opOptLevel.GetValue(); - threadCount_ = opThreadCount.GetValue(); + opt_level_ = opOptLevel.GetValue(); + thread_count_ = opThreadCount.GetValue(); if (opParseOnly.GetValue()) { options_ |= OptionFlags::PARSE_ONLY; @@ -151,11 +151,11 @@ bool Options::Parse(int argc, const char **argv) options_ |= OptionFlags::SIZE_STAT; } - compilerOptions_.dumpAsm = opDumpAssembly.GetValue(); - compilerOptions_.dumpAst = opDumpAst.GetValue(); - compilerOptions_.dumpDebugInfo = opDumpDebugInfo.GetValue(); - compilerOptions_.isDebug = opDebugInfo.GetValue(); - compilerOptions_.parseOnly = opParseOnly.GetValue(); + compiler_options_.dump_asm_ = opDumpAssembly.GetValue(); + compiler_options_.dump_ast_ = opDumpAst.GetValue(); + compiler_options_.dump_debug_info_ = opDumpDebugInfo.GetValue(); + compiler_options_.is_debug_ = opDebugInfo.GetValue(); + compiler_options_.parse_only_ = opParseOnly.GetValue(); return true; } diff --git a/aot/options.h b/aot/options.h index af8c8e3093a40394bd8679a28407a28d4dd16708..484c4b9ecce37446a26eb8c21f200d7457670480 100644 --- a/aot/options.h +++ b/aot/options.h @@ -67,37 +67,37 @@ public: const es2panda::CompilerOptions &CompilerOptions() const { - return compilerOptions_; + return compiler_options_; } const std::string &ParserInput() const { - return parserInput_; + return parser_input_; } const std::string &CompilerOutput() const { - return compilerOutput_; + return compiler_output_; } const std::string &SourceFile() const { - return sourceFile_; + return source_file_; } const std::string &ErrorMsg() const { - return errorMsg_; + return error_msg_; } int OptLevel() const { - return optLevel_; + return opt_level_; } int ThreadCount() const { - return threadCount_; + return thread_count_; } bool ParseModule() const @@ -117,16 +117,16 @@ public: private: es2panda::ScriptExtension extension_ {es2panda::ScriptExtension::JS}; - es2panda::CompilerOptions compilerOptions_ {}; + es2panda::CompilerOptions compiler_options_ {}; OptionFlags options_ {OptionFlags::DEFAULT}; panda::PandArgParser *argparser_; - std::string parserInput_; - std::string compilerOutput_; + std::string parser_input_; + std::string compiler_output_; std::string result_; - std::string sourceFile_; - std::string errorMsg_; - int optLevel_ {0}; - int threadCount_ {0}; + std::string source_file_; + std::string error_msg_; + int opt_level_ {0}; + int thread_count_ {0}; }; } // namespace panda::es2panda::aot diff --git a/binder/binder.cpp b/binder/binder.cpp index d2a8b2ad397c8be9b3a5a17ca306bd6354d2d199..9ffe0fa018a41c0b2bbb33f0680b80907ff9f41e 100644 --- a/binder/binder.cpp +++ b/binder/binder.cpp @@ -45,12 +45,12 @@ namespace panda::es2panda::binder { void Binder::InitTopScope() { if (program_->Kind() == parser::ScriptKind::MODULE) { - topScope_ = Allocator()->New(Allocator()); + top_scope_ = Allocator()->New(Allocator()); } else { - topScope_ = Allocator()->New(Allocator()); + top_scope_ = Allocator()->New(Allocator()); } - scope_ = topScope_; + scope_ = top_scope_; } ParameterDecl *Binder::AddParamDecl(const ir::AstNode *param) @@ -72,15 +72,15 @@ void Binder::ThrowRedeclaration(const lexer::SourcePosition &pos, const util::St std::stringstream ss; ss << "Variable '" << name << "' has already been declared."; - throw Error(ErrorType::SYNTAX, ss.str(), loc.line, loc.col); + throw Error(ErrorType::SYNTAX, ss.str(), loc.line_, loc.col_); } void Binder::IdentifierAnalysis() { ASSERT(program_->Ast()); - ASSERT(scope_ == topScope_); + ASSERT(scope_ == top_scope_); - BuildFunction(topScope_, "main"); + BuildFunction(top_scope_, "main"); ResolveReferences(program_->Ast()); AddMandatoryParams(); } @@ -88,12 +88,12 @@ void Binder::IdentifierAnalysis() void Binder::LookupReference(const util::StringView &name) { ScopeFindResult res = scope_->Find(name); - if (res.level == 0) { + if (res.level_ == 0) { return; } - ASSERT(res.variable); - res.variable->SetLexical(res.scope); + ASSERT(res.variable_); + res.variable_->SetLexical(res.scope_); } void Binder::InstantiateArguments() @@ -142,26 +142,26 @@ void Binder::LookupIdentReference(ir::Identifier *ident) } ScopeFindResult res = scope_->Find(ident->Name()); - if (res.level != 0) { - ASSERT(res.variable); - res.variable->SetLexical(res.scope); + if (res.level_ != 0) { + ASSERT(res.variable_); + res.variable_->SetLexical(res.scope_); } - if (!res.variable) { + if (!res.variable_) { return; } - if (res.variable->Declaration()->IsLetOrConstDecl() && !res.variable->HasFlag(VariableFlags::INITIALIZED)) { + if (res.variable_->Declaration()->IsLetOrConstDecl() && !res.variable_->HasFlag(VariableFlags::INITIALIZED)) { ident->SetTdz(); } - ident->SetVariable(res.variable); + ident->SetVariable(res.variable_); } void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name) { - uint32_t idx = functionScopes_.size(); - functionScopes_.push_back(funcScope); + uint32_t idx = function_scopes_.size(); + function_scopes_.push_back(funcScope); std::stringstream ss; ss << "func_" << name << "_" << std::to_string(idx); @@ -245,8 +245,8 @@ void Binder::BuildClassDefinition(ir::ClassDefinition *classDef) if (classDef->Parent()->IsClassDeclaration()) { ScopeFindResult res = scope_->Find(classDef->Ident()->Name()); - ASSERT(res.variable && res.variable->Declaration()->IsLetDecl()); - res.variable->AddFlag(VariableFlags::INITIALIZED); + ASSERT(res.variable_ && res.variable_->Declaration()->IsLetDecl()); + res.variable_->AddFlag(VariableFlags::INITIALIZED); } auto scopeCtx = LexicalScope::Enter(this, classDef->Scope()); @@ -258,8 +258,8 @@ void Binder::BuildClassDefinition(ir::ClassDefinition *classDef) if (classDef->Ident()) { ScopeFindResult res = scope_->Find(classDef->Ident()->Name()); - ASSERT(res.variable && res.variable->Declaration()->IsConstDecl()); - res.variable->AddFlag(VariableFlags::INITIALIZED); + ASSERT(res.variable_ && res.variable_->Declaration()->IsConstDecl()); + res.variable_->AddFlag(VariableFlags::INITIALIZED); } ResolveReference(classDef, classDef->Ctor()); @@ -462,15 +462,15 @@ void Binder::AddMandatoryParams(const MandatoryParams ¶ms) void Binder::AddMandatoryParams() { - ASSERT(scope_ == topScope_); - ASSERT(!functionScopes_.empty()); - auto iter = functionScopes_.begin(); + ASSERT(scope_ == top_scope_); + ASSERT(!function_scopes_.empty()); + auto iter = function_scopes_.begin(); [[maybe_unused]] auto *funcScope = *iter++; ASSERT(funcScope->IsGlobalScope() || funcScope->IsModuleScope()); AddMandatoryParams(FUNCTION_MANDATORY_PARAMS); - for (; iter != functionScopes_.end(); iter++) { + for (; iter != function_scopes_.end(); iter++) { funcScope = *iter; const auto *scriptFunc = funcScope->Node()->AsScriptFunction(); diff --git a/binder/binder.h b/binder/binder.h index 10d52ef951c5dca86d64509b83724fa55e8b4b6e..f5325e96edd63f4004b899577d1b549969c31416 100644 --- a/binder/binder.h +++ b/binder/binder.h @@ -41,7 +41,7 @@ class VariableScope; class Binder { public: - explicit Binder(parser::Program *program) : program_(program), functionScopes_(Allocator()->Adapter()) {} + explicit Binder(parser::Program *program) : program_(program), function_scopes_(Allocator()->Adapter()) {} NO_COPY_SEMANTIC(Binder); DEFAULT_MOVE_SEMANTIC(Binder); ~Binder() = default; @@ -64,7 +64,7 @@ public: GlobalScope *TopScope() const { - return topScope_; + return top_scope_; } [[noreturn]] void ThrowRedeclaration(const lexer::SourcePosition &pos, const util::StringView &name); @@ -79,12 +79,12 @@ public: const ArenaVector &Functions() const { - return functionScopes_; + return function_scopes_; } ArenaVector Functions() { - return functionScopes_; + return function_scopes_; } const parser::Program *Program() const @@ -135,9 +135,9 @@ private: void ResolveReferences(const ir::AstNode *parent); parser::Program *program_ {}; - GlobalScope *topScope_ {}; + GlobalScope *top_scope_ {}; Scope *scope_ {}; - ArenaVector functionScopes_; + ArenaVector function_scopes_; }; template @@ -158,7 +158,7 @@ public: ~LexicalScope() { ASSERT(binder_); - binder_->scope_ = prevScope_; + binder_->scope_ = prev_scope_; } [[nodiscard]] static LexicalScope Enter(Binder *binder, T *scope) @@ -172,14 +172,14 @@ public: private: NO_COPY_SEMANTIC(LexicalScope); - explicit LexicalScope(T *scope, Binder *binder) : binder_(binder), scope_(scope), prevScope_(binder->scope_) + explicit LexicalScope(T *scope, Binder *binder) : binder_(binder), scope_(scope), prev_scope_(binder->scope_) { binder_->scope_ = scope_; } Binder *binder_ {}; T *scope_ {}; - Scope *prevScope_ {}; + Scope *prev_scope_ {}; }; template diff --git a/binder/declaration.h b/binder/declaration.h index ab65a7579ac6db9768e837f80d82e57f8cbcdd62..0383e0e40755b0070012cfa4a54d5cf3fae7376e 100644 --- a/binder/declaration.h +++ b/binder/declaration.h @@ -113,7 +113,7 @@ private: class EnumLiteralDecl : public Decl { public: - explicit EnumLiteralDecl(util::StringView name, bool isConst) : Decl(name), isConst_(isConst) {} + explicit EnumLiteralDecl(util::StringView name, bool isConst) : Decl(name), is_const_(isConst) {} DeclType Type() const override { @@ -122,7 +122,7 @@ public: bool IsConst() const { - return isConst_; + return is_const_; } void BindScope(LocalScope *scope) @@ -137,7 +137,7 @@ public: private: LocalScope *scope_ {}; - bool isConst_ {}; + bool is_const_ {}; }; class InterfaceDecl : public MultiDecl { @@ -247,19 +247,19 @@ public: class ImportDecl : public Decl { public: explicit ImportDecl(util::StringView importName, util::StringView localName) - : Decl(localName), importName_(importName) + : Decl(localName), import_name_(importName) { } explicit ImportDecl(util::StringView importName, util::StringView localName, const ir::AstNode *node) - : Decl(localName), importName_(importName) + : Decl(localName), import_name_(importName) { BindNode(node); } const util::StringView &ImportName() const { - return importName_; + return import_name_; } const util::StringView &LocalName() const @@ -273,25 +273,25 @@ public: } private: - util::StringView importName_; + util::StringView import_name_; }; class ExportDecl : public Decl { public: explicit ExportDecl(util::StringView exportName, util::StringView localName) - : Decl(localName), exportName_(exportName) + : Decl(localName), export_name_(exportName) { } explicit ExportDecl(util::StringView exportName, util::StringView localName, const ir::AstNode *node) - : Decl(localName), exportName_(exportName) + : Decl(localName), export_name_(exportName) { BindNode(node); } const util::StringView &ExportName() const { - return exportName_; + return export_name_; } const util::StringView &LocalName() const @@ -305,7 +305,7 @@ public: } private: - util::StringView exportName_; + util::StringView export_name_; }; } // namespace panda::es2panda::binder diff --git a/binder/scope.cpp b/binder/scope.cpp index 402bdd7a0c77989d8eb0451300936e38afe78d8d..39cf92bea665f72d34c230b5f12d39b12a0aa481 100644 --- a/binder/scope.cpp +++ b/binder/scope.cpp @@ -237,8 +237,8 @@ std::tuple ParamScope::AddParamDecl(ArenaA void FunctionParamScope::BindName(ArenaAllocator *allocator, util::StringView name) { - nameVar_ = AddDecl(allocator, name, VariableFlags::INITIALIZED); - functionScope_->Bindings().insert({name, nameVar_}); + name_var_ = AddDecl(allocator, name, VariableFlags::INITIALIZED); + function_scope_->Bindings().insert({name, name_var_}); } bool FunctionParamScope::AddBinding([[maybe_unused]] ArenaAllocator *allocator, @@ -421,7 +421,7 @@ bool ModuleScope::ExportAnalysis() if (!variable->IsModuleVariable()) { variable->AddFlag(VariableFlags::LOCAL_EXPORT); - localExports_.insert({variable, decl->ExportName()}); + local_exports_.insert({variable, decl->ExportName()}); } } } @@ -448,41 +448,41 @@ void LoopDeclarationScope::ConvertToVariableScope(ArenaAllocator *allocator) continue; } - slotIndex_++; - loopType_ = ScopeType::LOOP_DECL; + slot_index_++; + loop_type_ = ScopeType::LOOP_DECL; auto *copiedVar = var->AsLocalVariable()->Copy(allocator, var->Declaration()); copiedVar->AddFlag(VariableFlags::INITIALIZED | VariableFlags::PER_ITERATION); var->AddFlag(VariableFlags::LOOP_DECL); - loopScope_->Bindings().insert({name, copiedVar}); + loop_scope_->Bindings().insert({name, copiedVar}); } - if (loopType_ == ScopeType::LOOP_DECL) { - slotIndex_ = std::max(slotIndex_, parent_->EnclosingVariableScope()->LexicalSlots()); - initScope_ = allocator->New(allocator, parent_); - initScope_->BindNode(node_); - initScope_->Bindings() = bindings_; + if (loop_type_ == ScopeType::LOOP_DECL) { + slot_index_ = std::max(slot_index_, parent_->EnclosingVariableScope()->LexicalSlots()); + init_scope_ = allocator->New(allocator, parent_); + init_scope_->BindNode(node_); + init_scope_->Bindings() = bindings_; } } void LoopScope::ConvertToVariableScope(ArenaAllocator *allocator) { - declScope_->ConvertToVariableScope(allocator); + decl_scope_->ConvertToVariableScope(allocator); - if (loopType_ != ScopeType::LOCAL) { + if (loop_type_ != ScopeType::LOCAL) { return; } for (const auto &[_, var] : bindings_) { (void)_; if (var->LexicalBound() && var->Declaration()->IsLetDecl()) { - ASSERT(declScope_->NeedLexEnv()); - loopType_ = ScopeType::LOOP; + ASSERT(decl_scope_->NeedLexEnv()); + loop_type_ = ScopeType::LOOP; break; } } - if (loopType_ == ScopeType::LOOP) { - slotIndex_ = std::max(slotIndex_, declScope_->LexicalSlots()); + if (loop_type_ == ScopeType::LOOP) { + slot_index_ = std::max(slot_index_, decl_scope_->LexicalSlots()); } } @@ -495,7 +495,7 @@ bool CatchParamScope::AddBinding(ArenaAllocator *allocator, Variable *currentVar bool CatchScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension) { - if (!newDecl->IsVarDecl() && paramScope_->FindLocal(newDecl->Name())) { + if (!newDecl->IsVarDecl() && param_scope_->FindLocal(newDecl->Name())) { return false; } diff --git a/binder/scope.h b/binder/scope.h index 881abfb48ec6e46b012a7ed05f2cb1b43acdbad8..611a3ca118e7277fbc69fec24541412df6e84430 100644 --- a/binder/scope.h +++ b/binder/scope.h @@ -46,17 +46,19 @@ class ScopeFindResult { public: ScopeFindResult() = default; ScopeFindResult(util::StringView n, Scope *s, uint32_t l, Variable *v) : ScopeFindResult(n, s, l, l, v) {} - ScopeFindResult(Scope *s, uint32_t l, uint32_t ll, Variable *v) : scope(s), level(l), lexLevel(ll), variable(v) {} + ScopeFindResult(Scope *s, uint32_t l, uint32_t ll, Variable *v) : scope_(s), level_(l), lex_level_(ll), variable_(v) + { + } ScopeFindResult(util::StringView n, Scope *s, uint32_t l, uint32_t ll, Variable *v) - : name(n), scope(s), level(l), lexLevel(ll), variable(v) + : name_(n), scope_(s), level_(l), lex_level_(ll), variable_(v) { } - util::StringView name {}; - Scope *scope {}; - uint32_t level {}; - uint32_t lexLevel {}; - Variable *variable {}; + util::StringView name_ {}; + Scope *scope_ {}; + uint32_t level_ {}; + uint32_t lex_level_ {}; + Variable *variable_ {}; }; class Scope { @@ -138,22 +140,22 @@ public: const compiler::IRNode *ScopeStart() const { - return startIns_; + return start_ins_; } const compiler::IRNode *ScopeEnd() const { - return endIns_; + return end_ins_; } void SetScopeStart(const compiler::IRNode *ins) { - startIns_ = ins; + start_ins_ = ins; } void SetScopeEnd(const compiler::IRNode *ins) { - endIns_ = ins; + end_ins_ = ins; } const ir::AstNode *Node() const @@ -237,8 +239,8 @@ protected: ArenaVector decls_; VariableMap bindings_; const ir::AstNode *node_ {}; - const compiler::IRNode *startIns_ {}; - const compiler::IRNode *endIns_ {}; + const compiler::IRNode *start_ins_ {}; + const compiler::IRNode *end_ins_ {}; }; class VariableScope : public Scope { @@ -264,17 +266,17 @@ public: uint32_t NextSlot() { - return slotIndex_++; + return slot_index_++; } uint32_t LexicalSlots() const { - return slotIndex_; + return slot_index_; } bool NeedLexEnv() const { - return slotIndex_ != 0; + return slot_index_ != 0; } protected: @@ -294,7 +296,7 @@ protected: bool AddLexical(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl); VariableScopeFlags flags_ {}; - uint32_t slotIndex_ {}; + uint32_t slot_index_ {}; }; class ParamScope : public Scope { @@ -335,17 +337,17 @@ public: FunctionScope *GetFunctionScope() const { - return functionScope_; + return function_scope_; } void BindFunctionScope(FunctionScope *funcScope) { - functionScope_ = funcScope; + function_scope_ = funcScope; } LocalVariable *NameVar() const { - return nameVar_; + return name_var_; } void BindName(ArenaAllocator *allocator, util::StringView name); @@ -363,8 +365,8 @@ public: friend class ScopeWithParamScope; private: - FunctionScope *functionScope_ {}; - LocalVariable *nameVar_ {}; + FunctionScope *function_scope_ {}; + LocalVariable *name_var_ {}; }; template @@ -383,21 +385,21 @@ public: ASSERT(this->parent_ == paramScope); ASSERT(this->bindings_.empty()); - paramScope_ = paramScope; + param_scope_ = paramScope; } T *ParamScope() { - return paramScope_; + return param_scope_; } const T *ParamScope() const { - return paramScope_; + return param_scope_; } protected: - T *paramScope_; + T *param_scope_; }; class FunctionScope : public ScopeWithParamScope { @@ -412,7 +414,7 @@ public: void BindName(util::StringView name, util::StringView internalName) { name_ = name; - internalName_ = internalName; + internal_name_ = internalName; } const util::StringView &Name() const @@ -422,7 +424,7 @@ public: const util::StringView &InternalName() const { - return internalName_; + return internal_name_; } bool AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, @@ -430,7 +432,7 @@ public: private: util::StringView name_ {}; - util::StringView internalName_ {}; + util::StringView internal_name_ {}; }; class LocalScope : public Scope { @@ -482,7 +484,7 @@ public: ScopeType Type() const override { - return loopType_; + return loop_type_; } bool AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, @@ -494,7 +496,7 @@ public: Scope *InitScope() { if (NeedLexEnv()) { - return initScope_; + return init_scope_; } return this; @@ -504,9 +506,9 @@ public: private: friend class LoopScope; - LoopScope *loopScope_ {}; - LocalScope *initScope_ {}; - ScopeType loopType_ {ScopeType::LOCAL}; + LoopScope *loop_scope_ {}; + LocalScope *init_scope_ {}; + ScopeType loop_type_ {ScopeType::LOCAL}; }; class LoopScope : public VariableScope { @@ -515,18 +517,18 @@ public: LoopDeclarationScope *DeclScope() { - return declScope_; + return decl_scope_; } void BindDecls(LoopDeclarationScope *declScope) { - declScope_ = declScope; - declScope_->loopScope_ = this; + decl_scope_ = declScope; + decl_scope_->loop_scope_ = this; } ScopeType Type() const override { - return loopType_; + return loop_type_; } void ConvertToVariableScope(ArenaAllocator *allocator); @@ -538,8 +540,8 @@ public: } protected: - LoopDeclarationScope *declScope_ {}; - ScopeType loopType_ {ScopeType::LOCAL}; + LoopDeclarationScope *decl_scope_ {}; + ScopeType loop_type_ {ScopeType::LOCAL}; }; class GlobalScope : public FunctionScope { @@ -547,7 +549,7 @@ public: explicit GlobalScope(ArenaAllocator *allocator) : FunctionScope(allocator, nullptr) { auto *paramScope = allocator->New(allocator, this); - paramScope_ = paramScope; + param_scope_ = paramScope; } ScopeType Type() const override @@ -572,7 +574,7 @@ public: allocator_(allocator), imports_(allocator_->Adapter()), exports_(allocator_->Adapter()), - localExports_(allocator_->Adapter()) + local_exports_(allocator_->Adapter()) { } @@ -593,7 +595,7 @@ public: const LocalExportNameMap &LocalExports() const { - return localExports_; + return local_exports_; } void AddImportDecl(const ir::ImportDeclaration *importDecl, ImportDeclList &&decls); @@ -613,7 +615,7 @@ private: ArenaAllocator *allocator_; ModuleEntry imports_; ModuleEntry exports_; - LocalExportNameMap localExports_; + LocalExportNameMap local_exports_; }; template diff --git a/binder/variable.h b/binder/variable.h index 4302048a8bf2ccafe9887e3574da5bfd7be16f1c..d65a5d6b938110475de79dfabd39257d2736f926 100644 --- a/binder/variable.h +++ b/binder/variable.h @@ -76,12 +76,12 @@ public: checker::Type *TsType() const { - return tsType_; + return ts_type_; } void SetTsType(checker::Type *tsType) { - tsType_ = tsType; + ts_type_ = tsType; } void AddFlag(VariableFlags flag) @@ -118,7 +118,7 @@ protected: Decl *decl_; VariableFlags flags_ {}; - checker::Type *tsType_ {}; + checker::Type *ts_type_ {}; }; class LocalVariable : public Variable { @@ -184,35 +184,35 @@ public: compiler::VReg &ModuleReg() { - return moduleReg_; + return module_reg_; } compiler::VReg ModuleReg() const { - return moduleReg_; + return module_reg_; } const util::StringView &ExoticName() const { - return exoticName_; + return exotic_name_; } util::StringView &ExoticName() { - return exoticName_; + return exotic_name_; } void SetLexical([[maybe_unused]] Scope *scope) override; private: - compiler::VReg moduleReg_ {}; - util::StringView exoticName_ {}; + compiler::VReg module_reg_ {}; + util::StringView exotic_name_ {}; }; class EnumVariable : public Variable { public: explicit EnumVariable(Decl *decl, bool backReference = false) - : Variable(decl, VariableFlags::NONE), backReference_(backReference) + : Variable(decl, VariableFlags::NONE), back_reference_(backReference) { } @@ -233,12 +233,12 @@ public: bool BackReference() const { - return backReference_; + return back_reference_; } void SetBackReference() { - backReference_ = true; + back_reference_ = true; } void ResetDecl(Decl *decl); @@ -247,7 +247,7 @@ public: private: EnumMemberResult value_ {false}; - bool backReference_ {}; + bool back_reference_ {}; }; } // namespace panda::es2panda::binder diff --git a/compiler/base/catchTable.h b/compiler/base/catchTable.h index 9954ae9ff79d2901a4fb61cd0ce0848c5e67dca7..faf7f47b94a226df2b5452b6fdfe8305b649bd90 100644 --- a/compiler/base/catchTable.h +++ b/compiler/base/catchTable.h @@ -68,7 +68,7 @@ private: class CatchTable { public: - CatchTable(PandaGen *pg, uint32_t depth) : labelSet_(pg), depth_(depth) {} + CatchTable(PandaGen *pg, uint32_t depth) : label_set_(pg), depth_(depth) {} ~CatchTable() = default; NO_COPY_SEMANTIC(CatchTable); @@ -76,7 +76,7 @@ public: const TryLabelSet &LabelSet() const { - return labelSet_; + return label_set_; } uint32_t Depth() const @@ -85,7 +85,7 @@ public: } private: - TryLabelSet labelSet_; + TryLabelSet label_set_; uint32_t depth_; }; diff --git a/compiler/base/iterators.cpp b/compiler/base/iterators.cpp index 1bf7ad888797b1fb5f2c829aab527b4979a09c8a..8224c2f3975fa6085aa241bee16c31f85dc18ceb 100644 --- a/compiler/base/iterators.cpp +++ b/compiler/base/iterators.cpp @@ -24,7 +24,12 @@ namespace panda::es2panda::compiler { // Iterator Iterator::Iterator(PandaGen *pg, const ir::AstNode *node, IteratorType type) - : pg_(pg), node_(node), method_(pg->AllocReg()), iterator_(pg->AllocReg()), nextResult_(pg->AllocReg()), type_(type) + : pg_(pg), + node_(node), + method_(pg->AllocReg()), + iterator_(pg->AllocReg()), + next_result_(pg->AllocReg()), + type_(type) { if (type_ == IteratorType::ASYNC) { pg_->GetAsyncIterator(node); @@ -64,18 +69,18 @@ void Iterator::Next() const } pg_->ThrowIfNotObject(node_); - pg_->StoreAccumulator(node_, nextResult_); + pg_->StoreAccumulator(node_, next_result_); } void Iterator::Complete() const { - pg_->LoadObjByName(node_, nextResult_, "done"); + pg_->LoadObjByName(node_, next_result_, "done"); pg_->ToBoolean(node_); } void Iterator::Value() const { - pg_->LoadObjByName(node_, nextResult_, "value"); + pg_->LoadObjByName(node_, next_result_, "value"); } void Iterator::Close(bool abruptCompletion) const diff --git a/compiler/base/iterators.h b/compiler/base/iterators.h index 0f23818d9ed2015bc8db01e274ba63b5a064dea1..ed1db0aef131b8132bfac30551c27b95020a8784 100644 --- a/compiler/base/iterators.h +++ b/compiler/base/iterators.h @@ -47,7 +47,7 @@ public: VReg NextResult() const { - return nextResult_; + return next_result_; } const ir::AstNode *Node() const @@ -70,7 +70,7 @@ protected: // These 3 regs must be allocated continously VReg method_; VReg iterator_; - VReg nextResult_; + VReg next_result_; IteratorType type_; }; diff --git a/compiler/base/lexenv.cpp b/compiler/base/lexenv.cpp index f3410f06c2ff81e8e0a5a098f5909111720f2970..21470e7a4b705812a0a26b2b5e4c8907f1feec2d 100644 --- a/compiler/base/lexenv.cpp +++ b/compiler/base/lexenv.cpp @@ -43,13 +43,13 @@ static void CheckConstAssignment(PandaGen *pg, const ir::AstNode *node, binder:: static void ExpandLoadLexVar(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result) { - pg->LoadLexicalVar(node, result.lexLevel, result.variable->AsLocalVariable()->LexIdx()); - pg->ThrowUndefinedIfHole(node, result.variable->Name()); + pg->LoadLexicalVar(node, result.lex_level_, result.variable_->AsLocalVariable()->LexIdx()); + pg->ThrowUndefinedIfHole(node, result.variable_->Name()); } static void ExpandLoadNormalVar(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result) { - auto *local = result.variable->AsLocalVariable(); + auto *local = result.variable_->AsLocalVariable(); if (CheckTdz(node)) { pg->LoadConst(node, Constant::JS_HOLE); @@ -61,7 +61,7 @@ static void ExpandLoadNormalVar(PandaGen *pg, const ir::AstNode *node, const bin void VirtualLoadVar::Expand(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result) { - if (result.variable->LexicalBound()) { + if (result.variable_->LexicalBound()) { ExpandLoadLexVar(pg, node, result); } else { ExpandLoadNormalVar(pg, node, result); @@ -87,9 +87,9 @@ static void StoreLocalExport(PandaGen *pg, const ir::AstNode *node, binder::Vari static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result, bool isDecl) { - binder::LocalVariable *local = result.variable->AsLocalVariable(); + binder::LocalVariable *local = result.variable_->AsLocalVariable(); - const auto *decl = result.variable->Declaration(); + const auto *decl = result.variable_->Declaration(); if (decl->IsLetOrConstDecl() && !isDecl) { RegScope rs(pg); @@ -106,7 +106,7 @@ static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const binde pg->LoadAccumulator(node, valueReg); } - pg->StoreLexicalVar(node, result.lexLevel, local->LexIdx()); + pg->StoreLexicalVar(node, result.lex_level_, local->LexIdx()); StoreLocalExport(pg, node, local); } @@ -114,7 +114,7 @@ static void ExpandStoreLexVar(PandaGen *pg, const ir::AstNode *node, const binde static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result, bool isDecl) { - auto *local = result.variable->AsLocalVariable(); + auto *local = result.variable_->AsLocalVariable(); VReg localReg = local->Vreg(); if (!isDecl) { @@ -132,7 +132,7 @@ static void ExpandStoreNormalVar(PandaGen *pg, const ir::AstNode *node, const bi void VirtualStoreVar::Expand(PandaGen *pg, const ir::AstNode *node, const binder::ScopeFindResult &result, bool isDecl) { - if (result.variable->LexicalBound()) { + if (result.variable_->LexicalBound()) { ExpandStoreLexVar(pg, node, result, isDecl); } else { ExpandStoreNormalVar(pg, node, result, isDecl); diff --git a/compiler/base/lreference.cpp b/compiler/base/lreference.cpp index 6fd21e14eedd2b4be322b5746b6411bd6f70a279..0920305bbf4fb3bfd0a29440c30971d6e0213ca0 100644 --- a/compiler/base/lreference.cpp +++ b/compiler/base/lreference.cpp @@ -31,7 +31,7 @@ namespace panda::es2panda::compiler { LReference::LReference(const ir::AstNode *node, PandaGen *pg, bool isDeclaration, ReferenceKind refKind, binder::ScopeFindResult res) - : node_(node), pg_(pg), refKind_(refKind), res_(res), isDeclaration_(isDeclaration) + : node_(node), pg_(pg), ref_kind_(refKind), res_(res), is_declaration_(isDeclaration) { if (refKind == ReferenceKind::MEMBER) { obj_ = pg_->AllocReg(); @@ -43,7 +43,7 @@ LReference::LReference(const ir::AstNode *node, PandaGen *pg, bool isDeclaration void LReference::GetValue() { - switch (refKind_) { + switch (ref_kind_) { case ReferenceKind::VAR_OR_GLOBAL: { pg_->LoadVar(node_->AsIdentifier(), res_); break; @@ -60,9 +60,9 @@ void LReference::GetValue() void LReference::SetValue() { - switch (refKind_) { + switch (ref_kind_) { case ReferenceKind::VAR_OR_GLOBAL: { - pg_->StoreVar(node_, res_, isDeclaration_); + pg_->StoreVar(node_, res_, is_declaration_); break; } case ReferenceKind::MEMBER: { @@ -86,12 +86,12 @@ void LReference::SetValue() ReferenceKind LReference::Kind() const { - return refKind_; + return ref_kind_; } binder::Variable *LReference::Variable() const { - return res_.variable; + return res_.variable_; } LReference LReference::CreateLRef(PandaGen *pg, const ir::AstNode *node, bool isDeclaration) diff --git a/compiler/base/lreference.h b/compiler/base/lreference.h index e7edf06f7b90d4f08a94bce2f7faaa85dea5c880..5da628d4079c4d68a886bc16fe1c7b898c4a51d1 100644 --- a/compiler/base/lreference.h +++ b/compiler/base/lreference.h @@ -56,11 +56,11 @@ public: private: const ir::AstNode *node_; PandaGen *pg_; - ReferenceKind refKind_; + ReferenceKind ref_kind_; binder::ScopeFindResult res_; VReg obj_; Operand prop_; - bool isDeclaration_; + bool is_declaration_; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/compileQueue.cpp b/compiler/core/compileQueue.cpp index 29460a7b3b4a59143e2c994747b7587c334251af..edea06bc46c83e69f05652f4a6679c814e2620e3 100644 --- a/compiler/core/compileQueue.cpp +++ b/compiler/core/compileQueue.cpp @@ -76,7 +76,7 @@ CompileQueue::~CompileQueue() std::unique_lock lock(m_); terminate_ = true; lock.unlock(); - jobsAvailable_.notify_all(); + jobs_available_.notify_all(); for (const auto handle_id : threads_) { os::thread::ThreadJoin(handle_id, &retval); @@ -85,24 +85,24 @@ CompileQueue::~CompileQueue() void CompileQueue::Schedule(CompilerContext *context) { - ASSERT(jobsCount_ == 0); + ASSERT(jobs_count_ == 0); std::unique_lock lock(m_); const auto &functions = context->Binder()->Functions(); jobs_ = new CompileJob[functions.size()](); for (auto *function : functions) { - jobs_[jobsCount_++].SetConext(context, function); + jobs_[jobs_count_++].SetConext(context, function); } lock.unlock(); - jobsAvailable_.notify_all(); + jobs_available_.notify_all(); } void CompileQueue::Worker(CompileQueue *queue) { while (true) { std::unique_lock lock(queue->m_); - queue->jobsAvailable_.wait(lock, [queue]() { return queue->terminate_ || queue->jobsCount_ != 0; }); + queue->jobs_available_.wait(lock, [queue]() { return queue->terminate_ || queue->jobs_count_ != 0; }); if (queue->terminate_) { return; @@ -111,18 +111,18 @@ void CompileQueue::Worker(CompileQueue *queue) lock.unlock(); queue->Consume(); - queue->jobsFinished_.notify_one(); + queue->jobs_finished_.notify_one(); } } void CompileQueue::Consume() { std::unique_lock lock(m_); - activeWorkers_++; + active_workers_++; - while (jobsCount_ > 0) { - --jobsCount_; - auto &job = jobs_[jobsCount_]; + while (jobs_count_ > 0) { + --jobs_count_; + auto &job = jobs_[jobs_count_]; lock.unlock(); @@ -137,13 +137,13 @@ void CompileQueue::Consume() lock.lock(); } - activeWorkers_--; + active_workers_--; } void CompileQueue::Wait() { std::unique_lock lock(m_); - jobsFinished_.wait(lock, [this]() { return activeWorkers_ == 0 && jobsCount_ == 0; }); + jobs_finished_.wait(lock, [this]() { return active_workers_ == 0 && jobs_count_ == 0; }); delete[] jobs_; if (!errors_.empty()) { diff --git a/compiler/core/compileQueue.h b/compiler/core/compileQueue.h index 5e227475ba26c314078b5d5f4108a8b5c069ee63..0499a66cf700c9d7cb1b2dd9ae19bce5f5fdaf4f 100644 --- a/compiler/core/compileQueue.h +++ b/compiler/core/compileQueue.h @@ -79,11 +79,11 @@ private: std::vector threads_; std::vector errors_; std::mutex m_; - std::condition_variable jobsAvailable_; - std::condition_variable jobsFinished_; + std::condition_variable jobs_available_; + std::condition_variable jobs_finished_; CompileJob *jobs_ {}; - size_t jobsCount_ {0}; - size_t activeWorkers_ {0}; + size_t jobs_count_ {0}; + size_t active_workers_ {0}; bool terminate_ {false}; }; diff --git a/compiler/core/compilerContext.cpp b/compiler/core/compilerContext.cpp index 6a97c410fdd32e9a6b48274c4700ec069553893c..35c62d4678357a3c4a00247b710ca81c8977acab 100644 --- a/compiler/core/compilerContext.cpp +++ b/compiler/core/compilerContext.cpp @@ -20,7 +20,7 @@ namespace panda::es2panda::compiler { CompilerContext::CompilerContext(binder::Binder *binder, bool isDebug) - : binder_(binder), emitter_(std::make_unique(this)), isDebug_(isDebug) + : binder_(binder), emitter_(std::make_unique(this)), is_debug_(isDebug) { } diff --git a/compiler/core/compilerContext.h b/compiler/core/compilerContext.h index 517163ae62d861c45600c38321c9780a62103e3a..90a97fa6d08142fbabb146cc8224dc5f1c1e0d86 100644 --- a/compiler/core/compilerContext.h +++ b/compiler/core/compilerContext.h @@ -50,13 +50,13 @@ public: int32_t LiteralCount() const { - return literalBufferIdx_; + return literal_buffer_idx_; } int32_t NewLiteralIndex() { std::lock_guard lock(m_); - return literalBufferIdx_++; + return literal_buffer_idx_++; } std::mutex &Mutex() @@ -66,15 +66,15 @@ public: bool IsDebug() const { - return isDebug_; + return is_debug_; } private: binder::Binder *binder_; std::unique_ptr emitter_; - int32_t literalBufferIdx_ {0}; + int32_t literal_buffer_idx_ {0}; std::mutex m_; - bool isDebug_; + bool is_debug_; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/compilerImpl.cpp b/compiler/core/compilerImpl.cpp index c4ff569b2a7da04f7405cbb0f76ded8ea043606e..32d523844a1c9876bd6c4cf90602ef2eec8a57b9 100644 --- a/compiler/core/compilerImpl.cpp +++ b/compiler/core/compilerImpl.cpp @@ -36,7 +36,7 @@ CompilerImpl::~CompilerImpl() panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const es2panda::CompilerOptions &options) { - CompilerContext context(program->Binder(), options.isDebug); + CompilerContext context(program->Binder(), options.is_debug_); if (program->Extension() == ScriptExtension::TS) { ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); @@ -53,7 +53,7 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e queue_->Consume(); queue_->Wait(); - return context.GetEmitter()->Finalize(options.dumpDebugInfo); + return context.GetEmitter()->Finalize(options.dump_debug_info_); } void CompilerImpl::DumpAsm(const panda::pandasm::Program *prog) diff --git a/compiler/core/dynamicContext.cpp b/compiler/core/dynamicContext.cpp index 73e9e9ddcb08b589c09a48c9d822fe1497086fb4..936ff81aaf3109aebaec2d0b992cbd1484720980 100644 --- a/compiler/core/dynamicContext.cpp +++ b/compiler/core/dynamicContext.cpp @@ -23,18 +23,19 @@ #include namespace panda::es2panda::compiler { -DynamicContext::DynamicContext(PandaGen *pg, LabelTarget target) : pg_(pg), target_(target), prev_(pg_->dynamicContext_) +DynamicContext::DynamicContext(PandaGen *pg, LabelTarget target) + : pg_(pg), target_(target), prev_(pg_->dynamic_context_) { - pg_->dynamicContext_ = this; + pg_->dynamic_context_ = this; } DynamicContext::~DynamicContext() { - pg_->dynamicContext_ = prev_; + pg_->dynamic_context_ = prev_; } LabelContext::LabelContext(PandaGen *pg, const ir::LabelledStatement *labelledStmt) - : DynamicContext(pg, LabelTarget(labelledStmt->Ident()->Name())), labelledStmt_(labelledStmt) + : DynamicContext(pg, LabelTarget(labelledStmt->Ident()->Name())), labelled_stmt_(labelledStmt) { if (!labelledStmt->Body()->IsBlockStatement()) { return; @@ -50,31 +51,31 @@ LabelContext::~LabelContext() return; } - pg_->SetLabel(labelledStmt_, label_); + pg_->SetLabel(labelled_stmt_, label_); } LexEnvContext::LexEnvContext(LoopEnvScope *envScope, PandaGen *pg, LabelTarget target) - : DynamicContext(pg, target), envScope_(envScope) + : DynamicContext(pg, target), env_scope_(envScope) { - if (!envScope_->HasEnv()) { + if (!env_scope_->HasEnv()) { return; } - catchTable_ = pg_->CreateCatchTable(); - const auto &labelSet = catchTable_->LabelSet(); - const auto *node = envScope_->Scope()->Node(); + catch_table_ = pg_->CreateCatchTable(); + const auto &labelSet = catch_table_->LabelSet(); + const auto *node = env_scope_->Scope()->Node(); pg_->SetLabel(node, labelSet.TryBegin()); } LexEnvContext::~LexEnvContext() { - if (!envScope_->HasEnv()) { + if (!env_scope_->HasEnv()) { return; } - const auto &labelSet = catchTable_->LabelSet(); - const auto *node = envScope_->Scope()->Node(); + const auto &labelSet = catch_table_->LabelSet(); + const auto *node = env_scope_->Scope()->Node(); pg_->SetLabel(node, labelSet.TryEnd()); pg_->Branch(node, labelSet.CatchEnd()); @@ -88,30 +89,30 @@ LexEnvContext::~LexEnvContext() bool LexEnvContext::HasTryCatch() const { - return envScope_->HasEnv(); + return env_scope_->HasEnv(); } void LexEnvContext::AbortContext([[maybe_unused]] ControlFlowChange cfc, [[maybe_unused]] const util::StringView &targetLabel) { - if (cfc == ControlFlowChange::CONTINUE || !envScope_->HasEnv()) { + if (cfc == ControlFlowChange::CONTINUE || !env_scope_->HasEnv()) { return; } - const auto *node = envScope_->Scope()->Node(); + const auto *node = env_scope_->Scope()->Node(); pg_->PopLexEnv(node); } IteratorContext::IteratorContext(PandaGen *pg, const Iterator &iterator, LabelTarget target) - : DynamicContext(pg, target), iterator_(iterator), catchTable_(pg->CreateCatchTable()) + : DynamicContext(pg, target), iterator_(iterator), catch_table_(pg->CreateCatchTable()) { - const auto &labelSet = catchTable_->LabelSet(); + const auto &labelSet = catch_table_->LabelSet(); pg_->SetLabel(iterator_.Node(), labelSet.TryBegin()); } IteratorContext::~IteratorContext() { - const auto &labelSet = catchTable_->LabelSet(); + const auto &labelSet = catch_table_->LabelSet(); const auto *node = iterator_.Node(); pg_->SetLabel(node, labelSet.TryEnd()); @@ -134,40 +135,40 @@ void IteratorContext::AbortContext([[maybe_unused]] ControlFlowChange cfc, void TryContext::InitFinalizer() { - ASSERT(tryStmt_); + ASSERT(try_stmt_); - if (!hasFinalizer_ || !tryStmt_->FinallyBlock()) { + if (!has_finalizer_ || !try_stmt_->FinallyBlock()) { return; } - finalizerRun_ = pg_->AllocReg(); - pg_->StoreConst(tryStmt_, finalizerRun_, Constant::JS_UNDEFINED); + finalizer_run_ = pg_->AllocReg(); + pg_->StoreConst(try_stmt_, finalizer_run_, Constant::JS_UNDEFINED); } void TryContext::InitCatchTable() { - catchTable_ = pg_->CreateCatchTable(); + catch_table_ = pg_->CreateCatchTable(); } const TryLabelSet &TryContext::LabelSet() const { - return catchTable_->LabelSet(); + return catch_table_->LabelSet(); } bool TryContext::HasFinalizer() const { - return hasFinalizer_; + return has_finalizer_; } void TryContext::EmitFinalizer() { - if (!hasFinalizer_ || inFinalizer_ || !tryStmt_->FinallyBlock()) { + if (!has_finalizer_ || in_finalizer_ || !try_stmt_->FinallyBlock()) { return; } - inFinalizer_ = true; - tryStmt_->FinallyBlock()->Compile(pg_); - inFinalizer_ = false; + in_finalizer_ = true; + try_stmt_->FinallyBlock()->Compile(pg_); + in_finalizer_ = false; } void TryContext::AbortContext([[maybe_unused]] ControlFlowChange cfc, diff --git a/compiler/core/dynamicContext.h b/compiler/core/dynamicContext.h index 2e13faab6e9ab022393fa06168150f4af0fa2590..cb766aacfbb643adbe98f8437800cd6745a6fa9a 100644 --- a/compiler/core/dynamicContext.h +++ b/compiler/core/dynamicContext.h @@ -97,7 +97,7 @@ public: private: Label *label_ {}; - const ir::LabelledStatement *labelledStmt_ {}; + const ir::LabelledStatement *labelled_stmt_ {}; }; class LexEnvContext : public DynamicContext { @@ -117,8 +117,8 @@ public: [[maybe_unused]] const util::StringView &targetLabel) override; private: - LoopEnvScope *envScope_; - CatchTable *catchTable_ {}; + LoopEnvScope *env_scope_; + CatchTable *catch_table_ {}; }; class IteratorContext : public DynamicContext { @@ -148,13 +148,13 @@ public: private: const Iterator &iterator_; - CatchTable *catchTable_; + CatchTable *catch_table_; }; class TryContext : public DynamicContext { public: explicit TryContext(PandaGen *pg, const ir::TryStatement *tryStmt, bool hasFinalizer = true) - : DynamicContext(pg, {}), tryStmt_(tryStmt), hasFinalizer_(hasFinalizer) + : DynamicContext(pg, {}), try_stmt_(tryStmt), has_finalizer_(hasFinalizer) { InitCatchTable(); InitFinalizer(); @@ -181,12 +181,12 @@ public: VReg FinalizerRun() const { - return finalizerRun_; + return finalizer_run_; } CatchTable *GetCatchTable() const { - return catchTable_; + return catch_table_; } const TryLabelSet &LabelSet() const; @@ -200,11 +200,11 @@ public: private: void InitCatchTable(); - const ir::TryStatement *tryStmt_ {}; - CatchTable *catchTable_ {}; - VReg finalizerRun_ {}; - bool hasFinalizer_ {}; - bool inFinalizer_ {}; + const ir::TryStatement *try_stmt_ {}; + CatchTable *catch_table_ {}; + VReg finalizer_run_ {}; + bool has_finalizer_ {}; + bool in_finalizer_ {}; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/emitter.cpp b/compiler/core/emitter.cpp index 6e617cb41f196d3b1ae3fdc361eed462f28af155..86826b88145c94f448239b2a84215a8a6ea5e032 100644 --- a/compiler/core/emitter.cpp +++ b/compiler/core/emitter.cpp @@ -41,19 +41,19 @@ namespace panda::es2panda::compiler { constexpr const auto LANG_EXT = panda::pandasm::extensions::Language::ECMASCRIPT; FunctionEmitter::FunctionEmitter(ArenaAllocator *allocator, const PandaGen *pg) - : pg_(pg), literalBuffers_(allocator->Adapter()) + : pg_(pg), literal_buffers_(allocator->Adapter()) { func_ = allocator->New(pg->InternalName().Mutf8(), LANG_EXT); size_t paramCount = pg->InternalParamCount(); - func_->params.reserve(paramCount); + func_->params_.reserve(paramCount); for (uint32_t i = 0; i < paramCount; ++i) { - func_->params.emplace_back(panda::pandasm::Type("any", 0), LANG_EXT); + func_->params_.emplace_back(panda::pandasm::Type("any", 0), LANG_EXT); } - func_->regs_num = pg->TotalRegsNum(); - func_->return_type = panda::pandasm::Type("any", 0); + func_->regs_num_ = pg->TotalRegsNum(); + func_->return_type_ = panda::pandasm::Type("any", 0); } void FunctionEmitter::Generate() @@ -73,7 +73,7 @@ const ArenaSet &FunctionEmitter::Strings() const void FunctionEmitter::GenBufferLiterals(const LiteralBuffer *buff) { - auto &[idx, array] = literalBuffers_.emplace_back(); + auto &[idx, array] = literal_buffers_.emplace_back(); idx = buff->Index(); array.reserve(buff->Literals().size() * 2); @@ -192,7 +192,7 @@ static size_t GetIRNodeWholeLength(const IRNode *node) static std::string WholeLine(const util::StringView &source, lexer::SourceRange range) { - return source.Substr(range.start.index, range.end.index).EscapeSymbol(); + return source.Substr(range.start_.index_, range.end_.index_).EscapeSymbol(); } void FunctionEmitter::GenInstructionDebugInfo(const IRNode *ins, panda::pandasm::Ins *pandaIns) @@ -202,32 +202,32 @@ void FunctionEmitter::GenInstructionDebugInfo(const IRNode *ins, panda::pandasm: ASSERT(astNode != nullptr); if (astNode == FIRST_NODE_OF_FUNCTION) { - astNode = pg_->Debuginfo().firstStmt; + astNode = pg_->Debuginfo().first_stmt_; if (!astNode) { return; } } - pandaIns->ins_debug.line_number = astNode->Range().start.line + 1; + pandaIns->ins_debug_.line_number_ = astNode->Range().start_.line_ + 1; if (pg_->IsDebug()) { size_t insLen = GetIRNodeWholeLength(ins); if (insLen != 0) { - pandaIns->ins_debug.bound_left = offset_; - pandaIns->ins_debug.bound_right = offset_ + insLen; + pandaIns->ins_debug_.bound_left_ = offset_; + pandaIns->ins_debug_.bound_right_ = offset_ + insLen; } offset_ += insLen; - pandaIns->ins_debug.whole_line = WholeLine(SourceCode(), astNode->Range()); + pandaIns->ins_debug_.whole_line_ = WholeLine(SourceCode(), astNode->Range()); } } void FunctionEmitter::GenFunctionInstructions() { - func_->ins.reserve(pg_->Insns().size()); + func_->ins_.reserve(pg_->Insns().size()); for (const auto *ins : pg_->Insns()) { - auto &pandaIns = func_->ins.emplace_back(); + auto &pandaIns = func_->ins_.emplace_back(); ins->Transform(&pandaIns); GenInstructionDebugInfo(ins, &pandaIns); @@ -254,21 +254,21 @@ void FunctionEmitter::GenFunctionICSize() panda::pandasm::ScalarValue::Create(pg_->FunctionName().Mutf8()))); funcAnnotationData.AddElement(std::move(funcNameAnnotationElement)); - func_->metadata->AddAnnotations({funcAnnotationData}); + func_->metadata_->AddAnnotations({funcAnnotationData}); } void FunctionEmitter::GenFunctionCatchTables() { - func_->catch_blocks.reserve(pg_->CatchList().size()); + func_->catch_blocks_.reserve(pg_->CatchList().size()); for (const auto *catchBlock : pg_->CatchList()) { const auto &labelSet = catchBlock->LabelSet(); - auto &pandaCatchBlock = func_->catch_blocks.emplace_back(); - pandaCatchBlock.try_begin_label = labelSet.TryBegin()->Id(); - pandaCatchBlock.try_end_label = labelSet.TryEnd()->Id(); - pandaCatchBlock.catch_begin_label = labelSet.CatchBegin()->Id(); - pandaCatchBlock.catch_end_label = labelSet.CatchEnd()->Id(); + auto &pandaCatchBlock = func_->catch_blocks_.emplace_back(); + pandaCatchBlock.try_begin_label_ = labelSet.TryBegin()->Id(); + pandaCatchBlock.try_end_label_ = labelSet.TryEnd()->Id(); + pandaCatchBlock.catch_begin_label_ = labelSet.CatchBegin()->Id(); + pandaCatchBlock.catch_end_label_ = labelSet.CatchEnd()->Id(); } } @@ -281,14 +281,14 @@ void FunctionEmitter::GenLiteralBuffers() void FunctionEmitter::GenSourceFileDebugInfo() { - func_->source_file = std::string {pg_->Binder()->Program()->SourceFile()}; + func_->source_file_ = std::string {pg_->Binder()->Program()->SourceFile()}; if (!pg_->IsDebug()) { return; } if (pg_->RootNode()->IsProgram()) { - func_->source_code = SourceCode().EscapeSymbol(); + func_->source_code_ = SourceCode().EscapeSymbol(); } } @@ -311,13 +311,13 @@ void FunctionEmitter::GenScopeVariableInfo(const binder::Scope *scope) continue; } - auto &variableDebug = func_->local_variable_debug.emplace_back(); - variableDebug.name = name.Mutf8(); - variableDebug.signature = "any"; - variableDebug.signature_type = "any"; - variableDebug.reg = static_cast(variable->AsLocalVariable()->Vreg()); - variableDebug.start = start; - variableDebug.length = static_cast(varsLength); + auto &variableDebug = func_->local_variable_debug_.emplace_back(); + variableDebug.name_ = name.Mutf8(); + variableDebug.signature_ = "any"; + variableDebug.signature_type_ = "any"; + variableDebug.reg_ = static_cast(variable->AsLocalVariable()->Vreg()); + variableDebug.start_ = start; + variableDebug.length_ = static_cast(varsLength); } break; @@ -333,7 +333,7 @@ void FunctionEmitter::GenVariablesDebugInfo() return; } - for (const auto *scope : pg_->Debuginfo().variableDebugInfo) { + for (const auto *scope : pg_->Debuginfo().variable_debug_info_) { GenScopeVariableInfo(scope); } } @@ -343,9 +343,9 @@ void FunctionEmitter::GenVariablesDebugInfo() Emitter::Emitter(const CompilerContext *context) { prog_ = new panda::pandasm::Program(); - prog_->lang = panda::pandasm::extensions::Language::ECMASCRIPT; + prog_->lang_ = panda::pandasm::extensions::Language::ECMASCRIPT; - prog_->function_table.reserve(context->Binder()->Functions().size()); + prog_->function_table_.reserve(context->Binder()->Functions().size()); GenESAnnoatationRecord(); GenESModuleModeRecord(context->Binder()->Program()->Kind() == parser::ScriptKind::MODULE); } @@ -358,25 +358,25 @@ Emitter::~Emitter() void Emitter::GenESAnnoatationRecord() { auto annotationRecord = panda::pandasm::Record("_ESAnnotation", LANG_EXT); - annotationRecord.metadata->SetAttribute("external"); - annotationRecord.metadata->SetAccessFlags(panda::ACC_ANNOTATION); - prog_->record_table.emplace(annotationRecord.name, std::move(annotationRecord)); + annotationRecord.metadata_->SetAttribute("external"); + annotationRecord.metadata_->SetAccessFlags(panda::ACC_ANNOTATION); + prog_->record_table_.emplace(annotationRecord.name_, std::move(annotationRecord)); } void Emitter::GenESModuleModeRecord(bool isModule) { auto modeRecord = panda::pandasm::Record("_ESModuleMode", LANG_EXT); - modeRecord.metadata->SetAccessFlags(panda::ACC_PUBLIC); + modeRecord.metadata_->SetAccessFlags(panda::ACC_PUBLIC); auto modeField = panda::pandasm::Field(LANG_EXT); - modeField.name = "isModule"; - modeField.type = panda::pandasm::Type("u8", 0); - modeField.metadata->SetValue( + modeField.name_ = "isModule"; + modeField.type_ = panda::pandasm::Type("u8", 0); + modeField.metadata_->SetValue( panda::pandasm::ScalarValue::Create(static_cast(isModule))); - modeRecord.field_list.emplace_back(std::move(modeField)); + modeRecord.field_list_.emplace_back(std::move(modeField)); - prog_->record_table.emplace(modeRecord.name, std::move(modeRecord)); + prog_->record_table_.emplace(modeRecord.name_, std::move(modeRecord)); } void Emitter::AddFunction(FunctionEmitter *func) @@ -384,16 +384,16 @@ void Emitter::AddFunction(FunctionEmitter *func) std::lock_guard lock(m_); for (const auto &str : func->Strings()) { - prog_->strings.insert(str.Mutf8()); + prog_->strings_.insert(str.Mutf8()); } for (auto &[idx, buf] : func->LiteralBuffers()) { auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(buf)); - prog_->literalarray_table.emplace(std::to_string(idx), std::move(literalArrayInstance)); + prog_->literalarray_table_.emplace(std::to_string(idx), std::move(literalArrayInstance)); } auto *function = func->Function(); - prog_->function_table.emplace(function->name, std::move(*function)); + prog_->function_table_.emplace(function->name_, std::move(*function)); } void Emitter::DumpAsm(const panda::pandasm::Program *prog) @@ -402,7 +402,7 @@ void Emitter::DumpAsm(const panda::pandasm::Program *prog) ss << ".language ECMAScript" << std::endl << std::endl; - for (auto &[name, func] : prog->function_table) { + for (auto &[name, func] : prog->function_table_) { ss << ".function any " << name << '('; for (uint32_t i = 0; i < func.GetParamsNum(); i++) { @@ -415,14 +415,14 @@ void Emitter::DumpAsm(const panda::pandasm::Program *prog) ss << ") {" << std::endl; - for (const auto &ins : func.ins) { - ss << (ins.set_label ? "" : "\t") << ins.ToString("", true, func.GetTotalRegs()) << std::endl; + for (const auto &ins : func.ins_) { + ss << (ins.set_label_ ? "" : "\t") << ins.ToString("", true, func.GetTotalRegs()) << std::endl; } ss << "}" << std::endl << std::endl; - for (const auto &ct : func.catch_blocks) { - ss << ".catchall " << ct.try_begin_label << ", " << ct.try_end_label << ", " << ct.catch_begin_label + for (const auto &ct : func.catch_blocks_) { + ss << ".catchall " << ct.try_begin_label_ << ", " << ct.try_end_label_ << ", " << ct.catch_begin_label_ << std::endl << std::endl; } diff --git a/compiler/core/emitter.h b/compiler/core/emitter.h index addf4b142b4daaeb21c86c5edcf424de01ea2c0b..176601b46bc299d675965670cba06e2188b51067 100644 --- a/compiler/core/emitter.h +++ b/compiler/core/emitter.h @@ -66,7 +66,7 @@ public: auto &LiteralBuffers() { - return literalBuffers_; + return literal_buffers_; } void Generate(); @@ -87,7 +87,7 @@ private: const PandaGen *pg_; panda::pandasm::Function *func_ {}; - ArenaVector>> literalBuffers_; + ArenaVector>> literal_buffers_; size_t offset_ {0}; }; diff --git a/compiler/core/envScope.cpp b/compiler/core/envScope.cpp index 6e2fa13c78c7038bb1a0d4e2a0eb7405af141868..5d5c643a6e2e350d1ad72144a4352ee3fe6b9a08 100644 --- a/compiler/core/envScope.cpp +++ b/compiler/core/envScope.cpp @@ -20,22 +20,22 @@ namespace panda::es2panda::compiler { -ScopeContext::ScopeContext(PandaGen *pg, binder::Scope *newScope) : pg_(pg), prevScope_(pg_->scope_) +ScopeContext::ScopeContext(PandaGen *pg, binder::Scope *newScope) : pg_(pg), prev_scope_(pg_->scope_) { pg_->scope_ = newScope; } ScopeContext::~ScopeContext() { - pg_->scope_ = prevScope_; + pg_->scope_ = prev_scope_; } void EnvScope::Initialize(PandaGen *pg, VReg lexEnv) { pg_ = pg; - prev_ = pg_->envScope_; - lexEnv_ = lexEnv; - pg_->envScope_ = this; + prev_ = pg_->env_scope_; + lex_env_ = lexEnv; + pg_->env_scope_ = this; } EnvScope::~EnvScope() @@ -44,7 +44,7 @@ EnvScope::~EnvScope() return; } - pg_->envScope_ = prev_; + pg_->env_scope_ = prev_; } void LoopEnvScope::CopyBindings(PandaGen *pg, binder::VariableScope *scope, binder::VariableFlags flag) @@ -56,7 +56,7 @@ void LoopEnvScope::CopyBindings(PandaGen *pg, binder::VariableScope *scope, bind Initialize(pg, pg->AllocReg()); pg_->NewLexEnv(scope_->Node(), scope->LexicalSlots()); - pg_->StoreAccumulator(scope_->Node(), lexEnv_); + pg_->StoreAccumulator(scope_->Node(), lex_env_); ASSERT(scope->NeedLexEnv()); @@ -78,7 +78,7 @@ void LoopEnvScope::CopyPetIterationCtx() } pg_->CopyLexEnv(scope_->Node()); - pg_->StoreAccumulator(scope_->Node(), lexEnv_); + pg_->StoreAccumulator(scope_->Node(), lex_env_); } } // namespace panda::es2panda::compiler diff --git a/compiler/core/envScope.h b/compiler/core/envScope.h index 55b801a7a1f3e026a9403344d896fdbedc68ecbe..0d9bdcbb5d08cc057fc94e324eb115b4497b8666 100644 --- a/compiler/core/envScope.h +++ b/compiler/core/envScope.h @@ -41,7 +41,7 @@ public: private: PandaGen *pg_; - binder::Scope *prevScope_; + binder::Scope *prev_scope_; }; class EnvScope { @@ -56,7 +56,7 @@ public: VReg LexEnv() const { - return lexEnv_; + return lex_env_; } EnvScope *Prev() const @@ -69,25 +69,25 @@ protected: PandaGen *pg_ {}; EnvScope *prev_ {}; - VReg lexEnv_ {}; + VReg lex_env_ {}; }; class LoopEnvScope : public EnvScope { public: explicit LoopEnvScope(PandaGen *pg, binder::LoopScope *scope, LabelTarget target) - : scope_(NeedEnv(scope) ? scope : nullptr), regScope_(pg, scope), lexEnvCtx_(this, pg, target) + : scope_(NeedEnv(scope) ? scope : nullptr), reg_scope_(pg, scope), lex_env_ctx_(this, pg, target) { CopyBindings(pg, scope, binder::VariableFlags::PER_ITERATION); } explicit LoopEnvScope(PandaGen *pg, LabelTarget target, binder::LoopScope *scope) - : scope_(NeedEnv(scope) ? scope : nullptr), regScope_(pg), lexEnvCtx_(this, pg, target) + : scope_(NeedEnv(scope) ? scope : nullptr), reg_scope_(pg), lex_env_ctx_(this, pg, target) { CopyBindings(pg, scope, binder::VariableFlags::PER_ITERATION); } explicit LoopEnvScope(PandaGen *pg, binder::LoopDeclarationScope *scope) - : scope_(NeedEnv(scope) ? scope : nullptr), regScope_(pg), lexEnvCtx_(this, pg, {}) + : scope_(NeedEnv(scope) ? scope : nullptr), reg_scope_(pg), lex_env_ctx_(this, pg, {}) { CopyBindings(pg, scope, binder::VariableFlags::LOOP_DECL); } @@ -114,8 +114,8 @@ private: void CopyBindings(PandaGen *pg, binder::VariableScope *scope, binder::VariableFlags flag); binder::VariableScope *scope_ {}; - LocalRegScope regScope_; - LexEnvContext lexEnvCtx_; + LocalRegScope reg_scope_; + LexEnvContext lex_env_ctx_; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/labelTarget.cpp b/compiler/core/labelTarget.cpp index 3fc9530fa07e3b66cd8c6e982274efeee2cfc3b1..38f386c377f4e4d414919b3ea25fa4b975155618 100644 --- a/compiler/core/labelTarget.cpp +++ b/compiler/core/labelTarget.cpp @@ -20,7 +20,7 @@ namespace panda::es2panda::compiler { LabelTarget::LabelTarget(PandaGen *pg) - : LabelPair(pg->AllocLabel(), pg->AllocLabel()), breakLabel_(BREAK_LABEL), continueLabel_(CONTINUE_LABEL) + : LabelPair(pg->AllocLabel(), pg->AllocLabel()), break_label_(BREAK_LABEL), continue_label_(CONTINUE_LABEL) { } diff --git a/compiler/core/labelTarget.h b/compiler/core/labelTarget.h index 6c9ee9792b458ad55d9721d3b82c47d7786d2e14..e8fe4c4b7b868774a0f09e441ed07a9969de33a4 100644 --- a/compiler/core/labelTarget.h +++ b/compiler/core/labelTarget.h @@ -41,7 +41,7 @@ public: explicit LabelTarget(PandaGen *pg); explicit LabelTarget(const util::StringView &label) : LabelTarget(nullptr, label) {} explicit LabelTarget(Label *target, const util::StringView &label) - : LabelPair(target, nullptr), breakLabel_(label), continueLabel_(label) + : LabelPair(target, nullptr), break_label_(label), continue_label_(label) { } LabelTarget() : LabelPair(nullptr, nullptr) {}; @@ -52,7 +52,7 @@ public: const util::StringView &BreakLabel() const { - return breakLabel_; + return break_label_; } Label *BreakTarget() const @@ -67,7 +67,7 @@ public: const util::StringView &ContinueLabel() const { - return continueLabel_; + return continue_label_; } Label *ContinueTarget() const @@ -79,8 +79,8 @@ public: static constexpr std::string_view CONTINUE_LABEL = "#c"; private: - util::StringView breakLabel_ {}; - util::StringView continueLabel_ {}; + util::StringView break_label_ {}; + util::StringView continue_label_ {}; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/pandagen.cpp b/compiler/core/pandagen.cpp index d4ff04eef6ad84d07c63c3b264d6773894c70c77..c675521faa477bf8460fc4346b37c37bdf4ac8bd 100644 --- a/compiler/core/pandagen.cpp +++ b/compiler/core/pandagen.cpp @@ -44,7 +44,7 @@ namespace panda::es2panda::compiler { Label *PandaGen::AllocLabel() { - std::string id = std::string {Label::PREFIX} + std::to_string(labelId_++); + std::string id = std::string {Label::PREFIX} + std::to_string(label_id_++); return sa_.AllocLabel(std::move(id)); } @@ -55,22 +55,22 @@ bool PandaGen::IsDebug() const uint32_t PandaGen::ParamCount() const { - if (rootNode_->IsProgram()) { + if (root_node_->IsProgram()) { return 0; } - return rootNode_->AsScriptFunction()->Params().size(); + return root_node_->AsScriptFunction()->Params().size(); } uint32_t PandaGen::FormalParametersCount() const { - if (rootNode_->IsProgram()) { + if (root_node_->IsProgram()) { return 0; } - ASSERT(rootNode_->IsScriptFunction()); + ASSERT(root_node_->IsScriptFunction()); - return rootNode_->AsScriptFunction()->FormalParamsLength(); + return root_node_->AsScriptFunction()->FormalParamsLength(); } uint32_t PandaGen::InternalParamCount() const @@ -81,12 +81,12 @@ uint32_t PandaGen::InternalParamCount() const const util::StringView &PandaGen::InternalName() const { - return topScope_->InternalName(); + return top_scope_->InternalName(); } const util::StringView &PandaGen::FunctionName() const { - return topScope_->Name(); + return top_scope_->Name(); } binder::Binder *PandaGen::Binder() const @@ -96,12 +96,12 @@ binder::Binder *PandaGen::Binder() const void PandaGen::FunctionInit(CatchTable *catchTable) { - if (rootNode_->IsProgram()) { + if (root_node_->IsProgram()) { builder_ = allocator_->New(this, catchTable); return; } - const ir::ScriptFunction *func = rootNode_->AsScriptFunction(); + const ir::ScriptFunction *func = root_node_->AsScriptFunction(); if (func->IsAsync()) { if (func->IsGenerator()) { @@ -123,31 +123,31 @@ void PandaGen::FunctionInit(CatchTable *catchTable) bool PandaGen::FunctionHasFinalizer() const { - if (rootNode_->IsProgram()) { + if (root_node_->IsProgram()) { return false; } - const ir::ScriptFunction *func = rootNode_->AsScriptFunction(); + const ir::ScriptFunction *func = root_node_->AsScriptFunction(); return func->IsAsync() || func->IsGenerator(); } void PandaGen::FunctionEnter() { - builder_->Prepare(rootNode_->AsScriptFunction()); + builder_->Prepare(root_node_->AsScriptFunction()); } void PandaGen::FunctionExit() { - builder_->CleanUp(rootNode_->AsScriptFunction()); + builder_->CleanUp(root_node_->AsScriptFunction()); } void PandaGen::InitializeLexEnv(const ir::AstNode *node, VReg lexEnv) { FrontAllocator fa(this); - if (topScope_->NeedLexEnv()) { - NewLexEnv(node, topScope_->LexicalSlots()); + if (top_scope_->NeedLexEnv()) { + NewLexEnv(node, top_scope_->LexicalSlots()); } else { LdLexEnv(node); } @@ -158,9 +158,9 @@ void PandaGen::InitializeLexEnv(const ir::AstNode *node, VReg lexEnv) void PandaGen::CopyFunctionArguments(const ir::AstNode *node) { FrontAllocator fa(this); - VReg targetReg = totalRegs_; + VReg targetReg = total_regs_; - for (const auto *param : topScope_->ParamScope()->Params()) { + for (const auto *param : top_scope_->ParamScope()->Params()) { if (param->LexicalBound()) { LoadAccumulator(node, targetReg++); StoreLexicalVar(node, 0, param->LexIdx()); @@ -177,7 +177,7 @@ LiteralBuffer *PandaGen::NewLiteralBuffer() int32_t PandaGen::AddLiteralBuffer(LiteralBuffer *buf) { - buffStorage_.push_back(buf); + buff_storage_.push_back(buf); buf->SetIndex(context_->NewLiteralIndex()); return buf->Index(); } @@ -204,10 +204,10 @@ void PandaGen::SetThis(const ir::AstNode *node) void PandaGen::LoadVar(const ir::Identifier *node, const binder::ScopeFindResult &result) { - auto *var = result.variable; + auto *var = result.variable_; if (!var) { - TryLoadGlobalByName(node, result.name); + TryLoadGlobalByName(node, result.name_); return; } @@ -227,10 +227,10 @@ void PandaGen::LoadVar(const ir::Identifier *node, const binder::ScopeFindResult void PandaGen::StoreVar(const ir::AstNode *node, const binder::ScopeFindResult &result, bool isDeclaration) { - binder::Variable *var = result.variable; + binder::Variable *var = result.variable_; if (!var) { - TryStoreGlobalByName(node, result.name); + TryStoreGlobalByName(node, result.name_); return; } @@ -262,7 +262,7 @@ void PandaGen::LoadAccFromArgs(const ir::AstNode *node) } binder::ScopeFindResult res = scope_->Find(binder::Binder::FUNCTION_ARGUMENTS); - ASSERT(res.scope); + ASSERT(res.scope_); GetUnmappedArgs(node); StoreAccToLexEnv(node, res, true); @@ -421,7 +421,7 @@ void PandaGen::StoreGlobalLet(const ir::AstNode *node, const util::StringView &n VReg PandaGen::LexEnv() const { - return envScope_->LexEnv(); + return env_scope_->LexEnv(); } void PandaGen::LoadAccFromLexEnv(const ir::AstNode *node, const binder::ScopeFindResult &result) @@ -523,7 +523,7 @@ void PandaGen::Branch(const ir::AstNode *node, Label *label) bool PandaGen::CheckControlFlowChange() { - const auto *iter = dynamicContext_; + const auto *iter = dynamic_context_; while (iter) { if (iter->HasFinalizer()) { @@ -538,7 +538,7 @@ bool PandaGen::CheckControlFlowChange() Label *PandaGen::ControlFlowChangeBreak(const ir::Identifier *label) { - auto *iter = dynamicContext_; + auto *iter = dynamic_context_; util::StringView labelName = label ? label->Name() : LabelTarget::BREAK_LABEL; Label *breakTarget = nullptr; @@ -564,7 +564,7 @@ Label *PandaGen::ControlFlowChangeBreak(const ir::Identifier *label) Label *PandaGen::ControlFlowChangeContinue(const ir::Identifier *label) { - auto *iter = dynamicContext_; + auto *iter = dynamic_context_; util::StringView labelName = label ? label->Name() : LabelTarget::CONTINUE_LABEL; Label *continueTarget = nullptr; @@ -1428,7 +1428,7 @@ void PandaGen::LdLexEnv(const ir::AstNode *node) uint32_t PandaGen::TryDepth() const { - const auto *iter = dynamicContext_; + const auto *iter = dynamic_context_; uint32_t depth = 0; while (iter) { @@ -1445,13 +1445,13 @@ uint32_t PandaGen::TryDepth() const CatchTable *PandaGen::CreateCatchTable() { auto *catchTable = allocator_->New(this, TryDepth()); - catchList_.push_back(catchTable); + catch_list_.push_back(catchTable); return catchTable; } void PandaGen::SortCatchTables() { - std::sort(catchList_.begin(), catchList_.end(), + std::sort(catch_list_.begin(), catch_list_.end(), [](const CatchTable *a, const CatchTable *b) { return b->Depth() < a->Depth(); }); } diff --git a/compiler/core/pandagen.h b/compiler/core/pandagen.h index ee623bd7fb247d7adb176af4a116a57d9a680fb5..105675e93474a42a3b87dc4bf02571230af67c14 100644 --- a/compiler/core/pandagen.h +++ b/compiler/core/pandagen.h @@ -62,13 +62,13 @@ enum class Constant { class DebugInfo { public: - explicit DebugInfo(ArenaAllocator *allocator) : variableDebugInfo(allocator->Adapter()) {}; + explicit DebugInfo(ArenaAllocator *allocator) : variable_debug_info_(allocator->Adapter()) {}; DEFAULT_COPY_SEMANTIC(DebugInfo); DEFAULT_MOVE_SEMANTIC(DebugInfo); ~DebugInfo() = default; - ArenaVector variableDebugInfo; - const ir::Statement *firstStmt {}; + ArenaVector variable_debug_info_; + const ir::Statement *first_stmt_ {}; }; class PandaGen { @@ -76,14 +76,14 @@ public: explicit PandaGen(ArenaAllocator *allocator, CompilerContext *context, binder::FunctionScope *scope) : allocator_(allocator), context_(context), - debugInfo_(allocator_), - topScope_(scope), - scope_(topScope_), - rootNode_(scope->Node()), + debug_info_(allocator_), + top_scope_(scope), + scope_(top_scope_), + root_node_(scope->Node()), insns_(allocator_->Adapter()), - catchList_(allocator_->Adapter()), + catch_list_(allocator_->Adapter()), strings_(allocator_->Adapter()), - buffStorage_(allocator_->Adapter()), + buff_storage_(allocator_->Adapter()), sa_(this), ra_(this), rra_(this) @@ -105,12 +105,12 @@ public: const ArenaVector &CatchList() const { - return catchList_; + return catch_list_; } binder::FunctionScope *TopScope() const { - return topScope_; + return top_scope_; } binder::Scope *Scope() const @@ -120,7 +120,7 @@ public: const ir::AstNode *RootNode() const { - return rootNode_; + return root_node_; } ArenaList &Insns() @@ -135,27 +135,27 @@ public: VReg AllocReg() { - return usedRegs_++; + return used_regs_++; } VReg NextReg() const { - return usedRegs_; + return used_regs_; } uint32_t TotalRegsNum() const { - return totalRegs_; + return total_regs_; } size_t LabelCount() const { - return labelId_; + return label_id_; } const DebugInfo &Debuginfo() const { - return debugInfo_; + return debug_info_; } FunctionBuilder *FuncBuilder() const @@ -165,12 +165,12 @@ public: EnvScope *GetEnvScope() const { - return envScope_; + return env_scope_; } const ArenaVector &BuffStorage() const { - return buffStorage_; + return buff_storage_; } uint32_t IcSize() const @@ -375,7 +375,7 @@ public: void SetFirstStmt(const ir::Statement *stmt) { - debugInfo_.firstStmt = stmt; + debug_info_.first_stmt_ = stmt; } [[noreturn]] static void Unimplemented() @@ -387,23 +387,23 @@ private: ArenaAllocator *allocator_; CompilerContext *context_; FunctionBuilder *builder_ {nullptr}; - DebugInfo debugInfo_; - binder::FunctionScope *topScope_; + DebugInfo debug_info_; + binder::FunctionScope *top_scope_; binder::Scope *scope_; - const ir::AstNode *rootNode_; + const ir::AstNode *root_node_; ArenaList insns_; - ArenaVector catchList_; + ArenaVector catch_list_; ArenaSet strings_; - ArenaVector buffStorage_; - EnvScope *envScope_ {}; - DynamicContext *dynamicContext_ {}; + ArenaVector buff_storage_; + EnvScope *env_scope_ {}; + DynamicContext *dynamic_context_ {}; InlineCache ic_; SimpleAllocator sa_; RegAllocator ra_; RangeRegAllocator rra_; - uint32_t usedRegs_ {0}; - uint32_t totalRegs_ {0}; + uint32_t used_regs_ {0}; + uint32_t total_regs_ {0}; friend class ScopeContext; friend class RegScope; friend class LocalRegScope; @@ -413,7 +413,7 @@ private: friend class EnvScope; friend class LoopEnvScope; friend class DynamicContext; - size_t labelId_ {0}; + size_t label_id_ {0}; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/regAllocator.cpp b/compiler/core/regAllocator.cpp index 7ed5763f5499b520da2aff1128a28b73cacc06a7..c6b90e157e17110258ecfc66e4cb79a0fc2c38b0 100644 --- a/compiler/core/regAllocator.cpp +++ b/compiler/core/regAllocator.cpp @@ -58,7 +58,7 @@ FrontAllocator::~FrontAllocator() VReg RegAllocatorBase::Spill(IRNode *ins, VReg reg) { VReg spillReg = pg_->AllocReg(); - VReg origin = spillIndex_++; + VReg origin = spill_index_++; Add(ins->Node(), spillReg, origin); Add(ins->Node(), origin, reg); @@ -68,9 +68,9 @@ VReg RegAllocatorBase::Spill(IRNode *ins, VReg reg) void RegAllocatorBase::Restore(IRNode *ins) { - spillIndex_--; - VReg spillReg = spillIndex_; - VReg origin = regEnd_ + spillIndex_; + spill_index_--; + VReg spillReg = spill_index_; + VReg origin = reg_end_ + spill_index_; Add(ins->Node(), origin, spillReg); } @@ -79,7 +79,7 @@ void RegAllocatorBase::Restore(IRNode *ins) void RegAllocator::Run(IRNode *ins) { - ASSERT(spillIndex_ == 0); + ASSERT(spill_index_ == 0); std::array regs {}; auto regCnt = ins->Registers(®s); auto registers = Span(regs.data(), regs.data() + regCnt); @@ -91,7 +91,7 @@ void RegAllocator::Run(IRNode *ins) RegScope regScope(pg_); - regEnd_ = pg_->NextReg(); + reg_end_ = pg_->NextReg(); for (auto *reg : registers) { if (IsRegisterCorrect(reg)) { @@ -104,7 +104,7 @@ void RegAllocator::Run(IRNode *ins) PushBack(ins); - while (spillIndex_ != 0) { + while (spill_index_ != 0) { Restore(ins); } } @@ -113,7 +113,7 @@ void RegAllocator::Run(IRNode *ins) void RangeRegAllocator::Run(IRNode *ins, VReg rangeStart, size_t argCount) { - ASSERT(spillIndex_ == 0); + ASSERT(spill_index_ == 0); const auto rangeEnd = rangeStart + argCount; std::array regs {}; @@ -127,7 +127,7 @@ void RangeRegAllocator::Run(IRNode *ins, VReg rangeStart, size_t argCount) RegScope regScope(pg_); - regEnd_ = pg_->NextReg(); + reg_end_ = pg_->NextReg(); auto *iter = registers.begin(); auto *iterEnd = iter + registers.size() - 1; @@ -151,7 +151,7 @@ void RangeRegAllocator::Run(IRNode *ins, VReg rangeStart, size_t argCount) PushBack(ins); - while (spillIndex_ != 0) { + while (spill_index_ != 0) { Restore(ins); } } diff --git a/compiler/core/regAllocator.h b/compiler/core/regAllocator.h index da5eeffecfb7646ce4fdbc314bf26d6dddc792a6..e187ab255c690f56fdc01757eaed9a54378ff6f6 100644 --- a/compiler/core/regAllocator.h +++ b/compiler/core/regAllocator.h @@ -121,8 +121,8 @@ protected: VReg Spill(IRNode *ins, VReg reg); void Restore(IRNode *ins); - VReg spillIndex_ {0}; - VReg regEnd_ {0}; + VReg spill_index_ {0}; + VReg reg_end_ {0}; size_t limit_ {0}; }; diff --git a/compiler/core/regScope.cpp b/compiler/core/regScope.cpp index 588340ed6b4b47818e86663c4e2567f64498c294..44f006c384fa5ef25bb4c2cf9d59584838f10b76 100644 --- a/compiler/core/regScope.cpp +++ b/compiler/core/regScope.cpp @@ -27,12 +27,12 @@ namespace panda::es2panda::compiler { // RegScope -RegScope::RegScope(PandaGen *pg) : pg_(pg), regBase_(pg_->usedRegs_) {} +RegScope::RegScope(PandaGen *pg) : pg_(pg), reg_base_(pg_->used_regs_) {} RegScope::~RegScope() { - pg_->totalRegs_ = std::max(pg_->totalRegs_, pg_->usedRegs_); - pg_->usedRegs_ = regBase_; + pg_->total_regs_ = std::max(pg_->total_regs_, pg_->used_regs_); + pg_->used_regs_ = reg_base_; } void RegScope::DebuggerCloseScope() @@ -50,7 +50,7 @@ LocalRegScope::LocalRegScope(PandaGen *pg) : RegScope(pg) {} LocalRegScope::LocalRegScope(PandaGen *pg, binder::Scope *scope) : RegScope(pg) { - prevScope_ = pg_->scope_; + prev_scope_ = pg_->scope_; pg_->scope_ = scope; for (const auto &[_, var] : scope->Bindings()) { @@ -62,7 +62,7 @@ LocalRegScope::LocalRegScope(PandaGen *pg, binder::Scope *scope) : RegScope(pg) if (pg_->IsDebug()) { pg_->scope_->SetScopeStart(pg_->insns_.back()); - pg_->debugInfo_.variableDebugInfo.push_back(pg_->scope_); + pg_->debug_info_.variable_debug_info_.push_back(pg_->scope_); } Hoisting::Hoist(pg_); @@ -70,18 +70,18 @@ LocalRegScope::LocalRegScope(PandaGen *pg, binder::Scope *scope) : RegScope(pg) LocalRegScope::~LocalRegScope() { - if (!prevScope_) { + if (!prev_scope_) { return; } DebuggerCloseScope(); - pg_->scope_ = prevScope_; + pg_->scope_ = prev_scope_; } // FunctionRegScope -FunctionRegScope::FunctionRegScope(PandaGen *pg) : RegScope(pg), envScope_(pg->Allocator()->New()) +FunctionRegScope::FunctionRegScope(PandaGen *pg) : RegScope(pg), env_scope_(pg->Allocator()->New()) { ASSERT(pg_->Scope()->IsFunctionVariableScope()); ASSERT(pg_->NextReg() == binder::Binder::MANDATORY_PARAM_FUNC_REG); @@ -95,7 +95,7 @@ FunctionRegScope::FunctionRegScope(PandaGen *pg) : RegScope(pg), envScope_(pg->A } } - envScope_->Initialize(pg_, pg->AllocReg()); + env_scope_->Initialize(pg_, pg->AllocReg()); for (const auto &[_, var] : funcScope->Bindings()) { (void)_; @@ -109,10 +109,10 @@ FunctionRegScope::FunctionRegScope(PandaGen *pg) : RegScope(pg), envScope_(pg->A } if (pg_->IsDebug()) { - pg_->debugInfo_.variableDebugInfo.push_back(funcScope); + pg_->debug_info_.variable_debug_info_.push_back(funcScope); } - pg_->LoadAccFromArgs(pg_->rootNode_); + pg_->LoadAccFromArgs(pg_->root_node_); if (funcScope->IsModuleScope()) { ModuleContext::Compile(pg_, pg_->scope_->AsModuleScope()); @@ -124,12 +124,12 @@ FunctionRegScope::FunctionRegScope(PandaGen *pg) : RegScope(pg), envScope_(pg->A FunctionRegScope::~FunctionRegScope() { if (pg_->IsDebug()) { - pg_->topScope_->SetScopeStart(pg_->insns_.front()); + pg_->top_scope_->SetScopeStart(pg_->insns_.front()); } DebuggerCloseScope(); - envScope_->~EnvScope(); + env_scope_->~EnvScope(); } } // namespace panda::es2panda::compiler diff --git a/compiler/core/regScope.h b/compiler/core/regScope.h index a34029c4f04ae87af4ab2267e52e3a5109a5196f..b0b71a6eeab39f25c92920946ba16f8ed9af87c0 100644 --- a/compiler/core/regScope.h +++ b/compiler/core/regScope.h @@ -42,7 +42,7 @@ protected: void DebuggerCloseScope(); PandaGen *pg_; - uint32_t regBase_; + uint32_t reg_base_; }; class LocalRegScope : public RegScope { @@ -57,7 +57,7 @@ public: void *operator new[](size_t) = delete; private: - binder::Scope *prevScope_ {}; + binder::Scope *prev_scope_ {}; }; class LoopRegScope : public RegScope { @@ -71,7 +71,7 @@ public: void *operator new[](size_t) = delete; private: - binder::Scope *prevScope_ {}; + binder::Scope *prev_scope_ {}; }; class FunctionRegScope : public RegScope { @@ -85,7 +85,7 @@ public: void *operator new[](size_t) = delete; private: - EnvScope *envScope_; + EnvScope *env_scope_; }; } // namespace panda::es2panda::compiler diff --git a/compiler/core/switchBuilder.cpp b/compiler/core/switchBuilder.cpp index 6dfa51d8fbc4d16f4ca50fca8765fa69f6d97a32..d17bfb783437285442ab1b6f071d5ff40697e41d 100644 --- a/compiler/core/switchBuilder.cpp +++ b/compiler/core/switchBuilder.cpp @@ -26,10 +26,10 @@ namespace panda::es2panda::compiler { // SwitchBuilder SwitchBuilder::SwitchBuilder(PandaGen *pg, const ir::SwitchStatement *stmt) - : pg_(pg), end_(pg->AllocLabel()), labelCtx_(pg, LabelTarget(end_, LabelTarget::BREAK_LABEL)), stmt_(stmt) + : pg_(pg), end_(pg->AllocLabel()), label_ctx_(pg, LabelTarget(end_, LabelTarget::BREAK_LABEL)), stmt_(stmt) { for (size_t i = 0; i < stmt_->Cases().size(); i++) { - caseLabels_.push_back(pg_->AllocLabel()); + case_labels_.push_back(pg_->AllocLabel()); } } @@ -40,7 +40,7 @@ SwitchBuilder::~SwitchBuilder() void SwitchBuilder::SetCaseTarget(uint32_t index) { - pg_->SetLabel(stmt_->Cases()[index], caseLabels_[index]); + pg_->SetLabel(stmt_->Cases()[index], case_labels_[index]); } void SwitchBuilder::CompileTagOfSwitch(VReg tag) @@ -60,13 +60,13 @@ void SwitchBuilder::JumpIfCase(VReg tag, uint32_t index) { const ir::SwitchCaseStatement *caseTarget = stmt_->Cases()[index]; caseTarget->Test()->Compile(pg_); - pg_->Condition(caseTarget, lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL, tag, caseLabels_[index]); + pg_->Condition(caseTarget, lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL, tag, case_labels_[index]); } void SwitchBuilder::JumpToDefault(uint32_t defaultIndex) { const ir::SwitchCaseStatement *defaultTarget = stmt_->Cases()[defaultIndex]; - pg_->Branch(defaultTarget, caseLabels_[defaultIndex]); + pg_->Branch(defaultTarget, case_labels_[defaultIndex]); } void SwitchBuilder::Break() diff --git a/compiler/core/switchBuilder.h b/compiler/core/switchBuilder.h index cea6db1b5dcb6be513c89fcb5f980ef38fff8a89..ad7f6bce28cc7287ec9acee91503528877fcd5a6 100644 --- a/compiler/core/switchBuilder.h +++ b/compiler/core/switchBuilder.h @@ -44,9 +44,9 @@ public: private: PandaGen *pg_; Label *end_; - LabelContext labelCtx_; + LabelContext label_ctx_; const ir::SwitchStatement *stmt_; - std::vector