diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -140,9 +140,7 @@ unsigned FieldAlignmentSize); StructInfo() = default; - - StructInfo(StringRef StructName, bool Union, unsigned AlignmentValue) - : Name(StructName), IsUnion(Union), Alignment(AlignmentValue) {} + StructInfo(StringRef StructName, bool Union, unsigned AlignmentValue); }; // FIXME: This should probably use a class hierarchy, raw pointers between the @@ -170,14 +168,8 @@ StructInfo Structure; StructFieldInfo() = default; - StructFieldInfo(const std::vector &V, StructInfo S) { - Initializers = V; - Structure = S; - } - StructFieldInfo(std::vector &&V, StructInfo S) { - Initializers = V; - Structure = S; - } + StructFieldInfo(const std::vector &V, StructInfo S); + StructFieldInfo(std::vector &&V, StructInfo S); }; class FieldInitializer { @@ -189,133 +181,19 @@ StructFieldInfo StructInfo; }; - ~FieldInitializer() { - switch (FT) { - case FT_INTEGRAL: - IntInfo.~IntFieldInfo(); - break; - case FT_REAL: - RealInfo.~RealFieldInfo(); - break; - case FT_STRUCT: - StructInfo.~StructFieldInfo(); - break; - } - } - - FieldInitializer(FieldType FT) : FT(FT) { - switch (FT) { - case FT_INTEGRAL: - new (&IntInfo) IntFieldInfo(); - break; - case FT_REAL: - new (&RealInfo) RealFieldInfo(); - break; - case FT_STRUCT: - new (&StructInfo) StructFieldInfo(); - break; - } - } - - FieldInitializer(SmallVector &&Values) : FT(FT_INTEGRAL) { - new (&IntInfo) IntFieldInfo(Values); - } - - FieldInitializer(SmallVector &&AsIntValues) : FT(FT_REAL) { - new (&RealInfo) RealFieldInfo(AsIntValues); - } + ~FieldInitializer(); + FieldInitializer(FieldType FT); + FieldInitializer(SmallVector &&Values); + FieldInitializer(SmallVector &&AsIntValues); FieldInitializer(std::vector &&Initializers, - struct StructInfo Structure) - : FT(FT_STRUCT) { - new (&StructInfo) StructFieldInfo(Initializers, Structure); - } - - FieldInitializer(const FieldInitializer &Initializer) : FT(Initializer.FT) { - switch (FT) { - case FT_INTEGRAL: - new (&IntInfo) IntFieldInfo(Initializer.IntInfo); - break; - case FT_REAL: - new (&RealInfo) RealFieldInfo(Initializer.RealInfo); - break; - case FT_STRUCT: - new (&StructInfo) StructFieldInfo(Initializer.StructInfo); - break; - } - } - - FieldInitializer(FieldInitializer &&Initializer) : FT(Initializer.FT) { - switch (FT) { - case FT_INTEGRAL: - new (&IntInfo) IntFieldInfo(Initializer.IntInfo); - break; - case FT_REAL: - new (&RealInfo) RealFieldInfo(Initializer.RealInfo); - break; - case FT_STRUCT: - new (&StructInfo) StructFieldInfo(Initializer.StructInfo); - break; - } - } + struct StructInfo Structure); - FieldInitializer &operator=(const FieldInitializer &Initializer) { - if (FT != Initializer.FT) { - switch (FT) { - case FT_INTEGRAL: - IntInfo.~IntFieldInfo(); - break; - case FT_REAL: - RealInfo.~RealFieldInfo(); - break; - case FT_STRUCT: - StructInfo.~StructFieldInfo(); - break; - } - } - FT = Initializer.FT; - switch (FT) { - case FT_INTEGRAL: - IntInfo = Initializer.IntInfo; - break; - case FT_REAL: - RealInfo = Initializer.RealInfo; - break; - case FT_STRUCT: - StructInfo = Initializer.StructInfo; - break; - } - return *this; - } + FieldInitializer(const FieldInitializer &Initializer); + FieldInitializer(FieldInitializer &&Initializer); - FieldInitializer &operator=(FieldInitializer &&Initializer) { - if (FT != Initializer.FT) { - switch (FT) { - case FT_INTEGRAL: - IntInfo.~IntFieldInfo(); - break; - case FT_REAL: - RealInfo.~RealFieldInfo(); - break; - case FT_STRUCT: - StructInfo.~StructFieldInfo(); - break; - } - } - FT = Initializer.FT; - switch (FT) { - case FT_INTEGRAL: - IntInfo = Initializer.IntInfo; - break; - case FT_REAL: - RealInfo = Initializer.RealInfo; - break; - case FT_STRUCT: - StructInfo = Initializer.StructInfo; - break; - } - return *this; - } + FieldInitializer &operator=(const FieldInitializer &Initializer); + FieldInitializer &operator=(FieldInitializer &&Initializer); }; struct StructInitializer { @@ -340,6 +218,22 @@ FieldInfo(FieldType FT) : Contents(FT) {} }; +StructFieldInfo::StructFieldInfo(const std::vector &V, + StructInfo S) { + Initializers = V; + Structure = S; +} + +StructFieldInfo::StructFieldInfo(std::vector &&V, + StructInfo S) { + Initializers = V; + Structure = S; +} + +StructInfo::StructInfo(StringRef StructName, bool Union, + unsigned AlignmentValue) + : Name(StructName), IsUnion(Union), Alignment(AlignmentValue) {} + FieldInfo &StructInfo::addField(StringRef FieldName, FieldType FT, unsigned FieldAlignmentSize) { if (!FieldName.empty()) @@ -355,6 +249,139 @@ return Field; } +FieldInitializer::~FieldInitializer() { + switch (FT) { + case FT_INTEGRAL: + IntInfo.~IntFieldInfo(); + break; + case FT_REAL: + RealInfo.~RealFieldInfo(); + break; + case FT_STRUCT: + StructInfo.~StructFieldInfo(); + break; + } +} + +FieldInitializer::FieldInitializer(FieldType FT) : FT(FT) { + switch (FT) { + case FT_INTEGRAL: + new (&IntInfo) IntFieldInfo(); + break; + case FT_REAL: + new (&RealInfo) RealFieldInfo(); + break; + case FT_STRUCT: + new (&StructInfo) StructFieldInfo(); + break; + } +} + +FieldInitializer::FieldInitializer(SmallVector &&Values) + : FT(FT_INTEGRAL) { + new (&IntInfo) IntFieldInfo(Values); +} + +FieldInitializer::FieldInitializer(SmallVector &&AsIntValues) + : FT(FT_REAL) { + new (&RealInfo) RealFieldInfo(AsIntValues); +} + +FieldInitializer::FieldInitializer( + std::vector &&Initializers, struct StructInfo Structure) + : FT(FT_STRUCT) { + new (&StructInfo) StructFieldInfo(Initializers, Structure); +} + +FieldInitializer::FieldInitializer(const FieldInitializer &Initializer) + : FT(Initializer.FT) { + switch (FT) { + case FT_INTEGRAL: + new (&IntInfo) IntFieldInfo(Initializer.IntInfo); + break; + case FT_REAL: + new (&RealInfo) RealFieldInfo(Initializer.RealInfo); + break; + case FT_STRUCT: + new (&StructInfo) StructFieldInfo(Initializer.StructInfo); + break; + } +} + +FieldInitializer::FieldInitializer(FieldInitializer &&Initializer) + : FT(Initializer.FT) { + switch (FT) { + case FT_INTEGRAL: + new (&IntInfo) IntFieldInfo(Initializer.IntInfo); + break; + case FT_REAL: + new (&RealInfo) RealFieldInfo(Initializer.RealInfo); + break; + case FT_STRUCT: + new (&StructInfo) StructFieldInfo(Initializer.StructInfo); + break; + } +} + +FieldInitializer & +FieldInitializer::operator=(const FieldInitializer &Initializer) { + if (FT != Initializer.FT) { + switch (FT) { + case FT_INTEGRAL: + IntInfo.~IntFieldInfo(); + break; + case FT_REAL: + RealInfo.~RealFieldInfo(); + break; + case FT_STRUCT: + StructInfo.~StructFieldInfo(); + break; + } + } + FT = Initializer.FT; + switch (FT) { + case FT_INTEGRAL: + IntInfo = Initializer.IntInfo; + break; + case FT_REAL: + RealInfo = Initializer.RealInfo; + break; + case FT_STRUCT: + StructInfo = Initializer.StructInfo; + break; + } + return *this; +} + +FieldInitializer &FieldInitializer::operator=(FieldInitializer &&Initializer) { + if (FT != Initializer.FT) { + switch (FT) { + case FT_INTEGRAL: + IntInfo.~IntFieldInfo(); + break; + case FT_REAL: + RealInfo.~RealFieldInfo(); + break; + case FT_STRUCT: + StructInfo.~StructFieldInfo(); + break; + } + } + FT = Initializer.FT; + switch (FT) { + case FT_INTEGRAL: + IntInfo = Initializer.IntInfo; + break; + case FT_REAL: + RealInfo = Initializer.RealInfo; + break; + case FT_STRUCT: + StructInfo = Initializer.StructInfo; + break; + } + return *this; +} + /// The concrete assembly parser instance. // Note that this is a full MCAsmParser, not an MCAsmParserExtension! // It's a peer of AsmParser, not of COFFAsmParser, WasmAsmParser, etc.