Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e41e8d6

Browse files
committed
C#: Remove ITrapBuilder in favour of TextWriter.
1 parent aeb38a1 commit e41e8d6

44 files changed

Lines changed: 550 additions & 552 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

csharp/extractor/Semmle.Extraction.CIL/Entities/Field.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection.Metadata;
66
using System.Reflection;
77
using System.Reflection.Metadata.Ecma335;
8+
using System.IO;
89

910
namespace Semmle.Extraction.CIL.Entities
1011
{
@@ -38,6 +39,16 @@ protected Field(Context cx) : base(cx)
3839

3940
public IId Id => ShortId + IdSuffix;
4041

42+
public void WriteId(TextWriter trapFile)
43+
{
44+
trapFile.WriteIId(Id);
45+
}
46+
47+
public void WriteQuotedId(TextWriter trapFile)
48+
{
49+
WriteId(trapFile);
50+
}
51+
4152
public Id IdSuffix => fieldSuffix;
4253

4354
static readonly StringId fieldSuffix = new StringId(";cil-field");

csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reflection;
77
using System.Linq;
88
using System.Reflection.Metadata.Ecma335;
9+
using System.IO;
910

1011
namespace Semmle.Extraction.CIL.Entities
1112
{

csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Collections.Generic;
77
using System.Reflection;
88
using Semmle.Util;
9+
using System.IO;
10+
using System.Text;
911

1012
namespace Semmle.Extraction.CIL.Entities
1113
{
@@ -55,6 +57,22 @@ protected TypeContainer(Context cx) : base(cx)
5557

5658
public virtual IId Id { get { return ShortId + IdSuffix; } }
5759

60+
public void WriteId(System.IO.TextWriter trapFile)
61+
{
62+
// TODO: Specialise this
63+
trapFile.WriteIId(Id);
64+
}
65+
66+
/// <summary>
67+
/// For debugging purposes.
68+
/// </summary>
69+
string DebugId => this.GetDebugLabel();
70+
71+
public void WriteQuotedId(TextWriter trapFile)
72+
{
73+
WriteId(trapFile);
74+
}
75+
5876
public Id ShortId { get; set; }
5977
public abstract Id IdSuffix { get; }
6078

csharp/extractor/Semmle.Extraction.CIL/ExtractionProduct.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34

45
namespace Semmle.Extraction.CIL
56
{
@@ -45,6 +46,16 @@ public abstract class UnlabelledEntity : IExtractedEntity
4546
public abstract IEnumerable<IExtractionProduct> Contents { get; }
4647
public Label Label { get; set; }
4748

49+
public void WriteId(System.IO.TextWriter trapFile)
50+
{
51+
trapFile.Write('*');
52+
}
53+
54+
public void WriteQuotedId(TextWriter trapFile)
55+
{
56+
WriteId(trapFile);
57+
}
58+
4859
public Microsoft.CodeAnalysis.Location ReportingLocation => throw new NotImplementedException();
4960

5061
public virtual IId Id => FreshId.Instance;
@@ -79,6 +90,16 @@ public abstract class LabelledEntity : ILabelledEntity
7990
public abstract Id IdSuffix { get; }
8091
public IId Id => ShortId + IdSuffix;
8192

93+
public void WriteId(System.IO.TextWriter trapFile)
94+
{
95+
trapFile.WriteIId(Id);
96+
}
97+
98+
public void WriteQuotedId(TextWriter trapFile)
99+
{
100+
WriteId(trapFile);
101+
}
102+
82103
public void Extract(Context cx2)
83104
{
84105
cx2.Populate(this);

csharp/extractor/Semmle.Extraction.CIL/Factories.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public T Populate<T>(T e) where T : ILabelledEntity
2323
}
2424
else
2525
{
26-
cx.DefineLabel(e);
26+
e.Label = cx.GetNewLabel();
27+
cx.DefineLabel(e, cx.TrapWriter.Writer);
2728
ids.Add(id, (e.Label, id));
2829
cx.PopulateLater(() =>
2930
{

csharp/extractor/Semmle.Extraction.CIL/Id.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.IO;
23
using System.Reflection.Metadata;
34

45
namespace Semmle.Extraction.CIL
@@ -9,14 +10,14 @@ namespace Semmle.Extraction.CIL
910
/// </summary>
1011
public abstract class Id : IId
1112
{
12-
public void AppendTo(ITrapBuilder tb)
13+
public void AppendTo(System.IO.TextWriter tb)
1314
{
14-
tb.Append("@\"");
15+
tb.Write("@\"");
1516
BuildParts(tb);
16-
tb.Append("\"");
17+
tb.Write("\"");
1718
}
1819

19-
public abstract void BuildParts(ITrapBuilder tb);
20+
public abstract void BuildParts(System.IO.TextWriter tb);
2021

2122
public static Id operator +(Id l1, Id l2) => Create(l1, l2);
2223

@@ -76,7 +77,7 @@ public ConsId(Id l1, Id l2)
7677
hash = unchecked(12 + 3 * (left.GetHashCode() + 51 * right.GetHashCode()));
7778
}
7879

79-
public override void BuildParts(ITrapBuilder tb)
80+
public override void BuildParts(System.IO.TextWriter tb)
8081
{
8182
left.BuildParts(tb);
8283
right.BuildParts(tb);
@@ -112,9 +113,9 @@ public StringId(string s)
112113
value = s;
113114
}
114115

115-
public override void BuildParts(ITrapBuilder tb)
116+
public override void BuildParts(System.IO.TextWriter tw)
116117
{
117-
tb.Append(value);
118+
tw.Write(value);
118119
}
119120

120121
public override bool Equals(object obj)
@@ -138,9 +139,9 @@ public IntId(int i)
138139
value = i;
139140
}
140141

141-
public override void BuildParts(ITrapBuilder tb)
142+
public override void BuildParts(System.IO.TextWriter tw)
142143
{
143-
tb.Append(value);
144+
tw.Write(value);
144145
}
145146

146147
public override bool Equals(object obj)

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ void DoExtractTree(SyntaxTree tree)
375375
Populators.CompilationUnit.Extract(cx, tree.GetRoot());
376376
cx.PopulateAll();
377377
cx.ExtractComments(cx.CommentGenerator);
378+
cx.PopulateAll();
378379
}
379380
}
380381
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentBlock.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Semmle.Extraction.CommentProcessing;
22
using Semmle.Extraction.Entities;
3+
using System.IO;
34

45
namespace Semmle.Extraction.CSharp.Entities
56
{
@@ -21,13 +22,10 @@ public override void Populate()
2122

2223
public override bool NeedsPopulation => true;
2324

24-
public override IId Id
25+
public override void WriteId(TextWriter tw)
2526
{
26-
get
27-
{
28-
var loc = Context.Create(symbol.Location);
29-
return new Key(loc, ";commentblock");
30-
}
27+
tw.WriteSubId(Context.Create(symbol.Location));
28+
tw.Write(";commentblock");
3129
}
3230

3331
public override Microsoft.CodeAnalysis.Location ReportingLocation => symbol.Location;

csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentLine.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.CodeAnalysis;
33
using Microsoft.CodeAnalysis.CSharp;
44
using Semmle.Extraction.Entities;
5+
using System.IO;
56

67
namespace Semmle.Extraction.CSharp.Entities
78
{
@@ -122,13 +123,10 @@ public override void Populate()
122123

123124
public override bool NeedsPopulation => true;
124125

125-
public override IId Id
126+
public override void WriteId(TextWriter tw)
126127
{
127-
get
128-
{
129-
var loc = Context.Create(Location);
130-
return new Key(loc, ";commentline");
131-
}
128+
tw.WriteSubId(Context.Create(Location));
129+
tw.Write(";commentline");
132130
}
133131

134132
static CommentLine Create(Context cx, Microsoft.CodeAnalysis.Location loc, CommentLineType type, string text, string raw) => CommentLineFactory.Instance.CreateEntity(cx, loc, type, text, raw);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using Microsoft.CodeAnalysis.CSharp;
77
using Semmle.Extraction.Entities;
8+
using System.IO;
89

910
namespace Semmle.Extraction.CSharp.Entities
1011
{
@@ -109,18 +110,12 @@ ConstructorDeclarationSyntax Syntax
109110
}
110111
}
111112

112-
public override IId Id
113+
public override void WriteId(TextWriter trapFile)
113114
{
114-
get
115-
{
116-
return new Key(tb =>
117-
{
118-
if (symbol.IsStatic) tb.Append("static");
119-
tb.Append(ContainingType);
120-
AddParametersToId(Context, tb, symbol);
121-
tb.Append(";constructor");
122-
});
123-
}
115+
if (symbol.IsStatic) trapFile.Write("static");
116+
trapFile.WriteSubId(ContainingType);
117+
AddParametersToId(Context, trapFile, symbol);
118+
trapFile.Write(";constructor");
124119
}
125120

126121
ConstructorDeclarationSyntax GetSyntax() =>

0 commit comments

Comments
 (0)