54
public LocationStorage LocationStorage {
54
public LocationsBag LocationsBag {
59
public ConversionVisitor (LocationStorage locationStorage)
59
public ConversionVisitor (LocationsBag locationsBag)
61
this.LocationStorage = locationStorage;
61
this.LocationsBag = locationsBag;
64
public static DomLocation Convert (Mono.CSharp.Location loc)
64
public static AstLocation Convert (Mono.CSharp.Location loc)
66
return new DomLocation (loc.Row - 1, loc.Column - 1);
66
return new AstLocation (loc.Row, loc.Column);
70
public override void Visit (ModuleCompiled mc)
70
Stack<NamespaceDeclaration> namespaceStack = new Stack<NamespaceDeclaration> ();
72
void AddTypeArguments (ATypeNameExpression texpr, AstType result)
74
if (!texpr.HasTypeArguments)
76
foreach (var arg in texpr.TypeArguments.Args) {
77
result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
81
AstType ConvertToType (Mono.CSharp.Expression typeName)
83
if (typeName is TypeExpression) {
84
var typeExpr = (Mono.CSharp.TypeExpression)typeName;
85
return new PrimitiveType (typeExpr.GetSignatureForError (), Convert (typeExpr.Location));
88
if (typeName is Mono.CSharp.QualifiedAliasMember) {
89
var qam = (Mono.CSharp.QualifiedAliasMember)typeName;
90
var memberType = new MonoDevelop.CSharp.Ast.MemberType ();
91
if (qam.LeftExpression == null) {
92
memberType.Target = new SimpleType ("global", Convert (qam.Location));
94
memberType.Target = ConvertToType (qam.LeftExpression);
96
memberType.IsDoubleColon = true;
97
memberType.MemberName = qam.Name;
101
if (typeName is MemberAccess) {
102
MemberAccess ma = (MemberAccess)typeName;
104
var memberType = new MonoDevelop.CSharp.Ast.MemberType ();
105
memberType.AddChild (ConvertToType (ma.LeftExpression), MonoDevelop.CSharp.Ast.MemberType.TargetRole);
106
memberType.MemberName = ma.Name;
108
AddTypeArguments (ma, memberType);
112
if (typeName is SimpleName) {
113
var sn = (SimpleName)typeName;
114
var result = new SimpleType (sn.Name, Convert (sn.Location));
115
AddTypeArguments (sn, result);
119
if (typeName is ComposedCast) {
120
var cc = (ComposedCast)typeName;
121
var baseType = ConvertToType (cc.Left);
122
var result = new ComposedType () { BaseType = baseType };
124
if (cc.Spec.IsNullable) {
125
result.HasNullableSpecifier = true;
126
} else if (cc.Spec.IsPointer) {
127
result.PointerRank++;
129
var location = LocationsBag.GetLocations (cc.Spec);
130
var spec = new ArraySpecifier () { Dimensions = cc.Spec.Dimension };
131
spec.AddChild (new CSharpTokenNode (Convert (cc.Spec.Location), 1), FieldDeclaration.Roles.LBracket);
132
if (location != null)
133
spec.AddChild (new CSharpTokenNode (Convert (location [0]), 1), FieldDeclaration.Roles.RBracket);
135
result.AddChild (spec, ComposedType.ArraySpecifierRole);
140
System.Console.WriteLine ("Error while converting :" + typeName + " - unknown type name");
141
System.Console.WriteLine (Environment.StackTrace);
142
return new SimpleType ("unknown");
145
public override void Visit (UsingsBag.Namespace nspace)
147
NamespaceDeclaration nDecl = null;
148
if (nspace.Name != null) {
149
nDecl = new NamespaceDeclaration ();
150
nDecl.AddChild (new CSharpTokenNode (Convert (nspace.NamespaceLocation), "namespace".Length), NamespaceDeclaration.Roles.Keyword);
151
ConvertNamespaceName (nspace.Name, nDecl);
152
nDecl.AddChild (new CSharpTokenNode (Convert (nspace.OpenBrace), 1), NamespaceDeclaration.Roles.LBrace);
153
AddToNamespace (nDecl);
154
namespaceStack.Push (nDecl);
157
VisitNamespaceUsings (nspace);
158
VisitNamespaceBody (nspace);
161
nDecl.AddChild (new CSharpTokenNode (Convert (nspace.CloseBrace), 1), NamespaceDeclaration.Roles.RBrace);
162
if (!nspace.OptSemicolon.IsNull)
163
nDecl.AddChild (new CSharpTokenNode (Convert (nspace.OptSemicolon), 1), NamespaceDeclaration.Roles.Semicolon);
165
namespaceStack.Pop ();
169
void ConvertNamespaceName (MemberName memberName, NamespaceDeclaration namespaceDecl)
171
AstNode insertPos = null;
172
while (memberName != null) {
173
Identifier newIdent = CreateIdentifier (memberName.Name, Convert (memberName.Location));
174
namespaceDecl.InsertChildBefore (insertPos, newIdent, NamespaceDeclaration.Roles.Identifier);
175
insertPos = newIdent;
176
memberName = memberName.Left;
180
public override void Visit (UsingsBag.Using u)
182
UsingDeclaration ud = new UsingDeclaration ();
183
ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingDeclaration.Roles.Keyword);
184
ud.AddChild (ConvertImport (u.NSpace), UsingDeclaration.ImportRole);
185
ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingDeclaration.Roles.Semicolon);
189
public override void Visit (UsingsBag.AliasUsing u)
191
UsingAliasDeclaration ud = new UsingAliasDeclaration ();
192
ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingAliasDeclaration.Roles.Keyword);
193
ud.AddChild (CreateIdentifier (u.Identifier.Value, Convert (u.Identifier.Location)), UsingAliasDeclaration.AliasRole);
194
ud.AddChild (new CSharpTokenNode (Convert (u.AssignLocation), 1), UsingAliasDeclaration.Roles.Assign);
195
ud.AddChild (ConvertImport (u.Nspace), UsingAliasDeclaration.ImportRole);
196
ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingAliasDeclaration.Roles.Semicolon);
200
AstType ConvertImport (MemberName memberName)
202
if (memberName.Left != null) {
204
var t = new MonoDevelop.CSharp.Ast.MemberType();
205
t.IsDoubleColon = memberName.IsDoubleColon;
206
t.AddChild (ConvertImport (memberName.Left), MonoDevelop.CSharp.Ast.MemberType.TargetRole);
207
t.AddChild (CreateIdentifier (memberName.Name, Convert(memberName.Location)), MonoDevelop.CSharp.Ast.MemberType.Roles.Identifier);
210
SimpleType t = new SimpleType();
211
t.AddChild (CreateIdentifier (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier);
212
// TODO type arguments
75
217
public override void Visit (MemberCore member)
77
219
Console.WriteLine ("Unknown member:");
158
312
public override void Visit (Mono.CSharp.Delegate d)
160
314
DelegateDeclaration newDelegate = new DelegateDeclaration ();
161
LocationDescriptor location = LocationStorage.Get (d);
315
var location = LocationsBag.GetMemberLocation (d);
163
317
AddModifiers (newDelegate, location);
165
newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.TypeKeyword);
166
newDelegate.AddChild ((INode)d.ReturnType.Accept (this), AbstractNode.Roles.ReturnType);
167
newDelegate.AddChild (new Identifier (d.Name, Convert (location[1])), AbstractNode.Roles.Identifier);
318
if (location != null)
319
newDelegate.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), TypeDeclaration.Roles.Keyword);
320
newDelegate.AddChild (ConvertToType (d.ReturnType), AstNode.Roles.Type);
321
newDelegate.AddChild (CreateIdentifier (d.Basename, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
168
322
if (d.MemberName.TypeArguments != null) {
169
LocationDescriptor typeArgLocation = LocationStorage.Get (d.MemberName);
170
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
171
AddTypeArguments (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
172
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
323
var typeArgLocation = LocationsBag.GetLocations (d.MemberName);
324
if (typeArgLocation != null)
325
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
326
AddTypeParameters (newDelegate, typeArgLocation, d.MemberName.TypeArguments);
327
if (typeArgLocation != null)
328
newDelegate.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
173
329
AddConstraints (newDelegate, d);
176
newDelegate.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DelegateDeclaration.Roles.LPar);
177
newDelegate.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DelegateDeclaration.Roles.RPar);
178
newDelegate.AddChild (new CSharpTokenNode (Convert (location[4]), 1), DelegateDeclaration.Roles.Semicolon);
331
if (location != null)
332
newDelegate.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DelegateDeclaration.Roles.LPar);
333
AddParameter (newDelegate, d.Parameters);
335
if (location != null) {
336
newDelegate.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DelegateDeclaration.Roles.RPar);
337
newDelegate.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DelegateDeclaration.Roles.Semicolon);
180
339
AddType (newDelegate);
183
void AddType (INode child)
342
void AddType (AttributedNode child)
185
344
if (typeStack.Count > 0) {
186
typeStack.Peek ().AddChild (child);
188
unit.AddChild (child);
345
typeStack.Peek ().AddChild (child, TypeDeclaration.MemberRole);
347
AddToNamespace (child);
351
void AddToNamespace (AstNode child)
353
if (namespaceStack.Count > 0) {
354
namespaceStack.Peek ().AddChild (child, NamespaceDeclaration.MemberRole);
356
unit.AddChild (child, MonoDevelop.CSharp.Ast.CompilationUnit.MemberRole);
192
360
public override void Visit (Mono.CSharp.Enum e)
194
362
TypeDeclaration newType = new TypeDeclaration ();
195
newType.ClassType = MonoDevelop.Projects.Dom.ClassType.Enum;
196
LocationDescriptor location = LocationStorage.Get (e);
363
newType.ClassType = ClassType.Enum;
364
var location = LocationsBag.GetMemberLocation (e);
198
366
AddModifiers (newType, location);
199
newType.AddChild (new CSharpTokenNode (Convert (location[0]), "enum".Length), TypeDeclaration.TypeKeyword);
200
newType.AddChild (new Identifier (e.Name, Convert (location[1])), AbstractNode.Roles.Identifier);
202
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AbstractCSharpNode.Roles.LBrace);
367
if (location != null)
368
newType.AddChild (new CSharpTokenNode (Convert (location[0]), "enum".Length), TypeDeclaration.Roles.Keyword);
369
newType.AddChild (CreateIdentifier (e.Basename, Convert (e.MemberName.Location)), AstNode.Roles.Identifier);
370
if (location != null && location.Count > 1)
371
newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace);
203
372
typeStack.Push (newType);
205
newType.AddChild (new CSharpTokenNode (Convert (location[3]), 1), AbstractCSharpNode.Roles.RBrace);
374
if (location != null && location.Count > 2)
375
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace);
206
376
typeStack.Pop ();
207
377
AddType (newType);
210
380
public override void Visit (EnumMember em)
212
FieldDeclaration newField = new FieldDeclaration ();
382
EnumMemberDeclaration newField = new EnumMemberDeclaration ();
213
383
VariableInitializer variable = new VariableInitializer ();
215
variable.AddChild (new Identifier (em.Name, Convert (em.Location)), AbstractNode.Roles.Identifier);
385
variable.AddChild (CreateIdentifier (em.Name, Convert (em.Location)), AstNode.Roles.Identifier);
217
387
if (em.Initializer != null) {
218
INode initializer = (INode)Visit (em.Initializer);
219
if (initializer != null)
220
variable.AddChild (initializer, AbstractNode.Roles.Initializer);
388
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)em.Initializer.Accept (this), VariableInitializer.Roles.Expression);
223
newField.AddChild (variable, AbstractNode.Roles.Initializer);
224
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
227
public override object Visit (EnumInitializer initializer)
229
return initializer.Expr != null ? initializer.Expr.Accept (this) : null;
391
newField.AddChild (variable, AstNode.Roles.Variable);
392
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
233
396
#region Type members
234
399
public override void Visit (FixedField f)
236
LocationDescriptor location = LocationStorage.Get (f);
238
FieldDeclaration newField;
240
DomLocation semicolonLocation = Convert (location[0]);
241
if (!visitedFields.TryGetValue (semicolonLocation, out newField)) {
242
newField = new FieldDeclaration ();
244
newField.AddChild (new CSharpTokenNode (Convert (location[1]), "fixed".Length), FieldDeclaration.Roles.Keyword);
245
newField.AddChild ((INode)f.TypeName.Accept (this), FieldDeclaration.Roles.ReturnType);
246
newField.AddChild (new CSharpTokenNode (semicolonLocation, 1), FieldDeclaration.Roles.Semicolon);
248
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
250
visitedFields[semicolonLocation] = newField;
252
newField.InsertChildBefore (newField.Semicolon, new CSharpTokenNode (Convert (location.LocationList [newField.Variables.Count () - 1]), 1), FieldDeclaration.Roles.Comma);
401
var location = LocationsBag.GetMemberLocation (f);
403
FieldDeclaration newField = new FieldDeclaration ();
405
AddModifiers (newField, location);
406
if (location != null)
407
newField.AddChild (new CSharpTokenNode (Convert (location[0]), "fixed".Length), FieldDeclaration.Roles.Keyword);
408
newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
255
410
VariableInitializer variable = new VariableInitializer ();
256
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), AbstractNode.Roles.Identifier);
257
newField.InsertChildBefore (newField.Semicolon, variable, AbstractNode.Roles.Initializer);
411
variable.AddChild (CreateIdentifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier);
412
if (!f.Initializer.IsNull) {
413
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)f.Initializer.Accept (this), FieldDeclaration.Roles.Expression);
416
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
417
if (f.Declarators != null) {
418
foreach (var decl in f.Declarators) {
419
var declLoc = LocationsBag.GetLocations (decl);
421
newField.AddChild (new CSharpTokenNode (Convert (declLoc[0]), 1), FieldDeclaration.Roles.Comma);
423
variable = new VariableInitializer ();
424
variable.AddChild (CreateIdentifier (decl.Name.Value, Convert (decl.Name.Location)), FieldDeclaration.Roles.Identifier);
425
if (!decl.Initializer.IsNull) {
426
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)decl.Initializer.Accept (this), FieldDeclaration.Roles.Expression);
428
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
431
if (location != null)
432
newField.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FieldDeclaration.Roles.Semicolon);
433
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
260
Dictionary<DomLocation, FieldDeclaration> visitedFields = new Dictionary<DomLocation, FieldDeclaration> ();
261
437
public override void Visit (Field f)
263
LocationDescriptor location = LocationStorage.Get (f);
265
FieldDeclaration newField;
267
DomLocation semicolonLocation = Convert (location[0]);
268
if (!visitedFields.TryGetValue (semicolonLocation, out newField)) {
269
newField = new FieldDeclaration ();
270
newField.AddChild ((INode)f.TypeName.Accept (this), FieldDeclaration.Roles.ReturnType);
271
newField.AddChild (new CSharpTokenNode (semicolonLocation, 1), FieldDeclaration.Roles.Semicolon);
273
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
275
visitedFields[semicolonLocation] = newField;
277
newField.InsertChildBefore (newField.Semicolon, new CSharpTokenNode (Convert (location.LocationList [newField.Variables.Count () - 1]), 1), FieldDeclaration.Roles.Comma);
280
VariableInitializer variable = new VariableInitializer ();
281
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), AbstractNode.Roles.Identifier);
282
newField.InsertChildBefore (newField.Semicolon, variable, AbstractNode.Roles.Initializer);
439
var location = LocationsBag.GetMemberLocation (f);
441
FieldDeclaration newField = new FieldDeclaration ();
443
AddModifiers (newField, location);
444
newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
446
VariableInitializer variable = new VariableInitializer ();
447
variable.AddChild (CreateIdentifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier);
449
if (f.Initializer != null) {
450
if (location != null)
451
variable.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.Assign);
452
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)f.Initializer.Accept (this), VariableInitializer.Roles.Expression);
454
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
455
if (f.Declarators != null) {
456
foreach (var decl in f.Declarators) {
457
var declLoc = LocationsBag.GetLocations (decl);
459
newField.AddChild (new CSharpTokenNode (Convert (declLoc[0]), 1), FieldDeclaration.Roles.Comma);
461
variable = new VariableInitializer ();
462
variable.AddChild (CreateIdentifier (decl.Name.Value, Convert (decl.Name.Location)), VariableInitializer.Roles.Identifier);
463
if (decl.Initializer != null) {
464
variable.AddChild (new CSharpTokenNode (Convert (decl.Initializer.Location), 1), FieldDeclaration.Roles.Assign);
465
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
467
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
470
if (location != null)
471
newField.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), 1), FieldDeclaration.Roles.Semicolon);
473
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
476
public override void Visit (Const f)
478
var location = LocationsBag.GetMemberLocation (f);
480
FieldDeclaration newField = new FieldDeclaration ();
482
AddModifiers (newField, location);
483
if (location != null)
484
newField.AddChild (new CSharpTokenNode (Convert (location[0]), "const".Length), FieldDeclaration.Roles.Keyword);
485
newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
487
VariableInitializer variable = new VariableInitializer ();
488
variable.AddChild (CreateIdentifier (f.MemberName.Name, Convert (f.MemberName.Location)), VariableInitializer.Roles.Identifier);
490
if (f.Initializer != null) {
491
variable.AddChild (new CSharpTokenNode (Convert (f.Initializer.Location), 1), VariableInitializer.Roles.Assign);
492
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)f.Initializer.Accept (this), VariableInitializer.Roles.Expression);
494
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
495
if (f.Declarators != null) {
496
foreach (var decl in f.Declarators) {
497
var declLoc = LocationsBag.GetLocations (decl);
499
newField.AddChild (new CSharpTokenNode (Convert (declLoc[0]), 1), FieldDeclaration.Roles.Comma);
501
variable = new VariableInitializer ();
502
variable.AddChild (CreateIdentifier (decl.Name.Value, Convert (decl.Name.Location)), FieldDeclaration.Roles.Identifier);
503
if (decl.Initializer != null) {
504
variable.AddChild (new CSharpTokenNode (Convert (decl.Initializer.Location), 1), FieldDeclaration.Roles.Assign);
505
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
507
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
510
if (location != null)
511
newField.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FieldDeclaration.Roles.Semicolon);
513
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
285
518
public override void Visit (Operator o)
287
520
OperatorDeclaration newOperator = new OperatorDeclaration ();
288
521
newOperator.OperatorType = (OperatorType)o.OperatorType;
290
LocationDescriptor location = LocationStorage.Get (o);
523
var location = LocationsBag.GetMemberLocation (o);
291
525
AddModifiers (newOperator, location);
293
newOperator.AddChild ((INode)o.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
527
newOperator.AddChild (ConvertToType (o.TypeName), AstNode.Roles.Type);
295
529
if (o.OperatorType == Operator.OpType.Implicit) {
296
newOperator.AddChild (new CSharpTokenNode (Convert (location[3]), "implicit".Length), OperatorDeclaration.OperatorTypeRole);
297
newOperator.AddChild (new CSharpTokenNode (Convert (location[2]), "operator".Length), OperatorDeclaration.OperatorKeywordRole);
530
if (location != null) {
531
newOperator.AddChild (new CSharpTokenNode (Convert (location[0]), "implicit".Length), OperatorDeclaration.OperatorTypeRole);
532
newOperator.AddChild (new CSharpTokenNode (Convert (location[1]), "operator".Length), OperatorDeclaration.OperatorKeywordRole);
298
534
} else if (o.OperatorType == Operator.OpType.Explicit) {
299
newOperator.AddChild (new CSharpTokenNode (Convert (location[3]), "explicit".Length), OperatorDeclaration.OperatorTypeRole);
300
newOperator.AddChild (new CSharpTokenNode (Convert (location[2]), "operator".Length), OperatorDeclaration.OperatorKeywordRole);
535
if (location != null) {
536
newOperator.AddChild (new CSharpTokenNode (Convert (location[0]), "explicit".Length), OperatorDeclaration.OperatorTypeRole);
537
newOperator.AddChild (new CSharpTokenNode (Convert (location[1]), "operator".Length), OperatorDeclaration.OperatorKeywordRole);
302
newOperator.AddChild (new CSharpTokenNode (Convert (location[2]), "operator".Length), OperatorDeclaration.OperatorKeywordRole);
540
if (location != null)
541
newOperator.AddChild (new CSharpTokenNode (Convert (location[0]), "operator".Length), OperatorDeclaration.OperatorKeywordRole);
304
543
int opLength = 1;
305
544
switch (newOperator.OperatorType) {
306
case OperatorType.LeftShift:
307
case OperatorType.RightShift:
308
case OperatorType.LessThanOrEqual:
309
case OperatorType.GreaterThanOrEqual:
310
case OperatorType.Equality:
311
case OperatorType.Inequality:
545
case OperatorType.LeftShift:
546
case OperatorType.RightShift:
547
case OperatorType.LessThanOrEqual:
548
case OperatorType.GreaterThanOrEqual:
549
case OperatorType.Equality:
550
case OperatorType.Inequality:
312
551
// case OperatorType.LogicalAnd:
313
552
// case OperatorType.LogicalOr:
316
case OperatorType.True:
317
opLength = "true".Length;
319
case OperatorType.False:
320
opLength = "false".Length;
555
case OperatorType.True:
556
opLength = "true".Length;
558
case OperatorType.False:
559
opLength = "false".Length;
323
newOperator.AddChild (new CSharpTokenNode (Convert (location[3]), opLength), OperatorDeclaration.OperatorTypeRole);
562
if (location != null)
563
newOperator.AddChild (new CSharpTokenNode (Convert (location[1]), opLength), OperatorDeclaration.OperatorTypeRole);
326
newOperator.AddChild (new CSharpTokenNode (Convert (location[0]), 1), OperatorDeclaration.Roles.LPar);
565
if (location != null)
566
newOperator.AddChild (new CSharpTokenNode (Convert (location[2]), 1), OperatorDeclaration.Roles.LPar);
327
567
AddParameter (newOperator, o.ParameterInfo);
328
newOperator.AddChild (new CSharpTokenNode (Convert (location[1]), 1), OperatorDeclaration.Roles.RPar);
568
if (location != null)
569
newOperator.AddChild (new CSharpTokenNode (Convert (location[3]), 1), OperatorDeclaration.Roles.RPar);
330
571
if (o.Block != null)
331
newOperator.AddChild ((INode)o.Block.Accept (this), OperatorDeclaration.Roles.Body);
572
newOperator.AddChild ((BlockStatement)o.Block.Accept (this), OperatorDeclaration.Roles.Body);
333
typeStack.Peek ().AddChild (newOperator, TypeDeclaration.Roles.Member);
574
typeStack.Peek ().AddChild (newOperator, TypeDeclaration.MemberRole);
336
577
public override void Visit (Indexer indexer)
338
579
IndexerDeclaration newIndexer = new IndexerDeclaration ();
340
LocationDescriptor location = LocationStorage.Get (indexer);
581
var location = LocationsBag.GetMemberLocation (indexer);
341
582
AddModifiers (newIndexer, location);
343
newIndexer.AddChild ((INode)indexer.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
345
newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket);
346
AddParameter (newIndexer, indexer.parameters);
347
newIndexer.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IndexerDeclaration.Roles.RBracket);
349
newIndexer.AddChild (new CSharpTokenNode (Convert (location[2]), 1), IndexerDeclaration.Roles.LBrace);
584
newIndexer.AddChild (ConvertToType (indexer.TypeName), AstNode.Roles.Type);
586
if (location != null)
587
newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket);
588
AddParameter (newIndexer, indexer.ParameterInfo);
589
if (location != null)
590
newIndexer.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IndexerDeclaration.Roles.RBracket);
592
if (location != null)
593
newIndexer.AddChild (new CSharpTokenNode (Convert (location[2]), 1), IndexerDeclaration.Roles.LBrace);
350
594
if (indexer.Get != null) {
351
MonoDevelop.CSharp.Dom.Accessor getAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
352
LocationDescriptor getLocation = LocationStorage.Get (indexer.Get);
595
Accessor getAccessor = new Accessor ();
596
var getLocation = LocationsBag.GetMemberLocation (indexer.Get);
353
597
AddModifiers (getAccessor, getLocation);
354
getAccessor.AddChild (new CSharpTokenNode (Convert (getLocation[0]), "get".Length), PropertyDeclaration.Roles.Keyword);
355
if (indexer.Get.Block != null)
356
getAccessor.AddChild ((INode)indexer.Get.Block.Accept (this), MethodDeclaration.Roles.Body);
357
newIndexer.AddChild (getAccessor, PropertyDeclaration.PropertyGetRole);
598
if (getLocation != null)
599
getAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Get.Location), "get".Length), PropertyDeclaration.Roles.Keyword);
600
if (indexer.Get.Block != null) {
601
getAccessor.AddChild ((BlockStatement)indexer.Get.Block.Accept (this), MethodDeclaration.Roles.Body);
603
if (getLocation != null && getLocation.Count > 0)
604
newIndexer.AddChild (new CSharpTokenNode (Convert (getLocation[0]), 1), MethodDeclaration.Roles.Semicolon);
606
newIndexer.AddChild (getAccessor, PropertyDeclaration.GetterRole);
360
609
if (indexer.Set != null) {
361
MonoDevelop.CSharp.Dom.Accessor setAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
362
LocationDescriptor setLocation = LocationStorage.Get (indexer.Set);
610
Accessor setAccessor = new Accessor ();
611
var setLocation = LocationsBag.GetMemberLocation (indexer.Set);
363
612
AddModifiers (setAccessor, setLocation);
364
setAccessor.AddChild (new CSharpTokenNode (Convert (setLocation[0]), "set".Length), PropertyDeclaration.Roles.Keyword);
613
if (setLocation != null)
614
setAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Set.Location), "set".Length), PropertyDeclaration.Roles.Keyword);
366
if (indexer.Set.Block != null)
367
setAccessor.AddChild ((INode)indexer.Set.Block.Accept (this), MethodDeclaration.Roles.Body);
368
newIndexer.AddChild (setAccessor, PropertyDeclaration.PropertySetRole);
616
if (indexer.Set.Block != null) {
617
setAccessor.AddChild ((BlockStatement)indexer.Set.Block.Accept (this), MethodDeclaration.Roles.Body);
619
if (setLocation != null && setLocation.Count > 0)
620
newIndexer.AddChild (new CSharpTokenNode (Convert (setLocation[0]), 1), MethodDeclaration.Roles.Semicolon);
622
newIndexer.AddChild (setAccessor, PropertyDeclaration.SetterRole);
371
newIndexer.AddChild (new CSharpTokenNode (Convert (location[3]), 1), IndexerDeclaration.Roles.RBrace);
625
if (location != null)
626
newIndexer.AddChild (new CSharpTokenNode (Convert (location[3]), 1), IndexerDeclaration.Roles.RBrace);
373
typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.Roles.Member);
628
typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.MemberRole);
376
631
public override void Visit (Method m)
378
633
MethodDeclaration newMethod = new MethodDeclaration ();
380
LocationDescriptor location = LocationStorage.Get (m);
635
var location = LocationsBag.GetMemberLocation (m);
381
636
AddModifiers (newMethod, location);
383
newMethod.AddChild ((INode)m.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
384
newMethod.AddChild (new Identifier (m.Name, Convert (m.Location)), AbstractNode.Roles.Identifier);
638
newMethod.AddChild (ConvertToType (m.TypeName), AstNode.Roles.Type);
639
newMethod.AddChild (CreateIdentifier (m.Name, Convert (m.Location)), AstNode.Roles.Identifier);
386
641
if (m.MemberName.TypeArguments != null) {
387
LocationDescriptor typeArgLocation = LocationStorage.Get (m.MemberName);
388
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
389
AddTypeArguments (newMethod, typeArgLocation, m.MemberName.TypeArguments);
390
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
642
var typeArgLocation = LocationsBag.GetLocations (m.MemberName);
643
if (typeArgLocation != null)
644
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
645
AddTypeParameters (newMethod, typeArgLocation, m.MemberName.TypeArguments);
646
if (typeArgLocation != null)
647
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
392
649
AddConstraints (newMethod, m.GenericMethod);
395
newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
652
if (location != null)
653
newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
397
654
AddParameter (newMethod, m.ParameterInfo);
399
newMethod.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
402
newMethod.AddChild ((INode)m.Block.Accept (this), MethodDeclaration.Roles.Body);
403
typeStack.Peek ().AddChild (newMethod, TypeDeclaration.Roles.Member);
656
if (location != null)
657
newMethod.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
658
if (m.Block != null) {
659
var bodyBlock = (BlockStatement)m.Block.Accept (this);
660
// if (m.Block is ToplevelBlock) {
661
// newMethod.AddChild (bodyBlock.FirstChild.NextSibling, MethodDeclaration.Roles.Body);
663
newMethod.AddChild (bodyBlock, MethodDeclaration.Roles.Body);
666
typeStack.Peek ().AddChild (newMethod, TypeDeclaration.MemberRole);
406
669
static Dictionary<Mono.CSharp.Modifiers, MonoDevelop.Projects.Dom.Modifiers> modifierTable = new Dictionary<Mono.CSharp.Modifiers, MonoDevelop.Projects.Dom.Modifiers> ();
670
static string[] keywordTable;
407
672
static ConversionVisitor ()
409
modifierTable[Mono.CSharp.Modifiers.NEW] = MonoDevelop.Projects.Dom.Modifiers.New;
410
modifierTable[Mono.CSharp.Modifiers.PUBLIC] = MonoDevelop.Projects.Dom.Modifiers.Public;
411
modifierTable[Mono.CSharp.Modifiers.PROTECTED] = MonoDevelop.Projects.Dom.Modifiers.Protected;
412
modifierTable[Mono.CSharp.Modifiers.PRIVATE] = MonoDevelop.Projects.Dom.Modifiers.Private;
413
modifierTable[Mono.CSharp.Modifiers.INTERNAL] = MonoDevelop.Projects.Dom.Modifiers.Internal;
414
modifierTable[Mono.CSharp.Modifiers.ABSTRACT] = MonoDevelop.Projects.Dom.Modifiers.Abstract;
415
modifierTable[Mono.CSharp.Modifiers.VIRTUAL] = MonoDevelop.Projects.Dom.Modifiers.Virtual;
416
modifierTable[Mono.CSharp.Modifiers.SEALED] = MonoDevelop.Projects.Dom.Modifiers.Sealed;
417
modifierTable[Mono.CSharp.Modifiers.STATIC] = MonoDevelop.Projects.Dom.Modifiers.Static;
418
modifierTable[Mono.CSharp.Modifiers.OVERRIDE] = MonoDevelop.Projects.Dom.Modifiers.Override;
419
modifierTable[Mono.CSharp.Modifiers.READONLY] = MonoDevelop.Projects.Dom.Modifiers.Readonly;
420
// modifierTable[Mono.CSharp.Modifiers.] = MonoDevelop.Projects.Dom.Modifiers.Const;
421
modifierTable[Mono.CSharp.Modifiers.PARTIAL] = MonoDevelop.Projects.Dom.Modifiers.Partial;
422
modifierTable[Mono.CSharp.Modifiers.EXTERN] = MonoDevelop.Projects.Dom.Modifiers.Extern;
423
modifierTable[Mono.CSharp.Modifiers.VOLATILE] = MonoDevelop.Projects.Dom.Modifiers.Volatile;
424
modifierTable[Mono.CSharp.Modifiers.UNSAFE] = MonoDevelop.Projects.Dom.Modifiers.Unsafe;
425
modifierTable[Mono.CSharp.Modifiers.OVERRIDE] = MonoDevelop.Projects.Dom.Modifiers.Overloads;
674
modifierTable [Mono.CSharp.Modifiers.NEW] = MonoDevelop.Projects.Dom.Modifiers.New;
675
modifierTable [Mono.CSharp.Modifiers.PUBLIC] = MonoDevelop.Projects.Dom.Modifiers.Public;
676
modifierTable [Mono.CSharp.Modifiers.PROTECTED] = MonoDevelop.Projects.Dom.Modifiers.Protected;
677
modifierTable [Mono.CSharp.Modifiers.PRIVATE] = MonoDevelop.Projects.Dom.Modifiers.Private;
678
modifierTable [Mono.CSharp.Modifiers.INTERNAL] = MonoDevelop.Projects.Dom.Modifiers.Internal;
679
modifierTable [Mono.CSharp.Modifiers.ABSTRACT] = MonoDevelop.Projects.Dom.Modifiers.Abstract;
680
modifierTable [Mono.CSharp.Modifiers.VIRTUAL] = MonoDevelop.Projects.Dom.Modifiers.Virtual;
681
modifierTable [Mono.CSharp.Modifiers.SEALED] = MonoDevelop.Projects.Dom.Modifiers.Sealed;
682
modifierTable [Mono.CSharp.Modifiers.STATIC] = MonoDevelop.Projects.Dom.Modifiers.Static;
683
modifierTable [Mono.CSharp.Modifiers.OVERRIDE] = MonoDevelop.Projects.Dom.Modifiers.Override;
684
modifierTable [Mono.CSharp.Modifiers.READONLY] = MonoDevelop.Projects.Dom.Modifiers.Readonly;
685
// modifierTable[Mono.CSharp.Modifiers.] = Modifiers.Const;
686
modifierTable [Mono.CSharp.Modifiers.PARTIAL] = MonoDevelop.Projects.Dom.Modifiers.Partial;
687
modifierTable [Mono.CSharp.Modifiers.EXTERN] = MonoDevelop.Projects.Dom.Modifiers.Extern;
688
modifierTable [Mono.CSharp.Modifiers.VOLATILE] = MonoDevelop.Projects.Dom.Modifiers.Volatile;
689
modifierTable [Mono.CSharp.Modifiers.UNSAFE] = MonoDevelop.Projects.Dom.Modifiers.Unsafe;
691
keywordTable = new string[255];
692
for (int i = 0; i< keywordTable.Length; i++)
693
keywordTable [i] = "unknown";
695
keywordTable [(int)BuiltinTypeSpec.Type.Other] = "void";
696
keywordTable [(int)BuiltinTypeSpec.Type.String] = "string";
697
keywordTable [(int)BuiltinTypeSpec.Type.Int] = "int";
698
keywordTable [(int)BuiltinTypeSpec.Type.Object] = "object";
699
keywordTable [(int)BuiltinTypeSpec.Type.Float] = "float";
700
keywordTable [(int)BuiltinTypeSpec.Type.Double] = "double";
701
keywordTable [(int)BuiltinTypeSpec.Type.Long] = "long";
702
keywordTable [(int)BuiltinTypeSpec.Type.Byte] = "byte";
703
keywordTable [(int)BuiltinTypeSpec.Type.UInt] = "uint";
704
keywordTable [(int)BuiltinTypeSpec.Type.ULong] = "ulong";
705
keywordTable [(int)BuiltinTypeSpec.Type.Short] = "short";
706
keywordTable [(int)BuiltinTypeSpec.Type.UShort] = "ushort";
707
keywordTable [(int)BuiltinTypeSpec.Type.SByte] = "sbyte";
708
keywordTable [(int)BuiltinTypeSpec.Type.Decimal] = "decimal";
709
keywordTable [(int)BuiltinTypeSpec.Type.Char] = "char";
428
void AddModifiers (AbstractNode parent, Mono.CSharp.LocationDescriptor location)
712
void AddModifiers (AttributedNode parent, LocationsBag.MemberLocations location)
430
if (location.Modifiers == null)
714
if (location == null || location.Modifiers == null)
432
716
foreach (var modifier in location.Modifiers) {
433
parent.AddChild (new CSharpModifierToken (Convert (modifier.Item1), modifierTable[modifier.Item2]), AbstractNode.Roles.Modifier);
717
parent.AddChild (new CSharpModifierToken (Convert (modifier.Item2), modifierTable[modifier.Item1]), AttributedNode.ModifierRole);
439
723
PropertyDeclaration newProperty = new PropertyDeclaration ();
441
LocationDescriptor location = LocationStorage.Get (p);
725
var location = LocationsBag.GetMemberLocation (p);
442
726
AddModifiers (newProperty, location);
444
newProperty.AddChild ((INode)p.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
445
newProperty.AddChild (new Identifier (p.MemberName.Name, Convert (p.MemberName.Location)), AbstractNode.Roles.Identifier);
446
newProperty.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LBrace);
727
newProperty.AddChild (ConvertToType (p.TypeName), AstNode.Roles.Type);
728
newProperty.AddChild (CreateIdentifier (p.MemberName.Name, Convert (p.MemberName.Location)), AstNode.Roles.Identifier);
729
if (location != null)
730
newProperty.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LBrace);
448
732
if (p.Get != null) {
449
MonoDevelop.CSharp.Dom.Accessor getAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
450
LocationDescriptor getLocation = LocationStorage.Get (p.Get);
733
Accessor getAccessor = new Accessor ();
734
var getLocation = LocationsBag.GetMemberLocation (p.Get);
451
735
AddModifiers (getAccessor, getLocation);
452
getAccessor.AddChild (new CSharpTokenNode (Convert (getLocation[0]), "get".Length), PropertyDeclaration.Roles.Keyword);
736
getAccessor.AddChild (new CSharpTokenNode (Convert (p.Get.Location), "get".Length), PropertyDeclaration.Roles.Keyword);
454
if (p.Get.Block != null)
455
getAccessor.AddChild ((INode)p.Get.Block.Accept (this), MethodDeclaration.Roles.Body);
456
newProperty.AddChild (getAccessor, PropertyDeclaration.PropertyGetRole);
738
if (p.Get.Block != null) {
739
getAccessor.AddChild ((BlockStatement)p.Get.Block.Accept (this), MethodDeclaration.Roles.Body);
741
if (getLocation != null && getLocation.Count > 0)
742
newProperty.AddChild (new CSharpTokenNode (Convert (getLocation[0]), 1), MethodDeclaration.Roles.Semicolon);
744
newProperty.AddChild (getAccessor, PropertyDeclaration.GetterRole);
459
747
if (p.Set != null) {
460
MonoDevelop.CSharp.Dom.Accessor setAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
461
LocationDescriptor setLocation = LocationStorage.Get (p.Set);
748
Accessor setAccessor = new Accessor ();
749
var setLocation = LocationsBag.GetMemberLocation (p.Set);
462
750
AddModifiers (setAccessor, setLocation);
463
setAccessor.AddChild (new CSharpTokenNode (Convert (setLocation[0]), "set".Length), PropertyDeclaration.Roles.Keyword);
751
setAccessor.AddChild (new CSharpTokenNode (Convert (p.Set.Location), "set".Length), PropertyDeclaration.Roles.Keyword);
465
if (p.Set.Block != null)
466
setAccessor.AddChild ((INode)p.Set.Block.Accept (this), MethodDeclaration.Roles.Body);
467
newProperty.AddChild (setAccessor, PropertyDeclaration.PropertySetRole);
753
if (p.Set.Block != null) {
754
setAccessor.AddChild ((BlockStatement)p.Set.Block.Accept (this), MethodDeclaration.Roles.Body);
756
if (setLocation != null && setLocation.Count > 0)
757
newProperty.AddChild (new CSharpTokenNode (Convert (setLocation[0]), 1), MethodDeclaration.Roles.Semicolon);
759
newProperty.AddChild (setAccessor, PropertyDeclaration.SetterRole);
469
newProperty.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RBrace);
761
if (location != null)
762
newProperty.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RBrace);
471
typeStack.Peek ().AddChild (newProperty, TypeDeclaration.Roles.Member);
764
typeStack.Peek ().AddChild (newProperty, TypeDeclaration.MemberRole);
474
767
public override void Visit (Constructor c)
476
769
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
477
LocationDescriptor location = LocationStorage.Get (c);
770
var location = LocationsBag.GetMemberLocation (c);
478
771
AddModifiers (newConstructor, location);
479
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
480
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
772
newConstructor.AddChild (CreateIdentifier (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
773
if (location != null)
774
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
776
AddParameter (newConstructor, c.ParameterInfo);
777
if (location != null)
778
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
482
780
if (c.Block != null)
483
newConstructor.AddChild ((INode)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
781
newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
485
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.Roles.Member);
783
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole);
488
786
public override void Visit (Destructor d)
490
788
DestructorDeclaration newDestructor = new DestructorDeclaration ();
491
LocationDescriptor location = LocationStorage.Get (d);
789
var location = LocationsBag.GetMemberLocation (d);
492
790
AddModifiers (newDestructor, location);
493
newDestructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
494
newDestructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
791
if (location != null)
792
newDestructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), DestructorDeclaration.TildeRole);
793
newDestructor.AddChild (CreateIdentifier (d.MemberName.Name, Convert (d.MemberName.Location)), AstNode.Roles.Identifier);
795
if (location != null) {
796
newDestructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DestructorDeclaration.Roles.LPar);
797
newDestructor.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DestructorDeclaration.Roles.RPar);
496
800
if (d.Block != null)
497
newDestructor.AddChild ((INode)d.Block.Accept (this), DestructorDeclaration.Roles.Body);
801
newDestructor.AddChild ((BlockStatement)d.Block.Accept (this), DestructorDeclaration.Roles.Body);
499
typeStack.Peek ().AddChild (newDestructor, TypeDeclaration.Roles.Member);
803
typeStack.Peek ().AddChild (newDestructor, TypeDeclaration.MemberRole);
502
806
public override void Visit (EventField e)
504
808
EventDeclaration newEvent = new EventDeclaration ();
506
LocationDescriptor location = LocationStorage.Get (e);
810
var location = LocationsBag.GetMemberLocation (e);
507
811
AddModifiers (newEvent, location);
509
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword);
510
newEvent.AddChild ((INode)e.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
511
newEvent.AddChild (new Identifier (e.MemberName.Name, Convert (e.MemberName.Location)), EventDeclaration.Roles.Identifier);
512
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), EventDeclaration.Roles.Semicolon);
813
if (location != null)
814
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword);
815
newEvent.AddChild (ConvertToType (e.TypeName), AstNode.Roles.Type);
816
newEvent.AddChild (CreateIdentifier (e.MemberName.Name, Convert (e.MemberName.Location)), EventDeclaration.Roles.Identifier);
817
if (location != null)
818
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), EventDeclaration.Roles.Semicolon);
514
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.Roles.Member);
820
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole);
517
823
public override void Visit (EventProperty ep)
519
EventDeclaration newEvent = new EventDeclaration ();
825
CustomEventDeclaration newEvent = new CustomEventDeclaration ();
521
LocationDescriptor location = LocationStorage.Get (ep);
827
var location = LocationsBag.GetMemberLocation (ep);
522
828
AddModifiers (newEvent, location);
524
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword);
525
newEvent.AddChild ((INode)ep.TypeName.Accept (this), EventDeclaration.Roles.ReturnType);
526
newEvent.AddChild (new Identifier (ep.MemberName.Name, Convert (ep.MemberName.Location)), EventDeclaration.Roles.Identifier);
527
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), EventDeclaration.Roles.LBrace);
830
if (location != null)
831
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), CustomEventDeclaration.Roles.Keyword);
832
newEvent.AddChild (ConvertToType (ep.TypeName), CustomEventDeclaration.Roles.Type);
833
newEvent.AddChild (CreateIdentifier (ep.MemberName.Name, Convert (ep.MemberName.Location)), CustomEventDeclaration.Roles.Identifier);
834
if (location != null && location.Count >= 2)
835
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CustomEventDeclaration.Roles.LBrace);
529
837
if (ep.Add != null) {
530
MonoDevelop.CSharp.Dom.Accessor addAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
531
LocationDescriptor addLocation = LocationStorage.Get (ep.Add);
838
Accessor addAccessor = new Accessor ();
839
var addLocation = LocationsBag.GetMemberLocation (ep.Add);
532
840
AddModifiers (addAccessor, addLocation);
533
addAccessor.AddChild (new CSharpTokenNode (Convert (addLocation[0]), "add".Length), EventDeclaration.Roles.Keyword);
841
addAccessor.AddChild (new CSharpTokenNode (Convert (ep.Add.Location), "add".Length), CustomEventDeclaration.Roles.Keyword);
534
842
if (ep.Add.Block != null)
535
addAccessor.AddChild ((INode)ep.Add.Block.Accept (this), EventDeclaration.Roles.Body);
536
newEvent.AddChild (addAccessor, EventDeclaration.EventAddRole);
843
addAccessor.AddChild ((BlockStatement)ep.Add.Block.Accept (this), CustomEventDeclaration.Roles.Body);
844
newEvent.AddChild (addAccessor, CustomEventDeclaration.AddAccessorRole);
539
847
if (ep.Remove != null) {
540
MonoDevelop.CSharp.Dom.Accessor removeAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
541
LocationDescriptor removeLocation = LocationStorage.Get (ep.Remove);
848
Accessor removeAccessor = new Accessor ();
849
var removeLocation = LocationsBag.GetMemberLocation (ep.Remove);
542
850
AddModifiers (removeAccessor, removeLocation);
543
removeAccessor.AddChild (new CSharpTokenNode (Convert (removeLocation[0]), "remove".Length), EventDeclaration.Roles.Keyword);
851
removeAccessor.AddChild (new CSharpTokenNode (Convert (ep.Remove.Location), "remove".Length), CustomEventDeclaration.Roles.Keyword);
545
853
if (ep.Remove.Block != null)
546
removeAccessor.AddChild ((INode)ep.Remove.Block.Accept (this), EventDeclaration.Roles.Body);
547
newEvent.AddChild (removeAccessor, EventDeclaration.EventRemoveRole);
854
removeAccessor.AddChild ((BlockStatement)ep.Remove.Block.Accept (this), CustomEventDeclaration.Roles.Body);
855
newEvent.AddChild (removeAccessor, CustomEventDeclaration.RemoveAccessorRole);
549
newEvent.AddChild (new CSharpTokenNode (Convert (location[2]), 1), EventDeclaration.Roles.RBrace);
857
if (location != null && location.Count >= 3)
858
newEvent.AddChild (new CSharpTokenNode (Convert (location[2]), 1), CustomEventDeclaration.Roles.RBrace);
551
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.Roles.Member);
860
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole);
556
865
#region Statements
557
public override object Visit (Statement stmt)
866
public override object Visit (Mono.CSharp.Statement stmt)
559
868
Console.WriteLine ("unknown statement:" + stmt);
872
public override object Visit (BlockVariableDeclaration blockVariableDeclaration)
874
var result = new VariableDeclarationStatement ();
875
result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), VariableDeclarationStatement.Roles.Type);
877
var varInit = new VariableInitializer ();
878
var location = LocationsBag.GetLocations (blockVariableDeclaration);
879
varInit.AddChild (CreateIdentifier (blockVariableDeclaration.Variable.Name, Convert (blockVariableDeclaration.Variable.Location)), VariableInitializer.Roles.Identifier);
880
if (blockVariableDeclaration.Initializer != null) {
881
if (location != null)
882
varInit.AddChild (new CSharpTokenNode (Convert (location[0]), 1), VariableInitializer.Roles.Assign);
883
varInit.AddChild ((MonoDevelop.CSharp.Ast.Expression)blockVariableDeclaration.Initializer.Accept (this), VariableInitializer.Roles.Expression);
886
result.AddChild (varInit, VariableDeclarationStatement.Roles.Variable);
888
if (blockVariableDeclaration.Declarators != null) {
889
foreach (var decl in blockVariableDeclaration.Declarators) {
890
var loc = LocationsBag.GetLocations (decl);
891
var init = new VariableInitializer ();
892
if (loc != null && loc.Count > 0)
893
result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), VariableInitializer.Roles.Comma);
894
init.AddChild (CreateIdentifier (decl.Variable.Name, Convert (decl.Variable.Location)), VariableInitializer.Roles.Identifier);
895
if (decl.Initializer != null) {
896
if (loc != null && loc.Count > 1)
897
result.AddChild (new CSharpTokenNode (Convert (loc [1]), 1), VariableInitializer.Roles.Assign);
898
init.AddChild ((MonoDevelop.CSharp.Ast.Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
901
result.AddChild (init, VariableDeclarationStatement.Roles.Variable);
904
if (location != null)
905
result.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), 1), VariableDeclarationStatement.Roles.Semicolon);
909
public override object Visit (BlockConstantDeclaration blockVariableDeclaration)
911
var result = new VariableDeclarationStatement ();
913
var location = LocationsBag.GetLocations (blockVariableDeclaration);
914
if (location != null)
915
result.AddChild (new CSharpModifierToken (Convert (location [0]), MonoDevelop.Projects.Dom.Modifiers.Const), VariableDeclarationStatement.ModifierRole);
917
result.AddChild (ConvertToType (blockVariableDeclaration.TypeExpression), VariableDeclarationStatement.Roles.Type);
919
var varInit = new VariableInitializer ();
920
varInit.AddChild (CreateIdentifier (blockVariableDeclaration.Variable.Name, Convert (blockVariableDeclaration.Variable.Location)), VariableInitializer.Roles.Identifier);
921
if (blockVariableDeclaration.Initializer != null) {
922
if (location != null)
923
varInit.AddChild (new CSharpTokenNode (Convert (location[1]), 1), VariableInitializer.Roles.Assign);
924
varInit.AddChild ((MonoDevelop.CSharp.Ast.Expression)blockVariableDeclaration.Initializer.Accept (this), VariableInitializer.Roles.Expression);
927
result.AddChild (varInit, VariableDeclarationStatement.Roles.Variable);
929
if (blockVariableDeclaration.Declarators != null) {
930
foreach (var decl in blockVariableDeclaration.Declarators) {
931
var loc = LocationsBag.GetLocations (decl);
932
var init = new VariableInitializer ();
933
init.AddChild (CreateIdentifier (decl.Variable.Name, Convert (decl.Variable.Location)), VariableInitializer.Roles.Identifier);
934
if (decl.Initializer != null) {
936
init.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), VariableInitializer.Roles.Assign);
937
init.AddChild ((MonoDevelop.CSharp.Ast.Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
938
if (loc != null && loc.Count > 1)
939
result.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), VariableInitializer.Roles.Comma);
941
if (loc != null && loc.Count > 0)
942
result.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), VariableInitializer.Roles.Comma);
944
result.AddChild (init, VariableDeclarationStatement.Roles.Variable);
947
if (location != null)
948
result.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), 1), VariableDeclarationStatement.Roles.Semicolon);
563
952
public override object Visit (Mono.CSharp.EmptyStatement emptyStatement)
565
var result = new MonoDevelop.CSharp.Dom.EmptyStatement ();
954
var result = new MonoDevelop.CSharp.Ast.EmptyStatement ();
566
955
result.Location = Convert (emptyStatement.loc);
570
959
public override object Visit (EmptyExpressionStatement emptyExpressionStatement)
572
// indicates an error
573
return new MonoDevelop.CSharp.Dom.EmptyStatement ();
961
return new MonoDevelop.CSharp.Ast.EmptyExpression (Convert (emptyExpressionStatement.Location));
577
964
public override object Visit (If ifStatement)
579
966
var result = new IfElseStatement ();
581
LocationDescriptor location = LocationStorage.Get (ifStatement);
583
result.AddChild (new CSharpTokenNode (Convert (location[2]), "if".Length), IfElseStatement.IfKeywordRole);
584
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IfElseStatement.Roles.LPar);
585
result.AddChild ((INode)ifStatement.Expr.Accept (this), IfElseStatement.Roles.Condition);
586
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IfElseStatement.Roles.RPar);
588
result.AddChild ((INode)ifStatement.TrueStatement.Accept (this), IfElseStatement.TrueEmbeddedStatementRole);
968
var location = LocationsBag.GetLocations (ifStatement);
970
result.AddChild (new CSharpTokenNode (Convert (ifStatement.loc), "if".Length), IfElseStatement.IfKeywordRole);
971
if (location != null)
972
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IfElseStatement.Roles.LPar);
973
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)ifStatement.Expr.Accept (this), IfElseStatement.Roles.Condition);
974
if (location != null)
975
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IfElseStatement.Roles.RPar);
977
if (ifStatement.TrueStatement != null)
978
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)ifStatement.TrueStatement.Accept (this), IfElseStatement.TrueRole);
590
980
if (ifStatement.FalseStatement != null) {
591
result.AddChild (new CSharpTokenNode (Convert (location[3]), "else".Length), IfElseStatement.ElseKeywordRole);
592
result.AddChild ((INode)ifStatement.FalseStatement.Accept (this), IfElseStatement.FalseEmbeddedStatementRole);
981
if (location != null)
982
result.AddChild (new CSharpTokenNode (Convert (location[2]), "else".Length), IfElseStatement.ElseKeywordRole);
983
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)ifStatement.FalseStatement.Accept (this), IfElseStatement.FalseRole);
598
989
public override object Visit (Do doStatement)
600
var result = new WhileStatement (WhilePosition.End);
601
LocationDescriptor location = LocationStorage.Get (doStatement);
602
result.AddChild (new CSharpTokenNode (Convert (location[2]), "do".Length), WhileStatement.DoKeywordRole);
603
result.AddChild ((INode)doStatement.EmbeddedStatement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
604
result.AddChild (new CSharpTokenNode (Convert (location[3]), "while".Length), WhileStatement.WhileKeywordRole);
605
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), WhileStatement.Roles.LPar);
606
result.AddChild ((INode)doStatement.expr.Accept (this), WhileStatement.Roles.Condition);
607
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), WhileStatement.Roles.RPar);
608
result.AddChild (new CSharpTokenNode (Convert (location[4]), 1), WhileStatement.Roles.Semicolon);
991
var result = new DoWhileStatement ();
992
var location = LocationsBag.GetLocations (doStatement);
993
result.AddChild (new CSharpTokenNode (Convert (doStatement.loc), "do".Length), DoWhileStatement.DoKeywordRole);
994
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)doStatement.EmbeddedStatement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
995
if (location != null)
996
result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), DoWhileStatement.WhileKeywordRole);
997
if (location != null)
998
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DoWhileStatement.Roles.LPar);
999
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition);
1000
if (location != null) {
1001
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DoWhileStatement.Roles.RPar);
1002
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DoWhileStatement.Roles.Semicolon);
613
1008
public override object Visit (While whileStatement)
615
var result = new WhileStatement (WhilePosition.Begin);
616
LocationDescriptor location = LocationStorage.Get (whileStatement);
617
result.AddChild (new CSharpTokenNode (Convert (location[2]), "while".Length), WhileStatement.WhileKeywordRole);
619
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), WhileStatement.Roles.LPar);
620
result.AddChild ((INode)whileStatement.expr.Accept (this), WhileStatement.Roles.Condition);
621
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), WhileStatement.Roles.RPar);
623
result.AddChild ((INode)whileStatement.Statement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
1010
var result = new WhileStatement ();
1011
var location = LocationsBag.GetLocations (whileStatement);
1012
result.AddChild (new CSharpTokenNode (Convert (whileStatement.loc), "while".Length), WhileStatement.WhileKeywordRole);
1014
if (location != null)
1015
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), WhileStatement.Roles.LPar);
1016
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)whileStatement.expr.Accept (this), WhileStatement.Roles.Condition);
1017
if (location != null)
1018
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), WhileStatement.Roles.RPar);
1019
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)whileStatement.Statement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
1024
void AddStatementOrList (ForStatement forStatement, Mono.CSharp.Statement init, Role<MonoDevelop.CSharp.Ast.Statement> role)
1028
if (init is StatementList) {
1029
foreach (var stmt in ((StatementList)init).Statements) {
1030
forStatement.AddChild ((MonoDevelop.CSharp.Ast.Statement)stmt.Accept (this), role);
1033
forStatement.AddChild ((MonoDevelop.CSharp.Ast.Statement)init.Accept (this), role);
628
1037
public override object Visit (For forStatement)
630
1039
var result = new ForStatement ();
632
LocationDescriptor location = LocationStorage.Get (forStatement);
634
result.AddChild (new CSharpTokenNode (Convert (location[2]), "for".Length), ForStatement.Roles.Keyword);
635
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ForStatement.Roles.LPar);
636
if (forStatement.InitStatement != null)
637
result.AddChild ((INode)forStatement.InitStatement.Accept (this), ForStatement.Roles.Initializer);
639
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), ForStatement.Roles.Semicolon);
1041
var location = LocationsBag.GetLocations (forStatement);
1043
result.AddChild (new CSharpTokenNode (Convert (forStatement.loc), "for".Length), ForStatement.Roles.Keyword);
1044
if (location != null)
1045
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ForStatement.Roles.LPar);
1047
AddStatementOrList (result, forStatement.InitStatement, ForStatement.InitializerRole);
1049
if (location != null)
1050
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ForStatement.Roles.Semicolon);
640
1051
if (forStatement.Test != null)
641
result.AddChild ((INode)forStatement.Test.Accept (this), ForStatement.Roles.Condition);
642
result.AddChild (new CSharpTokenNode (Convert (location[4]), 1), ForStatement.Roles.Semicolon);
643
if (forStatement.Increment != null)
644
result.AddChild ((INode)forStatement.Increment.Accept (this), ForStatement.Roles.Iterator);
645
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ForStatement.Roles.RPar);
647
result.AddChild ((INode)forStatement.Statement.Accept (this), ForStatement.Roles.EmbeddedStatement);
1052
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)forStatement.Test.Accept (this), ForStatement.Roles.Condition);
1053
if (location != null)
1054
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), ForStatement.Roles.Semicolon);
1056
AddStatementOrList (result, forStatement.Increment, ForStatement.IteratorRole);
1058
if (location != null)
1059
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), ForStatement.Roles.RPar);
1061
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)forStatement.Statement.Accept (this), ForStatement.Roles.EmbeddedStatement);
652
1066
public override object Visit (StatementExpression statementExpression)
654
var result = new MonoDevelop.CSharp.Dom.ExpressionStatement ();
655
LocationDescriptor location = LocationStorage.Get (statementExpression);
657
result.AddChild ((INode)statementExpression.Expr.Accept (this), MonoDevelop.CSharp.Dom.ExpressionStatement.Roles.Expression);
658
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MonoDevelop.CSharp.Dom.ExpressionStatement.Roles.Semicolon);
1068
var result = new MonoDevelop.CSharp.Ast.ExpressionStatement ();
1069
object expr = statementExpression.Expr.Accept (this);
1070
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)expr, MonoDevelop.CSharp.Ast.ExpressionStatement.Roles.Expression);
1071
var location = LocationsBag.GetLocations (statementExpression);
1072
if (location != null)
1073
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MonoDevelop.CSharp.Ast.ExpressionStatement.Roles.Semicolon);
662
1077
public override object Visit (Return returnStatement)
664
1079
var result = new ReturnStatement ();
665
LocationDescriptor location = LocationStorage.Get (returnStatement);
667
result.AddChild (new CSharpTokenNode (Convert (location[1]), "return".Length), ReturnStatement.Roles.Keyword);
1081
result.AddChild (new CSharpTokenNode (Convert (returnStatement.loc), "return".Length), ReturnStatement.Roles.Keyword);
668
1082
if (returnStatement.Expr != null)
669
result.AddChild ((INode)returnStatement.Expr.Accept (this), ReturnStatement.Roles.Expression);
670
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ReturnStatement.Roles.Semicolon);
1083
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)returnStatement.Expr.Accept (this), ReturnStatement.Roles.Expression);
1085
var location = LocationsBag.GetLocations (returnStatement);
1086
if (location != null)
1087
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ReturnStatement.Roles.Semicolon);
675
1092
public override object Visit (Goto gotoStatement)
677
var result = new GotoStatement (GotoType.Label);
678
LocationDescriptor location = LocationStorage.Get (gotoStatement);
680
result.AddChild (new CSharpTokenNode (Convert (location[1]), "goto".Length), GotoStatement.Roles.Keyword);
681
result.AddChild (new Identifier (gotoStatement.Target, Convert (gotoStatement.loc)), GotoStatement.Roles.Identifier);
682
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), GotoStatement.Roles.Semicolon);
1094
var result = new GotoStatement ();
1095
var location = LocationsBag.GetLocations (gotoStatement);
1096
result.AddChild (new CSharpTokenNode (Convert (gotoStatement.loc), "goto".Length), GotoStatement.Roles.Keyword);
1097
result.AddChild (CreateIdentifier (gotoStatement.Target, Convert (gotoStatement.loc)), GotoStatement.Roles.Identifier);
1098
if (location != null)
1099
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), GotoStatement.Roles.Semicolon);
752
1174
return left.Row < right.Row || left.Row == right.Row && left.Column < right.Column;
1177
public UsingStatement CreateUsingStatement (Block blockStatement)
1179
var usingResult = new UsingStatement ();
1180
Mono.CSharp.Statement cur = blockStatement.Statements[0];
1182
Using u = (Using)cur;
1183
usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword);
1184
usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar);
1185
if (u.Variables != null) {
1186
usingResult.AddChild (ConvertToType (u.Variables.TypeExpression), UsingStatement.Roles.Type);
1187
usingResult.AddChild (CreateIdentifier (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)), UsingStatement.Roles.Identifier);
1188
var loc = LocationsBag.GetLocations (u.Variables);
1190
usingResult.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), ContinueStatement.Roles.Assign);
1191
if (u.Variables.Initializer != null)
1192
usingResult.AddChild ((AstNode)u.Variables.Initializer.Accept (this), UsingStatement.ResourceAcquisitionRole);
1196
usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), UsingStatement.Roles.RPar);
1197
usingResult.AddChild ((MonoDevelop.CSharp.Ast.Statement)cur.Accept (this), UsingStatement.Roles.EmbeddedStatement);
1202
void AddBlockChildren (BlockStatement result, Block blockStatement, ref int curLocal)
1204
foreach (Mono.CSharp.Statement stmt in blockStatement.Statements) {
1207
/* if (curLocal < localVariables.Count && IsLower (localVariables[curLocal].Location, stmt.loc)) {
1208
result.AddChild (CreateVariableDeclaration (localVariables[curLocal]), AstNode.Roles.Statement);
1211
if (stmt is Block && !(stmt is ToplevelBlock || stmt is ExplicitBlock)) {
1212
AddBlockChildren (result, (Block)stmt, ref curLocal);
1214
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)stmt.Accept (this), BlockStatement.StatementRole);
754
1219
public override object Visit (Block blockStatement)
756
if (blockStatement.IsGenerated)
1221
if (blockStatement.IsCompilerGenerated && blockStatement.Statements.Any ()) {
1222
if (blockStatement.Statements.First () is Using)
1223
return CreateUsingStatement (blockStatement);
757
1224
return blockStatement.Statements.Last ().Accept (this);
758
1226
var result = new BlockStatement ();
759
result.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), AbstractCSharpNode.Roles.LBrace);
1227
result.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), AstNode.Roles.LBrace);
760
1228
int curLocal = 0;
761
List<LocalInfo> localVariables = new List<LocalInfo> (blockStatement.Variables.Values);
762
foreach (Statement stmt in blockStatement.Statements) {
763
if (curLocal < localVariables.Count && IsLower (localVariables[curLocal].Location, stmt.loc)) {
764
result.AddChild (CreateVariableDeclaration (localVariables[curLocal]), AbstractCSharpNode.Roles.Statement);
767
result.AddChild ((INode)stmt.Accept (this), AbstractCSharpNode.Roles.Statement);
770
while (curLocal < localVariables.Count) {
771
result.AddChild (CreateVariableDeclaration (localVariables[curLocal]), AbstractCSharpNode.Roles.Statement);
775
result.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), AbstractCSharpNode.Roles.RBrace);
780
VariableDeclarationStatement CreateVariableDeclaration (LocalInfo info)
782
VariableDeclarationStatement result = new VariableDeclarationStatement ();
783
result.AddChild ((INode)info.Type.Accept (this), CatchClause.Roles.ReturnType);
784
VariableInitializer variable = new VariableInitializer ();
785
variable.AddChild (new Identifier (info.Name, Convert (info.Location)), AbstractNode.Roles.Identifier);
786
result.AddChild (variable, AbstractNode.Roles.Initializer);
788
result.AddChild (new Identifier (info.Name, Convert (info.Location)), CatchClause.Roles.ReturnType);
1229
AddBlockChildren (result, blockStatement, ref curLocal);
1231
result.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), AstNode.Roles.RBrace);
792
1235
public override object Visit (Switch switchStatement)
794
1237
var result = new SwitchStatement ();
796
LocationDescriptor location = LocationStorage.Get (switchStatement);
797
result.AddChild (new CSharpTokenNode (Convert (location[2]), "switch".Length), SwitchStatement.Roles.Keyword);
798
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), SwitchStatement.Roles.LPar);
799
result.AddChild ((INode)switchStatement.Expr.Accept (this), SwitchStatement.Roles.Expression);
800
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), SwitchStatement.Roles.RPar);
802
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), SwitchStatement.Roles.LBrace);
1239
var location = LocationsBag.GetLocations (switchStatement);
1240
result.AddChild (new CSharpTokenNode (Convert (switchStatement.loc), "switch".Length), SwitchStatement.Roles.Keyword);
1241
if (location != null)
1242
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), SwitchStatement.Roles.LPar);
1243
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)switchStatement.Expr.Accept (this), SwitchStatement.Roles.Expression);
1244
if (location != null)
1245
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), SwitchStatement.Roles.RPar);
1246
if (location != null)
1247
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), SwitchStatement.Roles.LBrace);
803
1248
foreach (var section in switchStatement.Sections) {
804
var newSection = new MonoDevelop.CSharp.Dom.SwitchSection ();
1249
var newSection = new MonoDevelop.CSharp.Ast.SwitchSection ();
805
1250
foreach (var caseLabel in section.Labels) {
806
1251
var newLabel = new CaseLabel ();
807
1252
newLabel.AddChild (new CSharpTokenNode (Convert (caseLabel.Location), "case".Length), SwitchStatement.Roles.Keyword);
808
1253
if (caseLabel.Label != null)
809
newLabel.AddChild ((INode)caseLabel.Label.Accept (this), SwitchStatement.Roles.Expression);
811
newSection.AddChild (newLabel, MonoDevelop.CSharp.Dom.SwitchSection.CaseLabelRole);
813
newSection.AddChild ((INode)section.Block.Accept (this), MonoDevelop.CSharp.Dom.SwitchSection.Roles.Body);
1254
newLabel.AddChild ((MonoDevelop.CSharp.Ast.Expression)caseLabel.Label.Accept (this), SwitchStatement.Roles.Expression);
1256
newSection.AddChild (newLabel, MonoDevelop.CSharp.Ast.SwitchSection.CaseLabelRole);
1259
var blockStatement = section.Block;
1260
var bodyBlock = new BlockStatement ();
1262
AddBlockChildren (bodyBlock, blockStatement, ref curLocal);
1263
foreach (var statement in bodyBlock.Statements) {
1264
statement.Remove ();
1265
newSection.AddChild (statement, MonoDevelop.CSharp.Ast.SwitchSection.Roles.EmbeddedStatement);
814
1268
result.AddChild (newSection, SwitchStatement.SwitchSectionRole);
817
result.AddChild (new CSharpTokenNode (Convert (location[4]), 1), SwitchStatement.Roles.RBrace);
1271
if (location != null)
1272
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), SwitchStatement.Roles.RBrace);
821
1276
public override object Visit (Lock lockStatement)
823
1278
var result = new LockStatement ();
824
LocationDescriptor location = LocationStorage.Get (lockStatement);
825
result.AddChild (new CSharpTokenNode (Convert (location[2]), "lock".Length), LockStatement.Roles.Keyword);
827
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), LockStatement.Roles.LPar);
828
result.AddChild ((INode)lockStatement.Expr.Accept (this), LockStatement.Roles.Expression);
829
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), LockStatement.Roles.RPar);
830
result.AddChild ((INode)lockStatement.Statement.Accept (this), LockStatement.Roles.EmbeddedStatement);
1279
var location = LocationsBag.GetLocations (lockStatement);
1280
result.AddChild (new CSharpTokenNode (Convert (lockStatement.loc), "lock".Length), LockStatement.Roles.Keyword);
1282
if (location != null)
1283
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), LockStatement.Roles.LPar);
1284
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)lockStatement.Expr.Accept (this), LockStatement.Roles.Expression);
1286
if (location != null)
1287
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), LockStatement.Roles.RPar);
1288
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)lockStatement.Statement.Accept (this), LockStatement.Roles.EmbeddedStatement);
845
1302
public override object Visit (Checked checkedStatement)
847
1304
var result = new CheckedStatement ();
848
LocationDescriptor location = LocationStorage.Get (checkedStatement);
849
result.AddChild (new CSharpTokenNode (Convert (location[0]), "checked".Length), CheckedStatement.Roles.Keyword);
850
result.AddChild ((INode)checkedStatement.Block.Accept (this), CheckedStatement.Roles.EmbeddedStatement);
1305
result.AddChild (new CSharpTokenNode (Convert (checkedStatement.loc), "checked".Length), CheckedStatement.Roles.Keyword);
1306
result.AddChild ((BlockStatement)checkedStatement.Block.Accept (this), CheckedStatement.Roles.Body);
854
1310
public override object Visit (Unsafe unsafeStatement)
856
1312
var result = new UnsafeStatement ();
857
LocationDescriptor location = LocationStorage.Get (unsafeStatement);
858
result.AddChild (new CSharpTokenNode (Convert (location[0]), "unsafe".Length), UnsafeStatement.Roles.Keyword);
859
result.AddChild ((INode)unsafeStatement.Block.Accept (this), UnsafeStatement.Roles.Body);
1313
result.AddChild (new CSharpTokenNode (Convert (unsafeStatement.loc), "unsafe".Length), UnsafeStatement.Roles.Keyword);
1314
result.AddChild ((BlockStatement)unsafeStatement.Block.Accept (this), UnsafeStatement.Roles.Body);
863
1318
public override object Visit (Fixed fixedStatement)
865
1320
var result = new FixedStatement ();
866
LocationDescriptor location = LocationStorage.Get (fixedStatement);
868
result.AddChild (new CSharpTokenNode (Convert (location[2]), "fixed".Length), FixedStatement.FixedKeywordRole);
869
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FixedStatement.Roles.LPar);
871
result.AddChild ((INode)fixedStatement.Type.Accept (this), FixedStatement.PointerDeclarationRole);
873
foreach (KeyValuePair<LocalInfo, Expression> declarator in fixedStatement.Declarators) {
874
result.AddChild ((INode)declarator.Value.Accept (this), FixedStatement.DeclaratorRole);
1321
var location = LocationsBag.GetLocations (fixedStatement);
1323
result.AddChild (new CSharpTokenNode (Convert (fixedStatement.loc), "fixed".Length), FixedStatement.Roles.Keyword);
1324
if (location != null)
1325
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FixedStatement.Roles.LPar);
1327
if (fixedStatement.Variables != null) {
1328
// result.AddChild (ConvertToType (fixedStatement.Variables), UsingStatement.Roles.Type);
1329
result.AddChild (CreateIdentifier (fixedStatement.Variables.Variable.Name, Convert (fixedStatement.Variables.Variable.Location)), UsingStatement.Roles.Identifier);
1330
var loc = LocationsBag.GetLocations (fixedStatement.Variables);
1332
result.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), ContinueStatement.Roles.Assign);
1333
// if (fixedStatement.Variables.Initializer != null)
1334
// result.AddChild (fixedStatement.Variables.Initializer.Accept (this), UsingStatement.Roles.Variable);
876
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FixedStatement.Roles.RPar);
877
result.AddChild ((INode)fixedStatement.Statement.Accept (this), FixedStatement.Roles.EmbeddedStatement);
1337
if (location != null)
1338
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FixedStatement.Roles.RPar);
1339
result.AddChild ((MonoDevelop.CSharp.Ast.Statement)fixedStatement.Statement.Accept (this), FixedStatement.Roles.EmbeddedStatement);
881
1343
public override object Visit (TryFinally tryFinallyStatement)
883
1345
TryCatchStatement result;
884
LocationDescriptor location = LocationStorage.Get (tryFinallyStatement);
1346
var location = LocationsBag.GetLocations (tryFinallyStatement);
886
1348
if (tryFinallyStatement.Stmt is TryCatch) {
887
1349
result = (TryCatchStatement)tryFinallyStatement.Stmt.Accept (this);
889
1351
result = new TryCatchStatement ();
890
result.AddChild (new CSharpTokenNode (Convert (location[0]), "try".Length), TryCatchStatement.TryKeywordRole);
891
result.AddChild ((INode)tryFinallyStatement.Stmt.Accept (this), TryCatchStatement.TryBlockRole);
1352
result.AddChild (new CSharpTokenNode (Convert (tryFinallyStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole);
1353
result.AddChild ((BlockStatement)tryFinallyStatement.Stmt.Accept (this), TryCatchStatement.TryBlockRole);
894
result.AddChild (new CSharpTokenNode (Convert (location[1]), "finally".Length), TryCatchStatement.FinallyKeywordRole);
895
result.AddChild ((INode)tryFinallyStatement.Fini.Accept (this), TryCatchStatement.FinallyBlockRole);
1355
if (location != null)
1356
result.AddChild (new CSharpTokenNode (Convert (location[0]), "finally".Length), TryCatchStatement.FinallyKeywordRole);
1357
result.AddChild ((BlockStatement)tryFinallyStatement.Fini.Accept (this), TryCatchStatement.FinallyBlockRole);
900
CatchClause ConvertCatch (Catch ctch)
1362
CatchClause ConvertCatch (Catch ctch)
902
1364
CatchClause result = new CatchClause ();
903
LocationDescriptor location = LocationStorage.Get (ctch);
904
result.AddChild (new CSharpTokenNode (Convert (location[0]), "catch".Length), CatchClause.Roles.Keyword);
906
if (ctch.Type_expr != null) {
907
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), CatchClause.Roles.LPar);
909
result.AddChild ((INode)ctch.Type_expr.Accept (this), CatchClause.Roles.ReturnType);
910
if (!string.IsNullOrEmpty (ctch.Name))
911
result.AddChild (new Identifier (ctch.Name, Convert (location[1])), CatchClause.Roles.Identifier);
913
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), CatchClause.Roles.RPar);
1365
var location = LocationsBag.GetLocations (ctch);
1366
result.AddChild (new CSharpTokenNode (Convert (ctch.loc), "catch".Length), CatchClause.Roles.Keyword);
1367
if (ctch.TypeExpression != null) {
1368
if (location != null)
1369
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CatchClause.Roles.LPar);
1371
result.AddChild (ConvertToType (ctch.TypeExpression), CatchClause.Roles.Type);
1372
if (ctch.Variable != null && !string.IsNullOrEmpty (ctch.Variable.Name))
1373
result.AddChild (CreateIdentifier (ctch.Variable.Name, Convert (ctch.Variable.Location)), CatchClause.Roles.Identifier);
1375
if (location != null)
1376
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CatchClause.Roles.RPar);
916
result.AddChild ((INode)ctch.Block.Accept (this), CatchClause.Roles.Body);
1379
result.AddChild ((BlockStatement)ctch.Block.Accept (this), CatchClause.Roles.Body);
998
1444
public override object Visit (Yield yieldStatement)
1000
1446
var result = new YieldStatement ();
1001
LocationDescriptor location = LocationStorage.Get (yieldStatement);
1447
var location = LocationsBag.GetLocations (yieldStatement);
1003
result.AddChild (new CSharpTokenNode (Convert (location[0]), "yield".Length), YieldStatement.YieldKeywordRole);
1004
result.AddChild (new CSharpTokenNode (Convert (location[1]), "return".Length), YieldStatement.ReturnKeywordRole);
1449
result.AddChild (new CSharpTokenNode (Convert (yieldStatement.loc), "yield".Length), YieldStatement.YieldKeywordRole);
1450
if (location != null)
1451
result.AddChild (new CSharpTokenNode (Convert (location[0]), "return".Length), YieldStatement.ReturnKeywordRole);
1005
1452
if (yieldStatement.Expr != null)
1006
result.AddChild ((INode)yieldStatement.Expr.Accept (this), YieldStatement.Roles.Expression);
1007
result.AddChild (new CSharpTokenNode (Convert (location[2]), ";".Length), YieldStatement.Roles.Semicolon);
1453
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)yieldStatement.Expr.Accept (this), YieldStatement.Roles.Expression);
1454
if (location != null)
1455
result.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), YieldStatement.Roles.Semicolon);
1012
1460
public override object Visit (YieldBreak yieldBreakStatement)
1014
var result = new YieldStatement ();
1015
LocationDescriptor location = LocationStorage.Get (yieldBreakStatement);
1016
result.AddChild (new CSharpTokenNode (Convert (location[0]), "yield".Length), YieldStatement.YieldKeywordRole);
1017
result.AddChild (new CSharpTokenNode (Convert (location[1]), "break".Length), YieldStatement.BreakKeywordRole);
1018
result.AddChild (new CSharpTokenNode (Convert (location[2]), ";".Length), YieldStatement.Roles.Semicolon);
1462
var result = new YieldBreakStatement ();
1463
var location = LocationsBag.GetLocations (yieldBreakStatement);
1464
result.AddChild (new CSharpTokenNode (Convert (yieldBreakStatement.loc), "yield".Length), YieldBreakStatement.YieldKeywordRole);
1465
if (location != null) {
1466
result.AddChild (new CSharpTokenNode (Convert (location[0]), "break".Length), YieldBreakStatement.BreakKeywordRole);
1467
result.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), YieldBreakStatement.Roles.Semicolon);
1023
1473
#region Expression
1024
public override object Visit (Expression expression)
1474
public override object Visit (Mono.CSharp.Expression expression)
1026
1476
Console.WriteLine ("Visit unknown expression:" + expression);
1477
System.Console.WriteLine (Environment.StackTrace);
1030
public override object Visit (TypeLookupExpression typeLookupExpression)
1032
var result = new FullTypeName ();
1033
if (!string.IsNullOrEmpty (typeLookupExpression.Namespace)) {
1034
result.AddChild (new Identifier (typeLookupExpression.Namespace + "." + typeLookupExpression.Name, Convert (typeLookupExpression.Location)));
1036
result.AddChild (new Identifier (typeLookupExpression.Name, Convert (typeLookupExpression.Location)));
1481
public override object Visit (Mono.CSharp.DefaultParameterValueExpression defaultParameterValueExpression)
1483
return defaultParameterValueExpression.Child.Accept (this);
1486
public override object Visit (TypeExpression typeExpression)
1488
return new IdentifierExpression (keywordTable [(int)typeExpression.Type.BuiltinType], Convert (typeExpression.Location));
1041
1491
public override object Visit (LocalVariableReference localVariableReference)
1043
return new Identifier (localVariableReference.Name, Convert (localVariableReference.Location));;
1493
return CreateIdentifier (localVariableReference.Name, Convert (localVariableReference.Location));
1496
public override object Visit (QualifiedAliasMember qualifiedAliasMember)
1498
var result = new MonoDevelop.CSharp.Ast.MemberType ();
1499
result.Target = new SimpleType (qualifiedAliasMember.alias, Convert (qualifiedAliasMember.Location));
1500
result.IsDoubleColon = true;
1501
var location = LocationsBag.GetLocations (qualifiedAliasMember);
1502
result.AddChild (new Identifier (qualifiedAliasMember.Name, location != null ? Convert (location [0]) : AstLocation.Empty), MemberReferenceExpression.Roles.Identifier);
1503
return new TypeReferenceExpression () { Type = result };
1046
1506
public override object Visit (MemberAccess memberAccess)
1048
1508
var result = new MemberReferenceExpression ();
1049
result.AddChild ((INode)memberAccess.Left.Accept (this), MemberReferenceExpression.Roles.TargetExpression);
1050
result.AddChild (new Identifier (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier);
1509
if (memberAccess.LeftExpression != null) {
1510
var leftExpr = memberAccess.LeftExpression.Accept (this);
1511
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)leftExpr, MemberReferenceExpression.Roles.TargetExpression);
1513
result.AddChild (CreateIdentifier (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier);
1051
1514
if (memberAccess.TypeArguments != null) {
1052
LocationDescriptor location = LocationStorage.Get (memberAccess);
1053
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberReferenceExpression.Roles.LChevron);
1515
var location = LocationsBag.GetLocations (memberAccess);
1516
if (location != null)
1517
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberReferenceExpression.Roles.LChevron);
1054
1518
AddTypeArguments (result, location, memberAccess.TypeArguments);
1055
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MemberReferenceExpression.Roles.RChevron);
1519
if (location != null && location.Count > 1)
1520
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MemberReferenceExpression.Roles.RChevron);
1060
1525
public override object Visit (Constant constant)
1062
var result = new PrimitiveExpression (constant.GetValue (), Convert (constant.Location), constant.AsString ().Length);
1527
var result = new PrimitiveExpression (constant.GetValue (), Convert (constant.Location), constant.GetValueAsLiteral ().Length);
1066
1531
public override object Visit (SimpleName simpleName)
1068
var result = new FullTypeName ();
1069
result.AddChild (new Identifier (simpleName.Name, Convert (simpleName.Location)), FullTypeName.Roles.Identifier);
1533
var result = new IdentifierExpression ();
1534
result.AddChild (CreateIdentifier (simpleName.Name, Convert (simpleName.Location)), IdentifierExpression.Roles.Identifier);
1070
1535
if (simpleName.TypeArguments != null) {
1071
LocationDescriptor location = LocationStorage.Get (simpleName);
1072
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FullTypeName.Roles.LChevron);
1536
var location = LocationsBag.GetLocations (simpleName);
1537
if (location != null)
1538
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IdentifierExpression.Roles.LChevron);
1073
1539
AddTypeArguments (result, location, simpleName.TypeArguments);
1074
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FullTypeName.Roles.RChevron);
1540
if (location != null && location.Count > 1)
1541
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IdentifierExpression.Roles.RChevron);
1303
1790
var result = new ConditionalExpression ();
1305
result.AddChild ((INode)conditionalExpression.Expr.Accept (this), ConditionalExpression.Roles.Condition);
1306
LocationDescriptor location = LocationStorage.Get (conditionalExpression);
1792
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)conditionalExpression.Expr.Accept (this), ConditionalExpression.Roles.Condition);
1793
var location = LocationsBag.GetLocations (conditionalExpression);
1308
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ConditionalExpression.Roles.QuestionMark);
1309
result.AddChild ((INode)conditionalExpression.TrueExpr.Accept (this), ConditionalExpression.FalseExpressionRole);
1310
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ConditionalExpression.Roles.Colon);
1311
result.AddChild ((INode)conditionalExpression.FalseExpr.Accept (this), ConditionalExpression.FalseExpressionRole);
1795
result.AddChild (new CSharpTokenNode (Convert (conditionalExpression.Location), 1), ConditionalExpression.QuestionMarkRole);
1796
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)conditionalExpression.TrueExpr.Accept (this), ConditionalExpression.TrueRole);
1797
if (location != null)
1798
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ConditionalExpression.ColonRole);
1799
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)conditionalExpression.FalseExpr.Accept (this), ConditionalExpression.FalseRole);
1315
void AddParameter (AbstractCSharpNode parent, Mono.CSharp.ParametersCompiled parameters)
1803
void AddParameter (AstNode parent, Mono.CSharp.AParametersCollection parameters)
1317
if (parameters == null || !parameters.HasParams)
1805
if (parameters == null)
1319
LocationDescriptor paramLocation = LocationStorage.Get (parameters);
1807
var paramLocation = LocationsBag.GetLocations (parameters);
1321
1809
for (int i = 0; i < parameters.Count; i++) {
1322
if (paramLocation.LocationList != null && i > 0 && i - 1 < paramLocation.LocationList.Count)
1323
parent.AddChild (new CSharpTokenNode (Convert (paramLocation.LocationList[i - 1]), 1), ParameterDeclarationExpression.Roles.Comma);
1324
Parameter p = parameters[i];
1325
LocationDescriptor location = LocationStorage.Get (p);
1810
if (paramLocation != null && i > 0 && i - 1 < paramLocation.Count)
1811
parent.AddChild (new CSharpTokenNode (Convert (paramLocation [i - 1]), 1), ParameterDeclaration.Roles.Comma);
1812
var p = (Parameter)parameters.FixedParameters [i];
1813
var location = LocationsBag.GetLocations (p);
1327
ParameterDeclarationExpression parameterDeclarationExpression = new ParameterDeclarationExpression ();
1328
switch (p.ParameterModifier) {
1815
ParameterDeclaration parameterDeclarationExpression = new ParameterDeclaration ();
1816
switch (p.ModFlags) {
1329
1817
case Parameter.Modifier.OUT:
1330
1818
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out;
1331
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "out".Length), ParameterDeclarationExpression.Roles.Keyword);
1819
if (location != null)
1820
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location [0]), "out".Length), ParameterDeclaration.Roles.Keyword);
1333
1822
case Parameter.Modifier.REF:
1334
1823
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref;
1335
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "ref".Length), ParameterDeclarationExpression.Roles.Keyword);
1824
if (location != null)
1825
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location [0]), "ref".Length), ParameterDeclaration.Roles.Keyword);
1337
1827
case Parameter.Modifier.PARAMS:
1338
1828
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params;
1339
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "params".Length), ParameterDeclarationExpression.Roles.Keyword);
1341
case Parameter.Modifier.This:
1342
parameterDeclarationExpression.ParameterModifier = ParameterModifier.This;
1343
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location.LocationList[0]), "this".Length), ParameterDeclarationExpression.Roles.Keyword);
1346
parameterDeclarationExpression.AddChild ((INode)p.TypeName.Accept (this), ParameterDeclarationExpression.Roles.ReturnType);
1347
parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclarationExpression.Roles.Identifier);
1348
if (p.DefaultExpression != null) {
1349
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ParameterDeclarationExpression.Roles.Assign);
1350
parameterDeclarationExpression.AddChild ((INode)p.DefaultExpression.Accept (this), ParameterDeclarationExpression.Roles.Expression);
1352
parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Argument);
1356
void AddTypeArguments (AbstractCSharpNode parent, LocationDescriptor location, Mono.CSharp.TypeArguments typeArguments)
1358
if (typeArguments == null)
1360
for (int i = 0; i < typeArguments.Count; i++) {
1361
if (location.LocationList != null && i > 0 && i - 1 < location.LocationList.Count)
1362
parent.AddChild (new CSharpTokenNode (Convert (location.LocationList[i - 1]), 1), InvocationExpression.Roles.Comma);
1363
parent.AddChild ((INode)typeArguments.Args[i].Accept (this), InvocationExpression.Roles.TypeArgument);
1367
void AddConstraints (AbstractCSharpNode parent, DeclSpace d)
1829
if (location != null)
1830
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location [0]), "params".Length), ParameterDeclaration.Roles.Keyword);
1833
if (p.HasExtensionMethodModifier) {
1834
parameterDeclarationExpression.ParameterModifier = ParameterModifier.This;
1835
if (location != null)
1836
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location [0]), "this".Length), ParameterDeclaration.Roles.Keyword);
1840
if (p.TypeExpression != null) // lambdas may have no types (a, b) => ...
1841
parameterDeclarationExpression.AddChild (ConvertToType (p.TypeExpression), ParameterDeclaration.Roles.Type);
1842
parameterDeclarationExpression.AddChild (CreateIdentifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier);
1843
if (p.HasDefaultValue) {
1844
if (location != null)
1845
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location [1]), 1), ParameterDeclaration.Roles.Assign);
1846
parameterDeclarationExpression.AddChild ((MonoDevelop.CSharp.Ast.Expression)p.DefaultValue.Accept (this), ParameterDeclaration.Roles.Expression);
1848
parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Parameter);
1852
Identifier CreateIdentifier (string name, AstLocation loc)
1854
bool isQuoted = name != null ? name.StartsWith ("@") : false;
1855
string id = isQuoted ? name.Substring (1) : name;
1856
return new Identifier (id ?? "", loc) { IsQuoted = isQuoted };
1859
void AddTypeParameters (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
1861
if (typeArguments == null || typeArguments.IsEmpty)
1863
for (int i = 0; i < typeArguments.Count; i++) {
1864
if (location != null && i > 0 && i - 1 < location.Count)
1865
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
1866
var arg = (TypeParameterName)typeArguments.Args[i];
1869
TypeParameterDeclaration tp = new TypeParameterDeclaration();
1871
if (arg.Variance != Variance.None)
1872
throw new NotImplementedException(); // TODO: variance
1873
tp.AddChild (CreateIdentifier (arg.Name, Convert (arg.Location)), InvocationExpression.Roles.Identifier);
1874
parent.AddChild (tp, InvocationExpression.Roles.TypeParameter);
1878
void AddTypeArguments (AstNode parent, LocationsBag.MemberLocations location, Mono.CSharp.TypeArguments typeArguments)
1880
if (typeArguments == null || typeArguments.IsEmpty)
1882
for (int i = 0; i < typeArguments.Count; i++) {
1883
if (location != null && i > 0 && i - 1 < location.Count)
1884
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
1885
var arg = typeArguments.Args[i];
1888
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
1892
void AddTypeArguments (AstNode parent, List<Location> location, Mono.CSharp.TypeArguments typeArguments)
1894
if (typeArguments == null || typeArguments.IsEmpty)
1896
for (int i = 0; i < typeArguments.Count; i++) {
1897
if (location != null && i > 0 && i - 1 < location.Count)
1898
parent.AddChild (new CSharpTokenNode (Convert (location[i - 1]), 1), InvocationExpression.Roles.Comma);
1899
var arg = typeArguments.Args[i];
1902
parent.AddChild (ConvertToType (arg), InvocationExpression.Roles.TypeArgument);
1906
void AddConstraints (AstNode parent, DeclSpace d)
1369
1908
if (d == null || d.Constraints == null)
1371
1910
for (int i = 0; i < d.Constraints.Count; i++) {
1372
Constraints c = d.Constraints[i];
1373
LocationDescriptor location = LocationStorage.Get (c);
1911
Constraints c = d.Constraints [i];
1912
var location = LocationsBag.GetLocations (c);
1374
1913
var constraint = new Constraint ();
1375
parent.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), InvocationExpression.Roles.Keyword);
1376
parent.AddChild (new Identifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
1377
parent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), InvocationExpression.Roles.Colon);
1914
constraint.AddChild (new CSharpTokenNode (Convert (location [0]), "where".Length), InvocationExpression.Roles.Keyword);
1915
constraint.AddChild (CreateIdentifier (c.TypeParameter.Value, Convert (c.TypeParameter.Location)), InvocationExpression.Roles.Identifier);
1916
constraint.AddChild (new CSharpTokenNode (Convert (location [1]), 1), Constraint.ColonRole);
1378
1917
foreach (var expr in c.ConstraintExpressions)
1379
parent.AddChild ((INode)expr.Accept (this), InvocationExpression.Roles.TypeArgument);
1918
constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
1919
parent.AddChild (constraint, AstNode.Roles.Constraint);
1383
void AddArguments (AbstractCSharpNode parent, LocationDescriptor location, Mono.CSharp.Arguments args)
1923
void AddArguments (AstNode parent, object location, Mono.CSharp.Arguments args)
1385
1925
if (args == null)
1928
var commaLocations = LocationsBag.GetLocations (args);
1387
1930
for (int i = 0; i < args.Count; i++) {
1388
if (location.LocationList != null && i > 0 && i - 1 < location.LocationList.Count)
1389
parent.AddChild (new CSharpTokenNode (Convert (location.LocationList[i - 1]), 1), InvocationExpression.Roles.Comma);
1390
parent.AddChild ((INode)args[i].Expr.Accept (this), InvocationExpression.Roles.Argument);
1931
Argument arg = args[i];
1932
if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
1933
DirectionExpression direction = new DirectionExpression ();
1934
direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
1935
var argLocation = LocationsBag.GetLocations (arg);
1936
if (argLocation != null)
1937
direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
1938
direction.AddChild ((MonoDevelop.CSharp.Ast.Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
1940
parent.AddChild (direction, InvocationExpression.Roles.Argument);
1942
parent.AddChild ((MonoDevelop.CSharp.Ast.Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Argument);
1944
if (commaLocations != null && i > 0) {
1945
int idx = commaLocations.Count - i;
1947
parent.AddChild (new CSharpTokenNode (Convert (commaLocations[idx]), 1), InvocationExpression.Roles.Comma);
1950
if (commaLocations != null && commaLocations.Count > args.Count)
1951
parent.AddChild (new CSharpTokenNode (Convert (commaLocations[0]), 1), InvocationExpression.Roles.Comma);
1394
1954
public override object Visit (Invocation invocationExpression)
1396
1956
var result = new InvocationExpression ();
1397
LocationDescriptor location = LocationStorage.Get (invocationExpression);
1398
result.AddChild ((INode)invocationExpression.Expr.Accept (this), InvocationExpression.Roles.TargetExpression);
1399
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), InvocationExpression.Roles.LPar);
1957
var location = LocationsBag.GetLocations (invocationExpression);
1958
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)invocationExpression.Expression.Accept (this), InvocationExpression.Roles.TargetExpression);
1959
if (location != null)
1960
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), InvocationExpression.Roles.LPar);
1400
1961
AddArguments (result, location, invocationExpression.Arguments);
1402
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), InvocationExpression.Roles.RPar);
1963
if (location != null)
1964
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), InvocationExpression.Roles.RPar);
1408
1970
var result = new ObjectCreateExpression ();
1410
LocationDescriptor location = LocationStorage.Get (newExpression);
1411
result.AddChild (new CSharpTokenNode (Convert (location[2]), "new".Length), ObjectCreateExpression.Roles.Keyword);
1413
if (newExpression.NewType != null)
1414
result.AddChild ((INode)newExpression.NewType.Accept (this), ObjectCreateExpression.Roles.ReturnType);
1416
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar);
1417
AddArguments (result, location, newExpression.NewArguments);
1419
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ObjectCreateExpression.Roles.RPar);
1972
var location = LocationsBag.GetLocations (newExpression);
1973
result.AddChild (new CSharpTokenNode (Convert (newExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword);
1975
if (newExpression.TypeRequested != null)
1976
result.AddChild (ConvertToType (newExpression.TypeRequested), ObjectCreateExpression.Roles.Type);
1977
if (location != null)
1978
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar);
1979
AddArguments (result, location, newExpression.Arguments);
1981
if (location != null)
1982
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ObjectCreateExpression.Roles.RPar);
1984
// TODO: Collection initializer ?
1990
public override object Visit (NewInitialize newInitializeExpression)
1992
var result = new ObjectCreateExpression ();
1993
result.AddChild (new CSharpTokenNode (Convert (newInitializeExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword);
1995
if (newInitializeExpression.TypeRequested != null)
1996
result.AddChild (ConvertToType (newInitializeExpression.TypeRequested), ObjectCreateExpression.Roles.Type);
1998
var location = LocationsBag.GetLocations (newInitializeExpression);
1999
if (location != null)
2000
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar);
2001
AddArguments (result, location, newInitializeExpression.Arguments);
2002
if (location != null)
2003
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ObjectCreateExpression.Roles.RPar);
1424
2009
public override object Visit (ArrayCreation arrayCreationExpression)
1426
var result = new ArrayObjectCreateExpression ();
2011
var result = new ArrayCreateExpression ();
1428
var location = LocationStorage.Get (arrayCreationExpression);
1429
result.AddChild (new CSharpTokenNode (Convert (location[0]), "new".Length), ArrayObjectCreateExpression.Roles.Keyword);
2013
var location = LocationsBag.GetLocations (arrayCreationExpression);
2014
result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Location), "new".Length), ArrayCreateExpression.Roles.Keyword);
1431
2016
if (arrayCreationExpression.NewType != null)
1432
result.AddChild ((INode)arrayCreationExpression.NewType.Accept (this), ArrayObjectCreateExpression.Roles.ReturnType);
1434
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ArrayObjectCreateExpression.Roles.LBracket);
2017
result.AddChild (ConvertToType (arrayCreationExpression.NewType), ArrayCreateExpression.Roles.Type);
2018
if (location != null)
2019
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket);
1435
2020
if (arrayCreationExpression.Arguments != null) {
2021
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Arguments);
1436
2022
for (int i = 0 ;i < arrayCreationExpression.Arguments.Count; i++) {
1438
result.AddChild (new CSharpTokenNode (Convert (location.LocationList [i - 1]), 1), IndexerExpression.Roles.Comma);
1439
result.AddChild ((INode)arrayCreationExpression.Arguments[i].Accept (this), ObjectCreateExpression.Roles.Initializer);
2023
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)arrayCreationExpression.Arguments[i].Accept (this), ArrayCreateExpression.Roles.Argument);
2024
if (commaLocations != null && i > 0)
2025
result.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), ArrayCreateExpression.Roles.Comma);
1442
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), ArrayObjectCreateExpression.Roles.RBracket);
2028
if (location != null)
2029
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ArrayCreateExpression.Roles.RBracket);
1444
if (arrayCreationExpression.Initializers != null) {
1445
var initLocation = LocationStorage.Get (arrayCreationExpression.Initializers);
1446
result.AddChild (new CSharpTokenNode (Convert (initLocation[0]), 1), ArrayObjectCreateExpression.Roles.LBrace);
1447
if (arrayCreationExpression.Initializers.Elements != null) {
1448
for (int i = 0; i < arrayCreationExpression.Initializers.Elements.Count; i++) {
1450
result.AddChild (new CSharpTokenNode (Convert (initLocation.LocationList [i - 1]), 1), IndexerExpression.Roles.Comma);
1451
result.AddChild ((INode)arrayCreationExpression.Initializers.Elements[i].Accept (this), ObjectCreateExpression.Roles.Initializer);
2031
if (arrayCreationExpression.Initializers != null && arrayCreationExpression.Initializers.Count != 0) {
2032
//throw new NotImplementedException();
2033
/* TODO: use ArrayInitializerExpression
2034
var initLocation = LocationsBag.GetLocations (arrayCreationExpression.Initializers);
2035
result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Initializers.Location), 1), ArrayCreateExpression.Roles.LBrace);
2036
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Initializers.Elements);
2037
for (int i = 0; i < arrayCreationExpression.Initializers.Count; i++) {
2038
result.AddChild ((AstNode)arrayCreationExpression.Initializers[i].Accept (this), ObjectCreateExpression.Roles.Variable);
2039
if (commaLocations != null && i > 0) {
2040
result.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), IndexerExpression.Roles.Comma);
1454
result.AddChild (new CSharpTokenNode (Convert (initLocation[1]), 1), ArrayObjectCreateExpression.Roles.RBrace);
2044
if (initLocation != null)
2045
result.AddChild (new CSharpTokenNode (Convert (initLocation[initLocation.Count - 1]), 1), ArrayCreateExpression.Roles.RBrace); */
1576
2169
var result = new AssignmentExpression ();
1578
LocationDescriptor location = LocationStorage.Get (simpleAssign);
1580
result.AssignmentOperatorType = AssignmentOperatorType.Assign;
2171
result.Operator = AssignmentOperatorType.Assign;
1581
2172
if (simpleAssign.Target != null)
1582
result.AddChild ((INode)simpleAssign.Target.Accept (this), AssignmentExpression.LeftExpressionRole);
1583
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), AssignmentExpression.OperatorRole);
2173
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)simpleAssign.Target.Accept (this), AssignmentExpression.LeftRole);
2174
result.AddChild (new CSharpTokenNode (Convert (simpleAssign.Location), 1), AssignmentExpression.OperatorRole);
1585
if (simpleAssign.Source != null)
1586
result.AddChild ((INode)simpleAssign.Source.Accept (this), AssignmentExpression.RightExpressionRole);
2176
if (simpleAssign.Source != null) {
2177
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)simpleAssign.Source.Accept (this), AssignmentExpression.RightRole);
1590
2182
public override object Visit (CompoundAssign compoundAssign)
1592
2184
var result = new AssignmentExpression ();
1593
LocationDescriptor location = LocationStorage.Get (compoundAssign);
1594
2185
int opLength = 2;
1595
2186
switch (compoundAssign.Op) {
1596
case Binary.Operator.Multiply:
1597
result.AssignmentOperatorType = AssignmentOperatorType.Multiply;
1599
case Binary.Operator.Division:
1600
result.AssignmentOperatorType = AssignmentOperatorType.Divide;
1602
case Binary.Operator.Modulus:
1603
result.AssignmentOperatorType = AssignmentOperatorType.Modulus;
1605
case Binary.Operator.Addition:
1606
result.AssignmentOperatorType = AssignmentOperatorType.Add;
1608
case Binary.Operator.Subtraction:
1609
result.AssignmentOperatorType = AssignmentOperatorType.Subtract;
1611
case Binary.Operator.LeftShift:
1612
result.AssignmentOperatorType = AssignmentOperatorType.ShiftLeft;
1615
case Binary.Operator.RightShift:
1616
result.AssignmentOperatorType = AssignmentOperatorType.ShiftRight;
1619
case Binary.Operator.BitwiseAnd:
1620
result.AssignmentOperatorType = AssignmentOperatorType.BitwiseAnd;
1622
case Binary.Operator.BitwiseOr:
1623
result.AssignmentOperatorType = AssignmentOperatorType.BitwiseOr;
1625
case Binary.Operator.ExclusiveOr:
1626
result.AssignmentOperatorType = AssignmentOperatorType.ExclusiveOr;
2187
case Binary.Operator.Multiply:
2188
result.Operator = AssignmentOperatorType.Multiply;
2190
case Binary.Operator.Division:
2191
result.Operator = AssignmentOperatorType.Divide;
2193
case Binary.Operator.Modulus:
2194
result.Operator = AssignmentOperatorType.Modulus;
2196
case Binary.Operator.Addition:
2197
result.Operator = AssignmentOperatorType.Add;
2199
case Binary.Operator.Subtraction:
2200
result.Operator = AssignmentOperatorType.Subtract;
2202
case Binary.Operator.LeftShift:
2203
result.Operator = AssignmentOperatorType.ShiftLeft;
2206
case Binary.Operator.RightShift:
2207
result.Operator = AssignmentOperatorType.ShiftRight;
2210
case Binary.Operator.BitwiseAnd:
2211
result.Operator = AssignmentOperatorType.BitwiseAnd;
2213
case Binary.Operator.BitwiseOr:
2214
result.Operator = AssignmentOperatorType.BitwiseOr;
2216
case Binary.Operator.ExclusiveOr:
2217
result.Operator = AssignmentOperatorType.ExclusiveOr;
1630
result.AddChild ((INode)compoundAssign.Target.Accept (this), AssignmentExpression.LeftExpressionRole);
1631
result.AddChild (new CSharpTokenNode (Convert (location[0]), opLength), AssignmentExpression.OperatorRole);
1632
result.AddChild ((INode)compoundAssign.Source.Accept (this), AssignmentExpression.RightExpressionRole);
2221
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)compoundAssign.Target.Accept (this), AssignmentExpression.LeftRole);
2222
result.AddChild (new CSharpTokenNode (Convert (compoundAssign.Location), opLength), AssignmentExpression.OperatorRole);
2223
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)compoundAssign.Source.Accept (this), AssignmentExpression.RightRole);
1636
2227
public override object Visit (Mono.CSharp.AnonymousMethodExpression anonymousMethodExpression)
1638
var result = new MonoDevelop.CSharp.Dom.AnonymousMethodExpression ();
1639
LocationDescriptor location = LocationStorage.Get (anonymousMethodExpression);
1640
result.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), AssignmentExpression.Roles.Keyword);
2229
var result = new MonoDevelop.CSharp.Ast.AnonymousMethodExpression ();
2230
var location = LocationsBag.GetLocations (anonymousMethodExpression);
2231
if (location != null) {
2232
result.AddChild (new CSharpTokenNode (Convert (location[0]), "delegate".Length), AssignmentExpression.Roles.Keyword);
2234
if (location.Count > 1) {
2235
result.HasParameterList = true;
2236
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AssignmentExpression.Roles.LPar);
2237
AddParameter (result, anonymousMethodExpression.Parameters);
2238
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AssignmentExpression.Roles.RPar);
1642
if (location.Keywords.Length > 1) {
1643
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AssignmentExpression.Roles.LPar);
1644
AddParameter (result, anonymousMethodExpression.Parameters);
1645
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AssignmentExpression.Roles.RPar);
1647
result.AddChild ((INode)anonymousMethodExpression.Block.Accept (this), AssignmentExpression.Roles.Body);
2242
result.AddChild ((BlockStatement)anonymousMethodExpression.Block.Accept (this), AssignmentExpression.Roles.Body);
1651
2246
public override object Visit (Mono.CSharp.LambdaExpression lambdaExpression)
1653
var result = new MonoDevelop.CSharp.Dom.LambdaExpression ();
1654
LocationDescriptor location = LocationStorage.Get (lambdaExpression);
1656
if (location.Keywords == null || location.Keywords.Length == 1) {
1657
AddParameter (result, lambdaExpression.Parameters);
1658
result.AddChild (new CSharpTokenNode (Convert (location[0]), "=>".Length), AssignmentExpression.Roles.Assign);
1660
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AssignmentExpression.Roles.LPar);
1661
AddParameter (result, lambdaExpression.Parameters);
1662
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AssignmentExpression.Roles.RPar);
1663
result.AddChild (new CSharpTokenNode (Convert (location[0]), "=>".Length), AssignmentExpression.Roles.Assign);
1665
if (lambdaExpression.Block.IsGenerated) {
1666
ContextualReturn generatedReturn = (ContextualReturn)lambdaExpression.Block.Statements[0];
1667
result.AddChild ((INode)generatedReturn.Expr.Accept (this), AssignmentExpression.Roles.Expression);
1669
result.AddChild ((INode)lambdaExpression.Block.Accept (this), AssignmentExpression.Roles.Expression);
2248
var result = new MonoDevelop.CSharp.Ast.LambdaExpression ();
2249
var location = LocationsBag.GetLocations (lambdaExpression);
2251
if (location == null || location.Count == 1) {
2252
AddParameter (result, lambdaExpression.Parameters);
2253
if (location != null)
2254
result.AddChild (new CSharpTokenNode (Convert (location [0]), "=>".Length), MonoDevelop.CSharp.Ast.LambdaExpression.ArrowRole);
2256
result.AddChild (new CSharpTokenNode (Convert (lambdaExpression.Location), 1), MonoDevelop.CSharp.Ast.LambdaExpression.Roles.LPar);
2257
AddParameter (result, lambdaExpression.Parameters);
2258
if (location != null) {
2259
result.AddChild (new CSharpTokenNode (Convert (location [0]), 1), MonoDevelop.CSharp.Ast.LambdaExpression.Roles.RPar);
2260
result.AddChild (new CSharpTokenNode (Convert (location [1]), "=>".Length), MonoDevelop.CSharp.Ast.LambdaExpression.ArrowRole);
2263
if (lambdaExpression.Block.IsCompilerGenerated) {
2264
ContextualReturn generatedReturn = (ContextualReturn)lambdaExpression.Block.Statements [0];
2265
result.AddChild ((AstNode)generatedReturn.Expr.Accept (this), MonoDevelop.CSharp.Ast.LambdaExpression.BodyRole);
2267
result.AddChild ((AstNode)lambdaExpression.Block.Accept (this), MonoDevelop.CSharp.Ast.LambdaExpression.BodyRole);
2273
public override object Visit (ConstInitializer constInitializer)
2275
return constInitializer.Expr.Accept (this);
2278
public override object Visit (ArrayInitializer arrayInitializer)
2280
var result = new ArrayInitializerExpression ();
2281
var location = LocationsBag.GetLocations (arrayInitializer);
2282
result.AddChild (new CSharpTokenNode (Convert (arrayInitializer.Location), "{".Length), ArrayInitializerExpression.Roles.LBrace);
2283
var commaLocations = LocationsBag.GetLocations (arrayInitializer.Elements);
2284
for (int i = 0; i < arrayInitializer.Count; i++) {
2285
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)arrayInitializer[i].Accept (this), ArrayInitializerExpression.Roles.Expression);
2286
if (commaLocations != null && i < commaLocations.Count)
2287
result.AddChild (new CSharpTokenNode (Convert (commaLocations[i]), ",".Length), ArrayInitializerExpression.Roles.Comma);
2290
if (location != null) {
2291
if (location.Count == 2) // optional comma
2292
result.AddChild (new CSharpTokenNode (Convert (location[1]), ",".Length), ArrayInitializerExpression.Roles.Comma);
2293
result.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), "}".Length), ArrayInitializerExpression.Roles.RBrace);
1676
2300
#region LINQ expressions
1677
public override object Visit (Mono.CSharp.Linq.QueryExpression queryExpression)
2301
/* public override object Visit (Mono.CSharp.Linq.Query queryExpression)
1679
var result = new QueryExpressionFromClause ();
1680
LocationDescriptor location = LocationStorage.Get (queryExpression);
1681
result.AddChild (new CSharpTokenNode (Convert (location[0]), "from".Length), QueryExpressionFromClause.FromKeywordRole);
2303
var result = new QueryFromClause ();
2304
var location = LocationsBag.GetLocations (queryExpression);
2305
if (location != null)
2306
result.AddChild (new CSharpTokenNode (Convert (location[0]), "from".Length), QueryFromClause.FromKeywordRole);
1682
2307
// TODO: select identifier
1683
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryExpressionFromClause.InKeywordRole);
1684
result.AddChild ((INode)((Mono.CSharp.Linq.AQueryClause)queryExpression.Expr).Expr.Accept (this), QueryExpressionFromClause.Roles.Expression);
2308
if (location != null)
2309
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryFromClause.InKeywordRole);
2310
var query = queryExpression.Expr as Mono.CSharp.Linq.AQueryClause;
2311
// if (query != null && query.Expr != null)
2312
// result.AddChild ((AstNode)query.Expr.Accept (this), QueryFromClause.Roles.Expression);
1688
2316
public override object Visit (Mono.CSharp.Linq.SelectMany selectMany)
1690
var result = new QueryExpressionFromClause ();
1691
Mono.CSharp.Linq.Cast cast = selectMany.Expr as Mono.CSharp.Linq.Cast;
1692
LocationDescriptor location = LocationStorage.Get (selectMany);
1693
result.AddChild (new CSharpTokenNode (Convert (location[0]), "from".Length), QueryExpressionFromClause.FromKeywordRole);
1696
result.AddChild ((INode)cast.TypeExpr.Accept (this), QueryExpressionFromClause.Roles.ReturnType);
1698
result.AddChild (new Identifier (selectMany.SelectIdentifier.Value, Convert (selectMany.SelectIdentifier.Location)), QueryExpressionFromClause.Roles.Identifier);
1700
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryExpressionFromClause.InKeywordRole);
1702
result.AddChild ((INode)(cast != null ? cast.Expr : selectMany.Expr).Accept (this), QueryExpressionFromClause.Roles.Expression);
2318
var result = new QueryFromClause ();
2320
// Mono.CSharp.Linq.Cast cast = selectMany.Expr as Mono.CSharp.Linq.Cast;
2321
var location = LocationsBag.GetLocations (selectMany);
2322
if (location != null)
2323
result.AddChild (new CSharpTokenNode (Convert (location[0]), "from".Length), QueryFromClause.FromKeywordRole);
2325
// result.AddChild ((AstNode)cast.TypeExpr.Accept (this), QueryFromClause.Roles.ReturnType);
2326
// if (cast != null)
2328
// result.AddChild (CreateIdentifier (selectMany.SelectIdentifier.Value, Convert (selectMany.SelectIdentifier.Location)), QueryFromClause.Roles.Identifier);
2329
// result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryFromClause.InKeywordRole);
2331
// result.AddChild ((AstNode)(cast != null ? cast.Expr : selectMany.Expr).Accept (this), QueryFromClause.Roles.Expression);
1707
2337
public override object Visit (Mono.CSharp.Linq.Select sel)
1709
var result = new QueryExpressionSelectClause ();
1710
LocationDescriptor location = LocationStorage.Get (sel);
1711
result.AddChild (new CSharpTokenNode (Convert (location[0]), "select".Length), QueryExpressionWhereClause.Roles.Keyword);
1712
result.AddChild ((INode)sel.Expr.Accept (this), QueryExpressionWhereClause.Roles.Expression);
2339
var result = new QuerySelectClause ();
2340
var location = LocationsBag.GetLocations (sel);
2341
result.AddChild (new CSharpTokenNode (Convert (location[0]), "select".Length), QueryWhereClause.Roles.Keyword);
2342
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)sel.Expr.Accept (this), QueryWhereClause.Roles.Expression);
1716
2346
public override object Visit (Mono.CSharp.Linq.GroupBy groupBy)
1718
var result = new QueryExpressionGroupClause ();
1719
LocationDescriptor location = LocationStorage.Get (groupBy);
1720
result.AddChild (new CSharpTokenNode (Convert (location[0]), "group".Length), QueryExpressionGroupClause.GroupKeywordRole);
1721
result.AddChild ((INode)groupBy.ElementSelector.Accept (this), QueryExpressionGroupClause.GroupByExpressionRole);
1722
result.AddChild (new CSharpTokenNode (Convert (location[1]), "by".Length), QueryExpressionGroupClause.ByKeywordRole);
1723
result.AddChild ((INode)groupBy.Expr.Accept (this), QueryExpressionGroupClause.ProjectionExpressionRole);
2348
var result = new QueryGroupClause ();
2349
var location = LocationsBag.GetLocations (groupBy);
2350
if (location != null)
2351
result.AddChild (new CSharpTokenNode (Convert (location[0]), "group".Length), QueryGroupClause.GroupKeywordRole);
2352
// result.AddChild ((AstNode)groupBy.ElementSelector.Accept (this), QueryGroupClause.GroupByExpressionRole);
2353
// if (location != null)
2354
// result.AddChild (new CSharpTokenNode (Convert (location[1]), "by".Length), QueryGroupClause.ByKeywordRole);
2355
// result.AddChild ((AstNode)groupBy.Expr.Accept (this), QueryGroupClause.ProjectionExpressionRole);
1727
2359
public override object Visit (Mono.CSharp.Linq.Let l)
1729
var result = new QueryExpressionLetClause ();
1730
LocationDescriptor location = LocationStorage.Get (l);
2361
var result = new QueryLetClause ();
2362
var location = LocationsBag.GetLocations (l);
1732
result.AddChild (new CSharpTokenNode (Convert (location[0]), "let".Length), QueryExpressionWhereClause.Roles.Keyword);
2364
if (location != null)
2365
result.AddChild (new CSharpTokenNode (Convert (location[0]), "let".Length), QueryWhereClause.Roles.Keyword);
1734
2367
NewAnonymousType aType = l.Expr as NewAnonymousType;
1735
2368
AnonymousTypeParameter param = ((AnonymousTypeParameter)aType.Parameters[1]);
1736
result.AddChild (new Identifier (param.Name, Convert (param.Location)));
1738
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), QueryExpressionWhereClause.Roles.Assign);
1740
result.AddChild ((INode)param.Expr.Accept (this), QueryExpressionWhereClause.Roles.Condition);
2369
result.AddChild (CreateIdentifier (param.Name, Convert (param.Location)), Identifier.Roles.Identifier);
2371
if (location != null)
2372
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), QueryWhereClause.Roles.Assign);
2374
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)param.Expr.Accept (this), QueryWhereClause.Roles.Condition);
1744
2378
public override object Visit (Mono.CSharp.Linq.Where w)
1746
var result = new QueryExpressionWhereClause ();
1747
LocationDescriptor location = LocationStorage.Get (w);
1748
result.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), QueryExpressionWhereClause.Roles.Keyword);
1749
result.AddChild ((INode)w.Expr.Accept (this), QueryExpressionWhereClause.Roles.Condition);
2380
var result = new QueryWhereClause ();
2381
var location = LocationsBag.GetLocations (w);
2382
if (location != null)
2383
result.AddChild (new CSharpTokenNode (Convert (location[0]), "where".Length), QueryWhereClause.Roles.Keyword);
2384
result.AddChild ((MonoDevelop.CSharp.Ast.Expression)w.Expr.Accept (this), QueryWhereClause.Roles.Condition);
1753
2388
public override object Visit (Mono.CSharp.Linq.Join join)
1755
var result = new QueryExpressionJoinClause ();
1756
LocationDescriptor location = LocationStorage.Get (join);
1757
result.AddChild (new CSharpTokenNode (Convert (location[0]), "join".Length), QueryExpressionJoinClause.JoinKeywordRole);
1759
result.AddChild (new Identifier (join.JoinIdentifier.Value, Convert (join.JoinIdentifier.Location)));
1761
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryExpressionJoinClause.InKeywordRole);
1763
result.AddChild ((INode)join.Expr.Accept (this), QueryExpressionJoinClause.Roles.Expression);
1765
result.AddChild (new CSharpTokenNode (Convert (location[2]), "on".Length), QueryExpressionJoinClause.OnKeywordRole);
2390
var result = new QueryJoinClause ();
2391
/* var location = LocationsBag.GetLocations (join);
2392
if (location != null)
2393
result.AddChild (new CSharpTokenNode (Convert (location[0]), "join".Length), QueryJoinClause.JoinKeywordRole);
2395
result.AddChild (CreateIdentifier (join.JoinVariable.Name, Convert (join.JoinVariable.Location)), Identifier.Roles.Identifier);
2397
if (location != null)
2398
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryJoinClause.InKeywordRole);
2400
result.AddChild ((AstNode)join.Expr.Accept (this), QueryJoinClause.Roles.Expression);
2402
if (location != null)
2403
result.AddChild (new CSharpTokenNode (Convert (location[2]), "on".Length), QueryJoinClause.OnKeywordRole);
1766
2404
// TODO: on expression
1768
result.AddChild (new CSharpTokenNode (Convert (location[3]), "equals".Length), QueryExpressionJoinClause.EqualsKeywordRole);
2406
if (location != null)
2407
result.AddChild (new CSharpTokenNode (Convert (location[3]), "equals".Length), QueryJoinClause.EqualsKeywordRole);
1769
2408
// TODO: equals expression
1774
2413
public override object Visit (Mono.CSharp.Linq.GroupJoin groupJoin)
1776
var result = new QueryExpressionJoinClause ();
1777
LocationDescriptor location = LocationStorage.Get (groupJoin);
1778
result.AddChild (new CSharpTokenNode (Convert (location[0]), "join".Length), QueryExpressionJoinClause.JoinKeywordRole);
1780
result.AddChild (new Identifier (groupJoin.JoinIdentifier.Value, Convert (groupJoin.JoinIdentifier.Location)));
1782
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryExpressionJoinClause.InKeywordRole);
1784
result.AddChild ((INode)groupJoin.Expr.Accept (this), QueryExpressionJoinClause.Roles.Expression);
1786
result.AddChild (new CSharpTokenNode (Convert (location[2]), "on".Length), QueryExpressionJoinClause.OnKeywordRole);
2415
var result = new QueryJoinClause ();
2416
/* var location = LocationsBag.GetLocations (groupJoin);
2417
if (location != null)
2418
result.AddChild (new CSharpTokenNode (Convert (location[0]), "join".Length), QueryJoinClause.JoinKeywordRole);
2420
result.AddChild (CreateIdentifier (groupJoin.JoinVariable.Name, Convert (groupJoin.JoinVariable.Location)), Identifier.Roles.Identifier);
2422
if (location != null)
2423
result.AddChild (new CSharpTokenNode (Convert (location[1]), "in".Length), QueryJoinClause.InKeywordRole);
2425
result.AddChild ((AstNode)groupJoin.Expr.Accept (this), QueryJoinClause.Roles.Expression);
2427
if (location != null)
2428
result.AddChild (new CSharpTokenNode (Convert (location[2]), "on".Length), QueryJoinClause.OnKeywordRole);
1787
2429
// TODO: on expression
1789
result.AddChild (new CSharpTokenNode (Convert (location[3]), "equals".Length), QueryExpressionJoinClause.EqualsKeywordRole);
2431
if (location != null)
2432
result.AddChild (new CSharpTokenNode (Convert (location[3]), "equals".Length), QueryJoinClause.EqualsKeywordRole);
1790
2433
// TODO: equals expression
1792
result.AddChild (new CSharpTokenNode (Convert (location[4]), "into".Length), QueryExpressionJoinClause.IntoKeywordRole);
2435
if (location != null)
2436
result.AddChild (new CSharpTokenNode (Convert (location[4]), "into".Length), QueryJoinClause.IntoKeywordRole);
1794
result.AddChild (new Identifier (groupJoin.IntoVariable.Value, Convert (groupJoin.IntoVariable.Location)));
2438
result.AddChild (CreateIdentifier (groupJoin.JoinVariable.Name, Convert (groupJoin.JoinVariable.Location)), Identifier.Roles.Identifier);*/
1798
2442
public override object Visit (Mono.CSharp.Linq.OrderByAscending orderByAscending)
1800
var result = new QueryExpressionOrderClause ();
1801
result.OrderAscending = true;
1802
result.AddChild ((INode)orderByAscending.Expr.Accept (this), QueryExpressionWhereClause.Roles.Expression);
1803
LocationDescriptor location = LocationStorage.Get (orderByAscending);
1804
if (location.Keywords != null)
1805
result.AddChild (new CSharpTokenNode (Convert (location[0]), "ascending".Length), QueryExpressionWhereClause.Roles.Keyword);
2444
var result = new QueryOrderClause ();
2445
/* result.OrderAscending = true;
2446
result.AddChild ((AstNode)orderByAscending.Expr.Accept (this), QueryWhereClause.Roles.Expression);
2447
var location = LocationsBag.GetLocations (orderByAscending);
2448
if (location != null)
2449
result.AddChild (new CSharpTokenNode (Convert (location[0]), "ascending".Length), QueryWhereClause.Roles.Keyword);*/
1809
2453
public override object Visit (Mono.CSharp.Linq.OrderByDescending orderByDescending)
1811
var result = new QueryExpressionOrderClause ();
1812
result.OrderAscending = false;
1813
result.AddChild ((INode)orderByDescending.Expr.Accept (this), QueryExpressionWhereClause.Roles.Expression);
1814
LocationDescriptor location = LocationStorage.Get (orderByDescending);
1815
result.AddChild (new CSharpTokenNode (Convert (location[0]), "descending".Length), QueryExpressionWhereClause.Roles.Keyword);
2455
var result = new QueryOrderClause ();
2456
/* result.OrderAscending = false;
2457
result.AddChild ((AstNode)orderByDescending.Expr.Accept (this), QueryWhereClause.Roles.Expression);
2458
var location = LocationsBag.GetLocations (orderByDescending);
2459
if (location != null)
2460
result.AddChild (new CSharpTokenNode (Convert (location[0]), "descending".Length), QueryWhereClause.Roles.Keyword);*/
1819
2464
public override object Visit (Mono.CSharp.Linq.ThenByAscending thenByAscending)
1821
var result = new QueryExpressionOrderClause ();
1822
result.OrderAscending = true;
1823
result.AddChild ((INode)thenByAscending.Expr.Accept (this), QueryExpressionWhereClause.Roles.Expression);
1824
LocationDescriptor location = LocationStorage.Get (thenByAscending);
1825
if (location.Keywords != null)
1826
result.AddChild (new CSharpTokenNode (Convert (location[0]), "ascending".Length), QueryExpressionWhereClause.Roles.Keyword);
2466
var result = new QueryOrderClause ();
2467
/* result.OrderAscending = true;
2468
result.AddChild ((AstNode)thenByAscending.Expr.Accept (this), QueryWhereClause.Roles.Expression);
2469
var location = LocationsBag.GetLocations (thenByAscending);
2470
if (location != null)
2471
result.AddChild (new CSharpTokenNode (Convert (location[0]), "ascending".Length), QueryWhereClause.Roles.Keyword);*/
1830
2475
public override object Visit (Mono.CSharp.Linq.ThenByDescending thenByDescending)
1832
var result = new QueryExpressionOrderClause ();
1833
result.OrderAscending = false;
1834
result.AddChild ((INode)thenByDescending.Expr.Accept (this), QueryExpressionWhereClause.Roles.Expression);
1835
LocationDescriptor location = LocationStorage.Get (thenByDescending);
1836
result.AddChild (new CSharpTokenNode (Convert (location[0]), "descending".Length), QueryExpressionWhereClause.Roles.Keyword);
2477
var result = new QueryOrderClause ();
2478
/* result.OrderAscending = false;
2479
result.AddChild ((AstNode)thenByDescending.Expr.Accept (this), QueryWhereClause.Roles.Expression);
2480
var location = LocationsBag.GetLocations (thenByDescending);
2481
if (location != null)
2482
result.AddChild (new CSharpTokenNode (Convert (location[0]), "descending".Length), QueryWhereClause.Roles.Keyword);*/
1842
public MonoDevelop.CSharp.Dom.CompilationUnit Parse (TextEditorData data)
1844
Tokenizer.InterpretTabAsSingleChar = true;
1845
CompilerCompilationUnit top;
1846
using (Stream stream = data.OpenStream ()) {
1847
top = CompilerCallableEntryPoint.ParseFile (new string[] { "-v", "-unsafe"}, stream, data.Document.FileName, Console.Out);
2488
public static void InsertComment (AstNode node, MonoDevelop.CSharp.Ast.Comment comment)
2490
if (node.EndLocation < comment.StartLocation) {
2491
node.AddChild (comment, AstNode.Roles.Comment);
2495
foreach (var child in node.Children) {
2496
if (child.StartLocation < comment.StartLocation && comment.StartLocation < child.EndLocation) {
2497
InsertComment (child, comment);
2500
if (comment.StartLocation < child.StartLocation) {
2501
node.InsertChildBefore (child, comment, AstNode.Roles.Comment);
2506
node.AddChild (comment, AstNode.Roles.Comment);
2509
static void InsertComments (CompilerCompilationUnit top, ConversionVisitor conversionVisitor)
2511
foreach (var special in top.SpecialsBag.Specials) {
2512
var comment = special as SpecialsBag.Comment;
2514
if (comment != null) {
2515
var type = (MonoDevelop.CSharp.Ast.CommentType)comment.CommentType;
2516
var start = new AstLocation (comment.Line, comment.Col);
2517
var end = new AstLocation (comment.EndLine, comment.EndCol);
2518
var domComment = new MonoDevelop.CSharp.Ast.Comment (type, start, end);
2519
domComment.StartsLine = comment.StartsLine;
2520
domComment.Content = comment.Content;
2521
InsertComment (conversionVisitor.Unit, domComment);
2526
internal static MonoDevelop.CSharp.Ast.CompilationUnit Parse (CompilerCompilationUnit top)
1850
2528
if (top == null)
1852
CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationStorage);
1853
top.ModuleCompiled.Accept (conversionVisitor);
2530
CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
2531
top.UsingsBag.Global.Accept (conversionVisitor);
2532
InsertComments (top, conversionVisitor);
1854
2533
return conversionVisitor.Unit;
2536
McsParser.ErrorReportPrinter errorReportPrinter = new McsParser.ErrorReportPrinter ();
2538
public McsParser.ErrorReportPrinter ErrorReportPrinter {
2540
return errorReportPrinter;
2544
public bool HasErrors {
2546
return errorReportPrinter.ErrorsCount + errorReportPrinter.FatalCounter > 0;
2550
public bool HasWarnings {
2552
return errorReportPrinter.WarningsCount > 0;
2556
public MonoDevelop.CSharp.Ast.CompilationUnit Parse (TextEditorData data)
2558
lock (CompilerCallableEntryPoint.parseLock) {
2559
CompilerCompilationUnit top;
2560
using (Stream stream = data.OpenStream ()) {
2561
top = CompilerCallableEntryPoint.ParseFile (new string[] { "-v", "-unsafe"}, stream, data.Document.FileName ?? "empty.cs", errorReportPrinter);
2568
public MonoDevelop.CSharp.Ast.CompilationUnit Parse (TextReader reader)
2570
// TODO: can we optimize this to avoid the text->stream->text roundtrip?
2571
using (MemoryStream stream = new MemoryStream ()) {
2572
StreamWriter w = new StreamWriter(stream, Encoding.UTF8);
2573
char[] buffer = new char[2048];
2575
while ((read = reader.ReadBlock(buffer, 0, buffer.Length)) > 0)
2576
w.Write(buffer, 0, read);
2577
w.Flush(); // we can't close the StreamWriter because that would also close the MemoryStream
2578
stream.Position = 0;
2579
return Parse(stream);
2583
public MonoDevelop.CSharp.Ast.CompilationUnit Parse (Stream stream)
2585
lock (CompilerCallableEntryPoint.parseLock) {
2586
CompilerCompilationUnit top = CompilerCallableEntryPoint.ParseFile (new string[] { "-v", "-unsafe"}, stream, "parsed.cs", errorReportPrinter);
2590
CSharpParser.ConversionVisitor conversionVisitor = new ConversionVisitor (top.LocationsBag);
2591
top.UsingsBag.Global.Accept (conversionVisitor);
2592
InsertComments (top, conversionVisitor);
2593
return conversionVisitor.Unit;
2597
public IEnumerable<AttributedNode> ParseTypeMembers(TextReader reader)
2599
string code = "class MyClass { " + reader.ReadToEnd() + "}";
2600
var cu = Parse(new StringReader(code));
2601
var td = cu.Children.FirstOrDefault() as TypeDeclaration;
2604
return Enumerable.Empty<AttributedNode> ();
2607
public IEnumerable<MonoDevelop.CSharp.Ast.Statement> ParseStatements(TextReader reader)
2609
string code = "void M() { " + reader.ReadToEnd() + "}";
2610
var members = ParseTypeMembers(new StringReader(code));
2611
var method = members.FirstOrDefault() as MethodDeclaration;
2612
if (method != null && method.Body != null)
2613
return method.Body.Statements;
2614
return Enumerable.Empty<MonoDevelop.CSharp.Ast.Statement> ();
2617
public AstType ParseTypeReference(TextReader reader)
2619
// TODO: add support for parsing type references
2620
throw new NotImplementedException();
2623
public AstNode ParseExpression(TextReader reader)
2625
var es = ParseStatements(new StringReader("tmp = " + reader.ReadToEnd() + ";")).FirstOrDefault() as MonoDevelop.CSharp.Ast.ExpressionStatement;
2627
AssignmentExpression ae = es.Expression as AssignmentExpression;
2635
/// Parses a file snippet; guessing what the code snippet represents (compilation unit, type members, block, type reference, expression).
2637
public AstNode ParseSnippet(TextReader reader)
2639
// TODO: add support for parsing a part of a file
2640
throw new NotImplementedException();