Example #1
0
		/// <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);
		}
Example #2
0
			public override void Visit(Indexer i)
			{
				var newIndexer = new IndexerDeclaration();
				AddAttributeSection(newIndexer, i);
				var location = LocationsBag.GetMemberLocation(i);
				AddModifiers(newIndexer, location);
				newIndexer.AddChild(ConvertToType(i.TypeExpression), Roles.Type);
				AddExplicitInterface(newIndexer, i.MemberName);
				var name = i.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, i.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 (i.Get != null) {
					var getAccessor = new Accessor();
					var getLocation = LocationsBag.GetMemberLocation(i.Get);
					AddAttributeSection(getAccessor, i.Get);
					AddModifiers(getAccessor, getLocation);
					if (getLocation != null)
						getAccessor.AddChild(new CSharpTokenNode(Convert(i.Get.Location), PropertyDeclaration.GetKeywordRole), PropertyDeclaration.GetKeywordRole);
					if (i.Get.Block != null) {
						getAccessor.AddChild((BlockStatement)i.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 (i.Set != null) {
					var setAccessor = new Accessor();
					var setLocation = LocationsBag.GetMemberLocation(i.Set);
					AddAttributeSection(setAccessor, i.Set);
					AddModifiers(setAccessor, setLocation);
					if (setLocation != null)
						setAccessor.AddChild(new CSharpTokenNode(Convert(i.Set.Location), PropertyDeclaration.SetKeywordRole), PropertyDeclaration.SetKeywordRole);
					
					if (i.Set.Block != null) {
						setAccessor.AddChild((BlockStatement)i.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);
			}
Example #3
0
void case_219()
#line 1942 "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;
		current_local_parameters = (ParametersCompiled) yyVals[-1+yyTop];
	  }
Example #4
0
		public virtual void Visit (Indexer i)
		{
		}