Skip to content

Commit feb8284

Browse files
committed
Function parameters use Param
1 parent 87e4339 commit feb8284

File tree

14 files changed

+177
-44
lines changed

14 files changed

+177
-44
lines changed

include/mrdox/Metadata/FieldType.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ union FieldFlags
3131
};
3232

3333
// Info for field types.
34-
struct FieldTypeInfo
34+
struct FieldInfo
3535
: public TypeInfo
3636
{
3737
llvm::SmallString<16> Name; // Name associated with this info.
@@ -45,9 +45,9 @@ struct FieldTypeInfo
4545
FieldFlags Flags;
4646
//--------------------------------------------
4747

48-
FieldTypeInfo() = default;
48+
FieldInfo() = default;
4949

50-
FieldTypeInfo(
50+
FieldInfo(
5151
TypeInfo const& TI,
5252
llvm::StringRef Name = llvm::StringRef(),
5353
llvm::StringRef DefaultValue = llvm::StringRef(),

include/mrdox/Metadata/Function.hpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,39 @@ union FnFlags1
7171
BitField<6, 7, FunctionKind> functionKind;
7272
};
7373

74+
// KRYSTIAN TODO: attributes (nodiscard, deprecated, and carries_dependency)
75+
// KRYSTIAN TODO: flag to indicate whether this is a function parameter pack
76+
/** Represents a single function parameter */
77+
struct Param
78+
{
79+
/** The type of this parameter */
80+
TypeInfo Type;
81+
82+
/** The name of this parameter, if any */
83+
std::string Name;
84+
85+
/** The default argument for this parameter, if any */
86+
std::string Default;
87+
88+
Param() = default;
89+
90+
Param(
91+
TypeInfo&& type,
92+
std::string&& name,
93+
std::string&& def_arg)
94+
: Type(std::move(type))
95+
, Name(std::move(name))
96+
, Default(std::move(def_arg))
97+
{
98+
}
99+
};
100+
74101
// TODO: Expand to allow for documenting templating and default args.
75102
// Info for functions.
76103
struct FunctionInfo : SymbolInfo
77104
{
78105
TypeInfo ReturnType; // Info about the return type of this function.
79-
llvm::SmallVector<FieldTypeInfo, 4> Params; // List of parameters.
106+
std::vector<Param> Params; // List of parameters.
80107

81108
// When present, this function is a template or specialization.
82109
llvm::Optional<TemplateInfo> Template;

include/mrdox/Metadata/MemberType.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace mrdox {
2525
/** A data member for a class.
2626
*/
2727
struct MemberTypeInfo
28-
: FieldTypeInfo
28+
: FieldInfo
2929
//, SymbolInfo
3030
{
3131
Access access = Access::Public;
@@ -40,7 +40,7 @@ struct MemberTypeInfo
4040
TypeInfo const& TI,
4141
llvm::StringRef Name,
4242
Access access_)
43-
: FieldTypeInfo(TI, Name)
43+
: FieldInfo(TI, Name)
4444
, access(access_)
4545
{
4646
}

include/mrdox/Metadata/Members.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace mrdox {
2626

2727
struct DataMember
2828
{
29+
// FieldInfo const* I;
2930
MemberTypeInfo const* I;
3031
RecordInfo const* From;
3132
};

include/mrdox/MetadataFwd.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ enum class Access;
3030
struct BaseInfo;
3131
struct EnumValueInfo;
3232
struct EnumInfo;
33-
struct FieldTypeInfo;
33+
struct FieldInfo;
34+
struct Param;
3435
struct FunctionInfo;
3536
struct Info;
3637
struct Javadoc;

source/-XML/CXXTags.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ inline void writeReturnType(TypeInfo const& I, XMLTags& tags)
243243
});
244244
}
245245

246-
inline void writeParam(FieldTypeInfo const& I, XMLTags& tags)
246+
inline void writeParam(Param const& P, XMLTags& tags)
247247
{
248248
tags.write(paramTagName, {}, {
249-
{ "name", I.Name, ! I.Name.empty() },
250-
{ "type", I.Type.Name },
251-
{ "default", I.DefaultValue, ! I.DefaultValue.empty() },
252-
{ I.Type.id } });
249+
{ "name", P.Name, ! P.Name.empty() },
250+
{ "type", P.Type.Type.Name },
251+
{ "default", P.Default, ! P.Default.empty() },
252+
{ P.Type.Type.id } });
253253
}
254254

255255
inline void writeTemplateParam(const TParam& I, XMLTags& tags)

source/-adoc/AdocWriter.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ namespace adoc {
106106

107107
struct AdocWriter::FormalParam
108108
{
109-
FieldTypeInfo const& I;
109+
Param const& I;
110110
AdocWriter& w;
111111

112112
friend
@@ -115,9 +115,11 @@ struct AdocWriter::FormalParam
115115
llvm::raw_ostream& os,
116116
FormalParam const& t)
117117
{
118-
os << t.I.Type.Name;
118+
// KRYSTIAN FIXME: use AdocWriter::typeName
119+
os << t.I.Type.Type.Name;
119120
if(! t.I.Name.empty())
120121
os << ' ' << t.I.Name;
122+
// KRYSTIAN TODO: emit default argument
121123
return os;
122124
}
123125
};
@@ -218,7 +220,7 @@ write(
218220
auto
219221
AdocWriter::
220222
formalParam(
221-
FieldTypeInfo const& t) ->
223+
Param const& t) ->
222224
FormalParam
223225
{
224226
return FormalParam{ t, *this };
@@ -322,7 +324,7 @@ writeTrancheList(
322324
"|";
323325
writeBrief(V.I->javadoc, false);
324326
os_ << '\n';
325-
}
327+
}
326328
os_ <<
327329
"|===\n" <<
328330
"\n";
@@ -461,7 +463,7 @@ AdocWriter::
461463
writeLinkFor(OverloadInfo const& I)
462464
{
463465
std::string s = names_.get(I.Parent->id).str();
464-
466+
465467
os_ << "xref:#" <<
466468
names_.get(I.Parent->id) <<
467469
'-' << I.Name << "[" <<
@@ -516,7 +518,7 @@ writeNestedTypes(
516518
"|";
517519
writeBrief(I.javadoc, false);
518520
os_ << '\n';
519-
}
521+
}
520522
os_ <<
521523
"|===\n" <<
522524
"\n";

