From 67486dfd1ecbf2cb74beac553a9e82ae7d321f66 Mon Sep 17 00:00:00 2001 From: "@evian_hill" Date: Sat, 27 Mar 2021 21:28:16 +0800 Subject: [PATCH] create MIRStructType/ClassType/InterfaceType with strIdx in parser --- src/mapleall/maple_ir/include/mir_parser.h | 9 ++++---- src/mapleall/maple_ir/src/parser.cpp | 27 +++++++++------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/mapleall/maple_ir/include/mir_parser.h b/src/mapleall/maple_ir/include/mir_parser.h index e349f1745c..752fb99e15 100644 --- a/src/mapleall/maple_ir/include/mir_parser.h +++ b/src/mapleall/maple_ir/include/mir_parser.h @@ -75,15 +75,16 @@ class MIRParser { bool ParsePragmaElementForAnnotation(MIRPragmaElement &elem); bool ParsePragma(MIRStructType &type); bool ParseFields(MIRStructType &type); - bool ParseStructType(TyIdx &styIdx); - bool ParseClassType(TyIdx &tyIdx); - bool ParseInterfaceType(TyIdx &sTyIdx); + bool ParseStructType(TyIdx &styIdx, const GStrIdx &strIdx = GStrIdx(0)); + bool ParseClassType(TyIdx &tyIdx, const GStrIdx &strIdx = GStrIdx(0)); + bool ParseInterfaceType(TyIdx &sTyIdx, const GStrIdx &strIdx = GStrIdx(0)); bool ParseDefinedTypename(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown); bool ParseTypeParam(TyIdx &tyIdx); bool ParsePointType(TyIdx &tyIdx); bool ParseFuncType(TyIdx &tyIdx); bool ParseGenericInstantVector(MIRInstantVectorType &insVecType); - bool ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown); + bool ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind = kTypeUnknown, + const GStrIdx &strIdx = GStrIdx(0)); bool ParseType(TyIdx &tyIdx); bool ParseStatement(StmtNodePtr &stmt); bool ParseSpecialReg(PregIdx &pregIdx); diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index 31d369c532..f41bd1b316 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -787,7 +787,7 @@ bool MIRParser::ParseFields(MIRStructType &type) { return false; } -bool MIRParser::ParseStructType(TyIdx &styIdx) { +bool MIRParser::ParseStructType(TyIdx &styIdx, const GStrIdx &strIdx) { MIRTypeKind tkind = kTypeInvalid; switch (lexer.GetTokenKind()) { case TK_struct: @@ -806,7 +806,7 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { Error("expect { parsing struct body"); return false; } - MIRStructType structType(tkind); + MIRStructType structType(tkind, strIdx); if (mod.GetSrcLang() == kSrcLangCPlusPlus) { structType.SetIsCPlusPlus(true); } @@ -830,7 +830,7 @@ bool MIRParser::ParseStructType(TyIdx &styIdx) { return true; } -bool MIRParser::ParseClassType(TyIdx &styidx) { +bool MIRParser::ParseClassType(TyIdx &styidx, const GStrIdx &strIdx) { MIRTypeKind tkind = (lexer.GetTokenKind() == TK_class) ? kTypeClass : kTypeClassIncomplete; TyIdx parentTypeIdx(0); if (lexer.NextToken() == TK_langle) { @@ -840,7 +840,7 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { return false; } } - MIRClassType classType(tkind); + MIRClassType classType(tkind, strIdx); classType.SetParentTyIdx(parentTypeIdx); if (!ParseFields(classType)) { return false; @@ -873,7 +873,7 @@ bool MIRParser::ParseClassType(TyIdx &styidx) { return true; } -bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx) { +bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx, const GStrIdx &strIdx) { MIRTypeKind tkind = (lexer.GetTokenKind() == TK_interface) ? kTypeInterface : kTypeInterfaceIncomplete; std::vector parents; TokenKind tk = lexer.NextToken(); @@ -887,7 +887,7 @@ bool MIRParser::ParseInterfaceType(TyIdx &sTyIdx) { parents.push_back(parentTypeIdx); tk = lexer.GetTokenKind(); } - MIRInterfaceType interfaceType(tkind); + MIRInterfaceType interfaceType(tkind, strIdx); interfaceType.SetParentsTyIdx(parents); if (!ParseFields(interfaceType)) { return false; @@ -1290,7 +1290,7 @@ bool MIRParser::ParseGenericInstantVector(MIRInstantVectorType &insVecType) { return false; } -bool MIRParser::ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind) { +bool MIRParser::ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind, const GStrIdx &strIdx) { if (lexer.GetTokenKind() != TK_langle) { Error("expect langle but get "); return false; @@ -1319,21 +1319,21 @@ bool MIRParser::ParseDerivedType(TyIdx &tyIdx, MIRTypeKind kind) { case TK_struct: // struct type case TK_structincomplete: // structincomplete type case TK_union: // union type - if (!ParseStructType(tyIdx)) { + if (!ParseStructType(tyIdx, strIdx)) { Error("struct/union type wrong when parsing derived type at "); return false; } break; case TK_class: // class type case TK_classincomplete: - if (!ParseClassType(tyIdx)) { + if (!ParseClassType(tyIdx, strIdx)) { Error("class type wrong when parsing derived type at "); return false; } break; case TK_interface: // interface type case TK_interfaceincomplete: - if (!ParseInterfaceType(tyIdx)) { + if (!ParseInterfaceType(tyIdx, strIdx)) { Error("interface type wrong when parsing derived type at "); return false; } @@ -1518,7 +1518,7 @@ bool MIRParser::ParseTypedef() { Error("expect primitive type after typedef but get "); return false; } - } else if (!ParseDerivedType(tyIdx, kTypeUnknown)) { + } else if (!ParseDerivedType(tyIdx, kTypeUnknown, strIdx)) { Error("error passing derived type at "); return false; } @@ -1529,17 +1529,12 @@ bool MIRParser::ParseTypedef() { mod.CurFunction()->SetGStrIdxToTyIdx(strIdx, tyIdx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0u) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameStrIdx(strIdx); GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameIsLocal(true); } } else { prevTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); mod.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); mod.PushbackTypeDefOrder(strIdx); - ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); - if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0u) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameStrIdx(strIdx); - } } if (prevTyIdx != TyIdx(0) && prevTyIdx != tyIdx) { -- Gitee