Skip to content

Commit 9a12db8

Browse files
committed
Fixed a regression in the generator of C++/CLI.
Restored the sorting by order of definition. Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 32da859 commit 9a12db8

File tree

8 files changed

+46053
-46030
lines changed

8 files changed

+46053
-46030
lines changed

src/AST/DeclarationsList.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ protected override void InsertItem(int index, Declaration item)
3333
{
3434
Kind kind = GetKind(item);
3535
int offset = GetOffset(kind);
36-
if (GetStart(kind) < index && index < offset)
36+
// USR null means an artificial declaration, add at the end
37+
if (item.USR == null)
3738
{
38-
base.InsertItem(index, item);
39+
base.InsertItem(offset, item);
3940
}
4041
else
4142
{
42-
base.InsertItem(offset, item);
43+
int i = BinarySearch(GetStart(kind), offset, item);
44+
base.InsertItem(i, item);
4345
}
4446
for (Kind i = kind; i <= Kind.Event; i++)
4547
{
@@ -127,6 +129,27 @@ private int GetStart(Kind kind)
127129
return 0;
128130
}
129131

132+
private int BinarySearch(int start, int end, Declaration item)
133+
{
134+
int middle = end;
135+
136+
while (start < end)
137+
{
138+
middle = (start + end) / 2;
139+
140+
if (item.DefinitionOrder < this[middle].DefinitionOrder &&
141+
item.DefinitionOrder >= this[middle - 1].DefinitionOrder)
142+
break;
143+
144+
if (item.DefinitionOrder < this[middle].DefinitionOrder)
145+
end = middle;
146+
else
147+
start = ++middle;
148+
}
149+
150+
return middle;
151+
}
152+
130153
private Dictionary<Kind, int> offsets = new Dictionary<Kind, int>();
131154

132155
private enum Kind

src/CppParser/Bindings/CLI/AST.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ namespace CppSharp
444444

445445
static operator CppSharp::Parser::AST::Type^(CppSharp::Parser::AST::TypeKind kind);
446446

447-
protected:
447+
protected:
448448
bool __ownsNativeInstance;
449449
};
450450

@@ -485,7 +485,7 @@ namespace CppSharp
485485
void set(bool);
486486
}
487487

488-
protected:
488+
protected:
489489
bool __ownsNativeInstance;
490490
};
491491

@@ -520,7 +520,7 @@ namespace CppSharp
520520
void set(CppSharp::Parser::AST::TypeQualifiers^);
521521
}
522522

523-
protected:
523+
protected:
524524
bool __ownsNativeInstance;
525525
};
526526

@@ -818,7 +818,7 @@ namespace CppSharp
818818
void set(long);
819819
}
820820

821-
protected:
821+
protected:
822822
bool __ownsNativeInstance;
823823
};
824824

@@ -1131,7 +1131,7 @@ namespace CppSharp
11311131
void set(CppSharp::Parser::AST::Declaration^);
11321132
}
11331133

1134-
protected:
1134+
protected:
11351135
bool __ownsNativeInstance;
11361136
};
11371137

@@ -1171,7 +1171,7 @@ namespace CppSharp
11711171

11721172
void ClearComponents();
11731173

1174-
protected:
1174+
protected:
11751175
bool __ownsNativeInstance;
11761176
};
11771177

@@ -1218,7 +1218,7 @@ namespace CppSharp
12181218
void set(CppSharp::Parser::AST::VTableLayout^);
12191219
}
12201220

1221-
protected:
1221+
protected:
12221222
bool __ownsNativeInstance;
12231223
};
12241224

@@ -1265,7 +1265,7 @@ namespace CppSharp
12651265
void set(::System::IntPtr);
12661266
}
12671267

1268-
protected:
1268+
protected:
12691269
bool __ownsNativeInstance;
12701270
};
12711271

@@ -1300,7 +1300,7 @@ namespace CppSharp
13001300
void set(CppSharp::Parser::AST::Class^);
13011301
}
13021302

1303-
protected:
1303+
protected:
13041304
bool __ownsNativeInstance;
13051305
};
13061306

@@ -1416,7 +1416,7 @@ namespace CppSharp
14161416

14171417
void ClearBases();
14181418

1419-
protected:
1419+
protected:
14201420
bool __ownsNativeInstance;
14211421
};
14221422

@@ -1583,7 +1583,7 @@ namespace CppSharp
15831583

15841584
static operator CppSharp::Parser::AST::Declaration^(CppSharp::Parser::AST::DeclarationKind kind);
15851585

1586-
protected:
1586+
protected:
15871587
bool __ownsNativeInstance;
15881588
};
15891589

@@ -1870,7 +1870,7 @@ namespace CppSharp
18701870
void set(System::String^);
18711871
}
18721872

1873-
protected:
1873+
protected:
18741874
bool __ownsNativeInstance;
18751875
};
18761876

@@ -2400,7 +2400,7 @@ namespace CppSharp
24002400
void set(int);
24012401
}
24022402

2403-
protected:
2403+
protected:
24042404
bool __ownsNativeInstance;
24052405
};
24062406

@@ -2949,7 +2949,7 @@ namespace CppSharp
29492949

29502950
void ClearArguments();
29512951

2952-
protected:
2952+
protected:
29532953
bool __ownsNativeInstance;
29542954
};
29552955

@@ -3098,7 +3098,7 @@ namespace CppSharp
30983098
void set(CppSharp::Parser::AST::DeclarationKind);
30993099
}
31003100

3101-
protected:
3101+
protected:
31023102
bool __ownsNativeInstance;
31033103
};
31043104

@@ -3277,7 +3277,7 @@ namespace CppSharp
32773277

32783278
void ClearDependencies();
32793279

3280-
protected:
3280+
protected:
32813281
bool __ownsNativeInstance;
32823282
};
32833283

@@ -3319,7 +3319,7 @@ namespace CppSharp
33193319

33203320
void ClearTranslationUnits();
33213321

3322-
protected:
3322+
protected:
33233323
bool __ownsNativeInstance;
33243324
};
33253325

@@ -3350,7 +3350,7 @@ namespace CppSharp
33503350

33513351
static operator CppSharp::Parser::AST::Comment^(CppSharp::Parser::AST::CommentKind kind);
33523352

3353-
protected:
3353+
protected:
33543354
bool __ownsNativeInstance;
33553355
};
33563356

@@ -3489,7 +3489,7 @@ namespace CppSharp
34893489
void set(System::String^);
34903490
}
34913491

3492-
protected:
3492+
protected:
34933493
bool __ownsNativeInstance;
34943494
};
34953495

@@ -3702,7 +3702,7 @@ namespace CppSharp
37023702
void set(System::String^);
37033703
}
37043704

3705-
protected:
3705+
protected:
37063706
bool __ownsNativeInstance;
37073707
};
37083708

@@ -3796,7 +3796,7 @@ namespace CppSharp
37963796
void set(System::String^);
37973797
}
37983798

3799-
protected:
3799+
protected:
38003800
bool __ownsNativeInstance;
38013801
};
38023802

@@ -3913,7 +3913,7 @@ namespace CppSharp
39133913
void set(CppSharp::Parser::AST::FullComment^);
39143914
}
39153915

3916-
protected:
3916+
protected:
39173917
bool __ownsNativeInstance;
39183918
};
39193919
}

0 commit comments

Comments
 (0)