diff --git a/src/mapleall/maple_ir/include/mir_type.h b/src/mapleall/maple_ir/include/mir_type.h index 8c9cf8d79f8e782db59d30aa749577cd6ae4d37a..1856f5443b6ef354001885c39c560a2d8d2146ae 100755 --- a/src/mapleall/maple_ir/include/mir_type.h +++ b/src/mapleall/maple_ir/include/mir_type.h @@ -628,6 +628,18 @@ class MIRArrayType : public MIRType { this->dim = dim; } + TypeAttrs GetTypeAttrs() const { + return typeAttrs; + } + + TypeAttrs& GetTypeAttrs() { + return typeAttrs; + } + + void SetTypeAttrs(TypeAttrs attrs) { + typeAttrs = attrs; + } + MIRType *GetElemType() const; MIRType *CopyMIRTypeNode() const override { @@ -660,8 +672,7 @@ class MIRArrayType : public MIRType { CHECK_FATAL(i < kMaxArrayDim, "array index out of range"); hIdx += (sizeArray[i] << i); } - constexpr uint8 attrShift = 3; - hIdx += (typeAttrs.GetAttrFlag() << attrShift) + typeAttrs.GetAlignValue(); + hIdx += (typeAttrs.GetAttrFlag() << 3) + typeAttrs.GetAlignValue(); return hIdx % kTypeHashLength; } @@ -843,6 +854,14 @@ class MIRStructType : public MIRType { isUsed = flag; } + bool IsCPlusPlus() const { + return isCPlusPlus; + } + + void SetIsCPlusPlus(bool flag) { + isCPlusPlus = flag; + } + GStrIdx GetFieldGStrIdx(FieldID id) const { const FieldPair &fieldPair = TraverseToField(id); return fieldPair.first; @@ -1631,6 +1650,10 @@ class MIRInstantVectorType : public MIRType { return instantVec; } + GenericInstantVector &GetInstantVec() { + return instantVec; + } + void AddInstant(TypePair typePair) { instantVec.push_back(typePair); } diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index c20d81491ee3a43c42d89e73c008f928f8f2901e..f616d604814d272907e9598bead6490ee26edb34 100755 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -313,6 +313,10 @@ bool MIRParser::ParseArrayType(TyIdx &arrayTyIdx) { } ASSERT(tyIdx != 0u, "something wrong with parsing element type "); MIRArrayType arrayType(tyIdx, vec); + if (!ParseTypeAttrs(arrayType.GetTypeAttrs())) { + Error("bad type attribute in pointer type specification"); + return false; + } arrayTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&arrayType); return true; } @@ -1192,7 +1196,21 @@ bool MIRParser::ParseFuncType(TyIdx &tyIdx) { std::vector vecTyIdx; std::vector vecAttrs; TokenKind tokenKind = lexer.NextToken(); + bool varargs = false; while (tokenKind != TK_rparen) { + if (tokenKind == TK_dotdotdot) { + if (vecTyIdx.size() == 0) { + Error("variable arguments can only appear after fixed parameters "); + return false; + } + varargs = true; + tokenKind = lexer.NextToken(); + if (tokenKind != TK_rparen) { + Error("expect ) after ... but get"); + return false; + } + break; + } TyIdx tyIdxTmp(0); if (!ParseType(tyIdxTmp)) { Error("expect type parsing function parameters "); @@ -1224,9 +1242,9 @@ bool MIRParser::ParseFuncType(TyIdx &tyIdx) { Error("expect return type for function type but get "); return false; } - MIRType *funcType = - GlobalTables::GetTypeTable().GetOrCreateFunctionType(mod, retTyIdx, vecTyIdx, vecAttrs, false, true); - tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(funcType); + MIRFuncType functype(retTyIdx, vecTyIdx, vecAttrs, mod.GetMPAllocator()); + functype.SetVarArgs(varargs); + tyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&functype); return true; }