Skip to content

Commit e268db6

Browse files
committed
Fix source code references for objective-c members
- also provide better support for methods returning block types.
1 parent 39744a6 commit e268db6

8 files changed

Lines changed: 55 additions & 11 deletions

File tree

src/code.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,7 @@ static void startCodeLine(yyscan_t yyscanner)
25612561
//lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
25622562
25632563
const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
2564+
//printf("%s:startCodeLine(%d)=%p\n",qPrint(yyextra->sourceFileDef->name()),yyextra->yyLineNr,(void*)d);
25642565
DBG_CTX((stderr,"%s:startCodeLine(%d)=%p\n",qPrint(yyextra->sourceFileDef->name()),yyextra->yyLineNr,(void*)d));
25652566
if (!yyextra->includeCodeFragment && d)
25662567
{

src/declinfo.l

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ ID ([$a-z_A-Z\x80-\xFF][$a-z_A-Z0-9\x80-\xFF]*)|(@[0-9]+)
106106
yyextra->name += yytext;
107107
BEGIN(Operator);
108108
}
109+
<Start>{ID}({B}*"*")?{B}*"("{B}*"^"{B}*")"{B}*"(" { // Objective-C 2.0 block return type
110+
if (!yyextra->insideObjC)
111+
{
112+
REJECT;
113+
}
114+
else
115+
{
116+
addType(yyscanner);
117+
yyextra->type += yytext;
118+
}
119+
}
109120
<Start>{ID}{B}*"("{B}*{ID}{B}*")" { // Objective-C class categories
110121
if (!yyextra->insideObjC)
111122
{

src/definition.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,6 @@ void DefinitionImpl::writeSourceDef(OutputList &ol,const QCString &) const
10051005

10061006
void DefinitionImpl::setBodySegment(int defLine, int bls,int ble)
10071007
{
1008-
//printf("setBodySegment(%d,%d) for %s\n",bls,ble,qPrint(name()));
10091008
if (!m_impl->body) m_impl->body = make_DeepCopyUnique<BodyInfo>();
10101009
m_impl->body->defLine = defLine;
10111010
m_impl->body->startLine = bls;

src/doxygen.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,19 @@ static void buildFunctionList(const Entry *root)
37883788
addMethodToClass(root,cd,root->type,rname,root->args,isFriend,
37893789
root->protection,root->isStatic,root->virt,root->spec,root->relates);
37903790
}
3791+
else if (root->parent()->section.isObjcImpl() && cd)
3792+
{
3793+
const MemberDef *md = cd->getMemberByName(rname);
3794+
if (md)
3795+
{
3796+
MemberDefMutable *mdm = toMemberDefMutable(const_cast<MemberDef*>(md));
3797+
if (mdm)
3798+
{
3799+
mdm->setBodySegment(root->startLine,root->bodyLine,root->endBodyLine);
3800+
mdm->setBodyDef(root->fileDef());
3801+
}
3802+
}
3803+
}
37913804
else if (!root->parent()->section.isCompound() && !root->parent()->section.isObjcImpl() &&
37923805
!isMember &&
37933806
(root->relates.isEmpty() || root->relatesType==RelatesType::Duplicate) &&
@@ -4105,7 +4118,7 @@ static void transferFunctionDocumentation()
41054118
// find matching function declaration and definitions.
41064119
for (const auto &mn : *Doxygen::functionNameLinkedMap)
41074120
{
4108-
//printf("memberName=%s count=%d\n",mn->memberName(),mn->count());
4121+
//printf("memberName=%s count=%zu\n",qPrint(mn->memberName()),mn->size());
41094122
/* find a matching function declaration and definition for this function */
41104123
for (const auto &imdec : *mn)
41114124
{

src/filedef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ const QCString &FileDefImpl::name() const
14371437

14381438
void FileDefImpl::addSourceRef(int line,const Definition *d,const MemberDef *md)
14391439
{
1440-
//printf("FileDefImpl::addSourceDef(%d,%p,%p)\n",line,d,md);
1440+
//printf("FileDefImpl::addSourceRef(%d,%s,%s)\n",line,qPrint(d?d->name():"nullptr"),qPrint(md?md->name():"nullptr"));
14411441
if (d)
14421442
{
14431443
m_srcDefMap.emplace(line,d);

src/scanner.l

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ NONLopt [^\n]*
794794
yyextra->current->section = EntryType::makeFunction();
795795
yyextra->language = yyextra->current->lang = SrcLangExt::ObjC;
796796
yyextra->insideObjC = TRUE;
797+
yyextra->yyBegColNr = yyextra->yyColNr;
798+
yyextra->yyBegLineNr = yyextra->yyLineNr;
797799
yyextra->current->virt = Specifier::Virtual;
798800

799801
yyextra->current->isStatic=yytext[0]=='+';
@@ -803,11 +805,13 @@ NONLopt [^\n]*
803805
}
804806
<ObjCMethod>"(" { // start of method's return type
805807
BEGIN( ObjCReturnType );
808+
yyextra->current->type.clear();
809+
yyextra->roundCount=0;
806810
}
807811
<ObjCMethod>{ID} { // found method name
808812
if (yyextra->current->type.isEmpty())
809813
{
810-
yyextra->current->type = "id";
814+
yyextra->current->type += "id";
811815
}
812816
yyextra->current->name = yytext;
813817
storeClangId(yyscanner,yytext);
@@ -818,11 +822,27 @@ NONLopt [^\n]*
818822
yyextra->current->argList.push_back(a);
819823
BEGIN( ObjCParams );
820824
}
821-
<ObjCReturnType>[^)]* { // TODO: check if nested branches are possible.
822-
yyextra->current->type = yytext;
825+
<ObjCReturnType>[^()]* {
826+
yyextra->current->type += yytext;
827+
}
828+
<ObjCReturnType>"(^)(" { // Block return type
829+
yyextra->current->type += yytext;
830+
yyextra->roundCount++;
831+
}
832+
<ObjCReturnType>"(" {
833+
yyextra->current->type += yytext;
834+
yyextra->roundCount++;
823835
}
824836
<ObjCReturnType>")" {
825-
BEGIN( ObjCMethod );
837+
if (yyextra->roundCount<=0)
838+
{
839+
BEGIN( ObjCMethod );
840+
}
841+
else
842+
{
843+
yyextra->current->type += yytext;
844+
yyextra->roundCount--;
845+
}
826846
}
827847
<ObjCParams>({ID})?{BN}*":" { // Keyword of parameter
828848
QCString keyw = yytext;

testing/011/category_integer_07_arithmetic_08.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</detaileddescription>
2121
<inbodydescription>
2222
</inbodydescription>
23-
<location file="011_category.m" line="8" column="6"/>
23+
<location file="011_category.m" line="19" column="1"/>
2424
</memberdef>
2525
<memberdef kind="function" id="category_integer_07_arithmetic_08_1ae4ff0b0c62b6809e8f5bcee9baa6e521" prot="public" static="no" const="no" explicit="no" inline="no" virt="virtual">
2626
<type>id</type>
@@ -39,7 +39,7 @@
3939
</detaileddescription>
4040
<inbodydescription>
4141
</inbodydescription>
42-
<location file="011_category.m" line="8" column="6"/>
42+
<location file="011_category.m" line="21" column="1"/>
4343
</memberdef>
4444
</sectiondef>
4545
<briefdescription>

testing/011/interface_integer.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</detaileddescription>
3535
<inbodydescription>
3636
</inbodydescription>
37-
<location file="011_category.m" line="8" column="6"/>
37+
<location file="011_category.m" line="12" column="1"/>
3838
</memberdef>
3939
<memberdef kind="function" id="interface_integer_1ad2f47761103b2442ff7b3fbfe33ec6c9" prot="public" static="no" const="no" explicit="no" inline="no" virt="virtual">
4040
<type>id</type>
@@ -53,7 +53,7 @@
5353
</detaileddescription>
5454
<inbodydescription>
5555
</inbodydescription>
56-
<location file="011_category.m" line="8" column="6"/>
56+
<location file="011_category.m" line="14" column="1"/>
5757
</memberdef>
5858
</sectiondef>
5959
<briefdescription>

0 commit comments

Comments
 (0)