public override void Visit (Indexer indexer) { IndexerDeclaration newIndexer = new IndexerDeclaration (); AddAttributeSection (newIndexer, indexer); var location = LocationsBag.GetMemberLocation (indexer); AddModifiers (newIndexer, location); newIndexer.AddChild (ConvertToType (indexer.TypeExpression), Roles.Type); AddExplicitInterface (newIndexer, indexer.MemberName); var name = indexer.MemberName; newIndexer.AddChild (new CSharpTokenNode(Convert (name.Location), IndexerDeclaration.ThisKeywordRole), IndexerDeclaration.ThisKeywordRole); if (location != null && location.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.LBracket), Roles.LBracket); AddParameter (newIndexer, indexer.ParameterInfo); if (location != null && location.Count > 1) newIndexer.AddChild (new CSharpTokenNode (Convert (location [1]), Roles.RBracket), Roles.RBracket); if (location != null && location.Count > 2) newIndexer.AddChild (new CSharpTokenNode (Convert (location [2]), Roles.LBrace), Roles.LBrace); if (indexer.Get != null) { Accessor getAccessor = new Accessor (); var getLocation = LocationsBag.GetMemberLocation (indexer.Get); AddAttributeSection (getAccessor, indexer.Get); AddModifiers (getAccessor, getLocation); if (getLocation != null) getAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Get.Location), PropertyDeclaration.GetKeywordRole), PropertyDeclaration.GetKeywordRole); if (indexer.Get.Block != null) { getAccessor.AddChild ((BlockStatement)indexer.Get.Block.Accept (this), Roles.Body); } else { if (getLocation != null && getLocation.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (getLocation [0]), Roles.Semicolon), Roles.Semicolon); } newIndexer.AddChild (getAccessor, PropertyDeclaration.GetterRole); } if (indexer.Set != null) { Accessor setAccessor = new Accessor (); var setLocation = LocationsBag.GetMemberLocation (indexer.Set); AddAttributeSection (setAccessor, indexer.Set); AddModifiers (setAccessor, setLocation); if (setLocation != null) setAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Set.Location), PropertyDeclaration.SetKeywordRole), PropertyDeclaration.SetKeywordRole); if (indexer.Set.Block != null) { setAccessor.AddChild ((BlockStatement)indexer.Set.Block.Accept (this), Roles.Body); } else { if (setLocation != null && setLocation.Count > 0) newIndexer.AddChild (new CSharpTokenNode (Convert (setLocation [0]), Roles.Semicolon), Roles.Semicolon); } newIndexer.AddChild (setAccessor, PropertyDeclaration.SetterRole); } if (location != null) { if (location.Count > 3) newIndexer.AddChild (new CSharpTokenNode (Convert (location [3]), Roles.RBrace), Roles.RBrace); } else { // parser error, set end node to max value. newIndexer.AddChild (new ErrorNode (), Roles.Error); } typeStack.Peek ().AddChild (newIndexer, Roles.TypeMemberRole); }
public virtual void Visit (Indexer i) { }
void case_198() #line 1780 "cs-parser.jay" { valid_param_mod = 0; var type = (FullNamedExpression) yyVals[-5+yyTop]; Indexer indexer = new Indexer (current_type, type, (MemberName) yyVals[-4+yyTop], (Modifiers) yyVals[-6+yyTop], (ParametersCompiled) yyVals[-1+yyTop], (Attributes) yyVals[-7+yyTop]); current_property = indexer; current_type.AddIndexer (indexer); lbag.AddMember (current_property, GetModifierLocations (), GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[0+yyTop])); if (type.Type != null && type.Type.Kind == MemberKind.Void) report.Error (620, GetLocation (yyVals[-5+yyTop]), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ()); if (indexer.ParameterInfo.IsEmpty) { report.Error (1551, GetLocation (yyVals[-3+yyTop]), "Indexers must have at least one parameter"); } if (doc_support) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.Allowed; } lexer.PropertyParsing = true; }
/// <summary> /// Indexer has special handling in constrast to other AddXXX because the name can be driven by IndexerNameAttribute /// </summary> public void AddIndexer (Indexer i) { members.Add (i); }
void case_226() #line 2272 "ps-parser.jay" { valid_param_mod = 0; var type = (FullNamedExpression) yyVals[-1+yyTop]; var modifiers = (Modifiers) yyVals[-9+yyTop]; var name = (MemberName) yyVals[-7+yyTop]; if (current_container.Kind == MemberKind.Class && name.ExplicitInterface == null && (modifiers & (Modifiers.NEW | Modifiers.SEALED | Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.VIRTUAL | Modifiers.OVERRIDE)) == 0) modifiers |= Modifiers.VIRTUAL; Indexer indexer = new Indexer (current_type, type, name, modifiers, (ParametersCompiled) yyVals[-4+yyTop], (Attributes) yyVals[-10+yyTop]); current_property = indexer; if (is_config_enabled) { current_type.AddIndexer (indexer); } is_config_enabled = true; lbag.AddMember (current_property, GetModifierLocations (), GetLocation (yyVals[-6+yyTop]), GetLocation (yyVals[-3+yyTop])); if (type.Type != null && type.Type.Kind == MemberKind.Void) report.Error (620, GetLocation (yyVals[-8+yyTop]), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ()); if (indexer.ParameterInfo.IsEmpty) { report.Error (1551, GetLocation (yyVals[-6+yyTop]), "Indexers must have at least one parameter"); } if (doc_support) { tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.Allowed; } lexer.PropertyParsing = true; }