source/-adoc/AdocWriter.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class AdocWriter
6565
Section sect_;
6666
std::string temp_;
6767

68-
friend class TypeName;
69-
68+
friend struct TypeName;
7069
public:
7170
virtual ~AdocWriter() = default;
7271

@@ -136,7 +135,7 @@ class AdocWriter
136135
void writeNode(Javadoc::TParam const& node);
137136
void writeNode(Javadoc::Returns const& node);
138137

139-
FormalParam formalParam(FieldTypeInfo const& ft);
138+
FormalParam formalParam(Param const& ft);
140139
TypeName typeName(TypeInfo const& ti);
141140

142141
void beginSection(Info const& I);

source/AST/ASTVisitor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,10 @@ parseParameters(
337337
// KRYSTIAN NOTE: call getOriginalType instead
338338
// of getType if we want to preserve top-level
339339
// cv-qualfiers/array types/function types
340-
FieldTypeInfo& FieldInfo = I.Params.emplace_back(
340+
I.Params.emplace_back(
341341
getTypeInfoForType(P->getType()),
342-
P->getNameAsString());
343-
FieldInfo.DefaultValue = getSourceCode(
344-
D, P->getDefaultArgRange());
342+
P->getNameAsString(),
343+
getSourceCode(D, P->getDefaultArgRange()));
345344
}
346345
}
347346

source/AST/AnyBlock.hpp

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,13 @@ class FieldTypeBlock
438438
{
439439
protected:
440440
BitcodeReader& br_;
441-
FieldTypeInfo& I_;
441+
FieldInfo& I_;
442442

443443
public:
444444
FieldId F;
445445

446446
FieldTypeBlock(
447-
FieldTypeInfo& I,
447+
FieldInfo& I,
448448
BitcodeReader& br) noexcept
449449
: br_(br)
450450
, I_(I)
@@ -807,6 +807,80 @@ class TemplateBlock
807807
}
808808
};
809809

810+
//------------------------------------------------
811+
812+
class FunctionParamBlock
813+
: public BitcodeReader::AnyBlock
814+
{
815+
BitcodeReader& br_;
816+
Param& I_;
817+
818+
public:
819+
FunctionParamBlock(
820+
Param& I,
821+
BitcodeReader& br) noexcept
822+
: br_(br)
823+
, I_(I)
824+
{
825+
}
826+
827+
llvm::Error
828+
parseRecord(
829+
Record const& R,
830+
unsigned ID,
831+
llvm::StringRef Blob) override
832+
{
833+
switch(ID)
834+
{
835+
case FUNCTION_PARAM_NAME:
836+
{
837+
return decodeRecord(R, I_.Name, Blob);
838+
}
839+
case FUNCTION_PARAM_DEFAULT:
840+
{
841+
return decodeRecord(R, I_.Default, Blob);
842+
}
843+
/*
844+
case FUNCTION_PARAM_IS_PACK:
845+
{
846+
return decodeRecord(R, I_.IsParameterPack, Blob);
847+
}
848+
*/
849+
default:
850+
return AnyBlock::parseRecord(R, ID, Blob);
851+
}
852+
}
853+
854+
llvm::Error
855+
readSubBlock(
856+
unsigned ID) override
857+
{
858+
switch(ID)
859+
{
860+
case BI_TYPE_BLOCK_ID:
861+
{
862+
TypeBlock B(I_.Type, br_);
863+
if(auto Err = br_.readBlock(B, ID))
864+
return Err;
865+
// KRYSTIAN NOTE: is this check correct?
866+
// copied from a function with TypeInfo sub-block
867+
switch(B.F)
868+
{
869+
case FieldId::F_type:
870+
break;
871+
default:
872+
return makeWrongFieldError(B.F);
873+
}
874+
return llvm::Error::success();
875+
}
876+
default:
877+
break;
878+
}
879+
return AnyBlock::readSubBlock(ID);
880+
}
881+
};
882+
883+
810884
//------------------------------------------------
811885

812886
template<class T>
@@ -1041,6 +1115,8 @@ class FunctionBlock
10411115
}
10421116
return llvm::Error::success();
10431117
}
1118+
1119+
#if 0
10441120
case BI_FIELD_TYPE_BLOCK_ID:
10451121
{
10461122
FieldTypeBlock B(I->Params.emplace_back(), br_);
@@ -1055,6 +1131,13 @@ class FunctionBlock
10551131
}
10561132
return llvm::Error::success();
10571133
}
1134+
#else
1135+
case BI_FUNCTION_PARAM_BLOCK_ID:
1136+
{
1137+
FunctionParamBlock B(I->Params.emplace_back(), br_);
1138+
return br_.readBlock(B, ID);
1139+
}
1140+
#endif
10581141
case BI_TEMPLATE_BLOCK_ID:
10591142
{
10601143
TemplateBlock B(I->Template, br_);

0 commit comments

Comments
 (0)