2 // cs-tokenizer.cs: The Tokenizer for the C# compiler
3 // This also implements the preprocessor
5 // Author: Miguel de Icaza (miguel@gnu.org)
6 // Marek Safar (marek.safar@seznam.cz)
8 // Dual licensed under the terms of the MIT X11 or GNU GPL
10 // Copyright 2001, 2002 Ximian, Inc (http://www.ximian.com)
11 // Copyright 2004-2008 Novell, Inc
17 using System.Collections;
19 using System.Globalization;
20 using System.Reflection;
25 /// Tokenizer for C# source code.
28 public class Tokenizer : yyParser.yyInput
30 SeekableStreamReader reader;
38 bool handle_get_set = false;
39 bool handle_remove_add = false;
40 bool handle_assembly = false;
41 bool handle_where = false;
42 bool handle_typeof = false;
43 bool lambda_arguments_parsing;
44 Location current_location;
45 Location current_comment_location = Location.Null;
46 ArrayList escaped_identifiers = new ArrayList ();
47 public int parsing_block;
48 internal int query_parsing;
51 // XML documentation buffer. The save point is used to divide
52 // comments on types and comments on members.
54 StringBuilder xml_comment_buffer;
57 // See comment on XmlCommentState enumeration.
59 XmlCommentState xml_doc_state = XmlCommentState.Allowed;
62 // Whether tokens have been seen on this line
64 bool tokens_seen = false;
67 // Whether a token has been seen on the file
68 // This is needed because `define' is not allowed to be used
69 // after a token has been seen.
71 bool any_token_seen = false;
73 static Hashtable token_values;
74 static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
76 private static Hashtable TokenValueName
79 if (token_values == null)
80 token_values = GetTokenValueNameHash ();
86 private static Hashtable GetTokenValueNameHash ()
88 Type t = typeof (Token);
89 FieldInfo [] fields = t.GetFields ();
90 Hashtable hash = new Hashtable ();
91 foreach (FieldInfo field in fields) {
92 if (field.IsLiteral && field.IsStatic && field.FieldType == typeof (int))
93 hash.Add (field.GetValue (null), field.Name);
99 // Returns a verbose representation of the current location
101 public string location {
105 if (current_token == Token.ERROR)
106 det = "detail: " + error_details;
110 // return "Line: "+line+" Col: "+col + "\n" +
111 // "VirtLine: "+ref_line +
112 // " Token: "+current_token + " " + det;
113 string current_token_name = TokenValueName [current_token] as string;
114 if (current_token_name == null)
115 current_token_name = current_token.ToString ();
117 return String.Format ("{0} ({1},{2}), Token: {3} {4}", ref_name.Name,
125 public bool PropertyParsing {
126 get { return handle_get_set; }
127 set { handle_get_set = value; }
130 public bool AssemblyTargetParsing {
131 get { return handle_assembly; }
132 set { handle_assembly = value; }
135 public bool EventParsing {
136 get { return handle_remove_add; }
137 set { handle_remove_add = value; }
140 public bool ConstraintsParsing {
141 get { return handle_where; }
142 set { handle_where = value; }
145 public bool TypeOfParsing {
146 get { return handle_typeof; }
147 set { handle_typeof = value; }
150 public XmlCommentState doc_state {
151 get { return xml_doc_state; }
153 if (value == XmlCommentState.Allowed) {
154 check_incorrect_doc_comment ();
155 reset_doc_comment ();
157 xml_doc_state = value;
161 public bool IsEscapedIdentifier (Location loc)
163 foreach (LocatedToken lt in escaped_identifiers)
164 if (lt.Location.Equals (loc))
172 static CharArrayHashtable[] keywords;
173 static Hashtable keyword_strings;
174 static NumberStyles styles;
175 static NumberFormatInfo csharp_format_info;
178 // Values for the associated token returned
188 const int TAKING = 1;
189 const int ELSE_SEEN = 4;
190 const int PARENT_TAKING = 8;
191 const int REGION = 16;
194 // pre-processor if stack state:
198 static System.Text.StringBuilder string_builder;
200 const int max_id_size = 512;
201 static char [] id_builder = new char [max_id_size];
203 static CharArrayHashtable [] identifiers = new CharArrayHashtable [max_id_size + 1];
205 const int max_number_size = 512;
206 static char [] number_builder = new char [max_number_size];
207 static int number_pos;
210 // Details about the error encoutered by the tokenizer
212 string error_details;
214 public string error {
216 return error_details;
233 // This is used when the tokenizer needs to save
234 // the current position as it needs to do some parsing
235 // on its own to deamiguate a token in behalf of the
238 Stack position_stack = new Stack (2);
244 public int putback_char;
245 public int previous_col;
246 public Stack ifstack;
247 public int parsing_generic_less_than;
248 public int current_token;
250 public Position (Tokenizer t)
252 position = t.reader.Position;
254 ref_line = t.ref_line;
256 putback_char = t.putback_char;
257 previous_col = t.previous_col;
258 if (t.ifstack != null && t.ifstack.Count != 0)
259 ifstack = (Stack)t.ifstack.Clone ();
260 parsing_generic_less_than = t.parsing_generic_less_than;
261 current_token = t.current_token;
265 public void PushPosition ()
267 position_stack.Push (new Position (this));
270 public void PopPosition ()
272 Position p = (Position) position_stack.Pop ();
274 reader.Position = p.position;
275 ref_line = p.ref_line;
278 putback_char = p.putback_char;
279 previous_col = p.previous_col;
281 parsing_generic_less_than = p.parsing_generic_less_than;
282 current_token = p.current_token;
285 // Do not reset the position, ignore it.
286 public void DiscardPosition ()
288 position_stack.Pop ();
291 static void AddKeyword (string kw, int token)
293 keyword_strings.Add (kw, kw);
294 if (keywords [kw.Length] == null) {
295 keywords [kw.Length] = new CharArrayHashtable (kw.Length);
297 keywords [kw.Length] [kw.ToCharArray ()] = token;
300 static void InitTokens ()
302 keyword_strings = new Hashtable ();
303 keywords = new CharArrayHashtable [64];
305 AddKeyword ("__arglist", Token.ARGLIST);
306 AddKeyword ("abstract", Token.ABSTRACT);
307 AddKeyword ("as", Token.AS);
308 AddKeyword ("add", Token.ADD);
309 AddKeyword ("assembly", Token.ASSEMBLY);
310 AddKeyword ("base", Token.BASE);
311 AddKeyword ("bool", Token.BOOL);
312 AddKeyword ("break", Token.BREAK);
313 AddKeyword ("byte", Token.BYTE);
314 AddKeyword ("case", Token.CASE);
315 AddKeyword ("catch", Token.CATCH);
316 AddKeyword ("char", Token.CHAR);
317 AddKeyword ("checked", Token.CHECKED);
318 AddKeyword ("class", Token.CLASS);
319 AddKeyword ("const", Token.CONST);
320 AddKeyword ("continue", Token.CONTINUE);
321 AddKeyword ("decimal", Token.DECIMAL);
322 AddKeyword ("default", Token.DEFAULT);
323 AddKeyword ("delegate", Token.DELEGATE);
324 AddKeyword ("do", Token.DO);
325 AddKeyword ("double", Token.DOUBLE);
326 AddKeyword ("else", Token.ELSE);
327 AddKeyword ("enum", Token.ENUM);
328 AddKeyword ("event", Token.EVENT);
329 AddKeyword ("explicit", Token.EXPLICIT);
330 AddKeyword ("extern", Token.EXTERN);
331 AddKeyword ("false", Token.FALSE);
332 AddKeyword ("finally", Token.FINALLY);
333 AddKeyword ("fixed", Token.FIXED);
334 AddKeyword ("float", Token.FLOAT);
335 AddKeyword ("for", Token.FOR);
336 AddKeyword ("foreach", Token.FOREACH);
337 AddKeyword ("goto", Token.GOTO);
338 AddKeyword ("get", Token.GET);
339 AddKeyword ("if", Token.IF);
340 AddKeyword ("implicit", Token.IMPLICIT);
341 AddKeyword ("in", Token.IN);
342 AddKeyword ("int", Token.INT);
343 AddKeyword ("interface", Token.INTERFACE);
344 AddKeyword ("internal", Token.INTERNAL);
345 AddKeyword ("is", Token.IS);
346 AddKeyword ("lock", Token.LOCK);
347 AddKeyword ("long", Token.LONG);
348 AddKeyword ("namespace", Token.NAMESPACE);
349 AddKeyword ("new", Token.NEW);
350 AddKeyword ("null", Token.NULL);
351 AddKeyword ("object", Token.OBJECT);
352 AddKeyword ("operator", Token.OPERATOR);
353 AddKeyword ("out", Token.OUT);
354 AddKeyword ("override", Token.OVERRIDE);
355 AddKeyword ("params", Token.PARAMS);
356 AddKeyword ("private", Token.PRIVATE);
357 AddKeyword ("protected", Token.PROTECTED);
358 AddKeyword ("public", Token.PUBLIC);
359 AddKeyword ("readonly", Token.READONLY);
360 AddKeyword ("ref", Token.REF);
361 AddKeyword ("remove", Token.REMOVE);
362 AddKeyword ("return", Token.RETURN);
363 AddKeyword ("sbyte", Token.SBYTE);
364 AddKeyword ("sealed", Token.SEALED);
365 AddKeyword ("set", Token.SET);
366 AddKeyword ("short", Token.SHORT);
367 AddKeyword ("sizeof", Token.SIZEOF);
368 AddKeyword ("stackalloc", Token.STACKALLOC);
369 AddKeyword ("static", Token.STATIC);
370 AddKeyword ("string", Token.STRING);
371 AddKeyword ("struct", Token.STRUCT);
372 AddKeyword ("switch", Token.SWITCH);
373 AddKeyword ("this", Token.THIS);
374 AddKeyword ("throw", Token.THROW);
375 AddKeyword ("true", Token.TRUE);
376 AddKeyword ("try", Token.TRY);
377 AddKeyword ("typeof", Token.TYPEOF);
378 AddKeyword ("uint", Token.UINT);
379 AddKeyword ("ulong", Token.ULONG);
380 AddKeyword ("unchecked", Token.UNCHECKED);
381 AddKeyword ("unsafe", Token.UNSAFE);
382 AddKeyword ("ushort", Token.USHORT);
383 AddKeyword ("using", Token.USING);
384 AddKeyword ("virtual", Token.VIRTUAL);
385 AddKeyword ("void", Token.VOID);
386 AddKeyword ("volatile", Token.VOLATILE);
387 AddKeyword ("while", Token.WHILE);
388 AddKeyword ("partial", Token.PARTIAL);
389 AddKeyword ("where", Token.WHERE);
392 AddKeyword ("from", Token.FROM);
393 AddKeyword ("join", Token.JOIN);
394 AddKeyword ("on", Token.ON);
395 AddKeyword ("equals", Token.EQUALS);
396 AddKeyword ("select", Token.SELECT);
397 AddKeyword ("group", Token.GROUP);
398 AddKeyword ("by", Token.BY);
399 AddKeyword ("let", Token.LET);
400 AddKeyword ("orderby", Token.ORDERBY);
401 AddKeyword ("ascending", Token.ASCENDING);
402 AddKeyword ("descending", Token.DESCENDING);
403 AddKeyword ("into", Token.INTO);
414 public static void Reset ()
417 csharp_format_info = NumberFormatInfo.InvariantInfo;
418 styles = NumberStyles.Float;
420 string_builder = new System.Text.StringBuilder ();
423 int GetKeyword (char[] id, int id_len)
426 * Keywords are stored in an array of hashtables grouped by their
430 if ((id_len >= keywords.Length) || (keywords [id_len] == null))
432 object o = keywords [id_len] [id];
439 if (!handle_get_set && (res == Token.GET || res == Token.SET))
441 if (!handle_remove_add && (res == Token.REMOVE || res == Token.ADD))
443 if (!handle_assembly && res == Token.ASSEMBLY)
447 // A query expression is any expression that starts with `from identifier'
448 // followed by any token except ; , =
450 if (query_parsing == 0) {
451 if (res == Token.FROM && !lambda_arguments_parsing) {
453 // HACK: to disable generics micro-parser, because PushPosition does not
454 // store identifiers array
455 parsing_generic_less_than = 1;
457 case Token.IDENTIFIER:
469 int next_token = xtoken ();
470 if (next_token == Token.SEMICOLON || next_token == Token.COMMA || next_token == Token.EQUALS)
474 if (RootContext.Version <= LanguageVersion.ISO_2)
475 Report.FeatureIsNotAvailable (Location, "query expressions");
478 Expression.Error_VoidInvalidInTheContext (Location);
482 // HACK: A token is not a keyword so we need to restore identifiers buffer
483 // which has been overwritten before we grabbed the identifier
484 id_builder [0] = 'f'; id_builder [1] = 'r'; id_builder [2] = 'o'; id_builder [3] = 'm';
491 if (res > Token.QUERY_FIRST_TOKEN && res < Token.QUERY_LAST_TOKEN)
495 if (res == Token.WHERE && !handle_where && query_parsing == 0)
501 public Location Location {
502 get { return current_location; }
505 void define (string def)
507 if (!RootContext.AllDefines.Contains (def)){
508 RootContext.AllDefines [def] = true;
510 if (defines.Contains (def))
512 defines [def] = true;
515 public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
517 this.ref_name = file;
518 this.file_name = file;
524 defines = new Hashtable ();
525 foreach (string def in defs)
529 xml_comment_buffer = new StringBuilder ();
532 // FIXME: This could be `Location.Push' but we have to
533 // find out why the MS compiler allows this
535 Mono.CSharp.Location.Push (file);
538 static bool is_identifier_start_character (char c)
540 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
543 static bool is_identifier_part_character (char c)
545 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') ||
546 Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
549 public static bool IsKeyword (string s)
551 return keyword_strings [s] != null;
555 // Tests whether '(' is beggining of lambda parameters
557 bool IsLambdaOpenParens ()
560 while ((ntoken = xtoken ()) != Token.EOF) {
562 case Token.CLOSE_PARENS:
563 return xtoken () == Token.ARROW;
566 case Token.SEMICOLON:
567 case Token.OPEN_BRACE:
568 case Token.OPEN_PARENS:
569 case Token.LITERAL_STRING:
574 Error_TokenExpected (",' or `)");
578 public static bool IsValidIdentifier (string s)
580 if (s == null || s.Length == 0)
583 if (!is_identifier_start_character (s [0]))
586 for (int i = 1; i < s.Length; i ++)
587 if (! is_identifier_part_character (s [i]))
593 bool parse_less_than ()
596 int the_token = token ();
597 if (the_token == Token.OPEN_BRACKET) {
599 the_token = token ();
600 } while (the_token != Token.CLOSE_BRACKET);
601 the_token = token ();
604 case Token.IDENTIFIER:
627 the_token = token ();
629 if (the_token == Token.OP_GENERICS_GT)
631 else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
633 else if (the_token == Token.INTERR || the_token == Token.STAR)
635 else if (the_token == Token.OP_GENERICS_LT) {
636 if (!parse_less_than ())
639 } else if (the_token == Token.OPEN_BRACKET) {
641 the_token = token ();
642 if (the_token == Token.CLOSE_BRACKET)
644 else if (the_token == Token.COMMA)
645 goto rank_specifiers;
652 public void PutbackNullable ()
654 if (nullable_pos < 0)
655 throw new Exception ();
659 reader.Position = nullable_pos;
664 public void PutbackCloseParens ()
670 int nullable_pos = -1;
672 public void CheckNullable (bool is_nullable)
675 nullable_pos = reader.Position;
680 bool parse_generic_dimension (out int dimension)
685 int the_token = token ();
686 if (the_token == Token.OP_GENERICS_GT)
688 else if (the_token == Token.COMMA) {
696 public int peek_token ()
701 the_token = token ();
707 int parsing_generic_less_than = 0;
709 int is_punct (char c, ref bool doread)
719 return Token.OPEN_BRACE;
722 return Token.CLOSE_BRACE;
724 // To block doccomment inside attribute declaration.
725 if (doc_state == XmlCommentState.Allowed)
726 doc_state = XmlCommentState.NotAllowed;
727 return Token.OPEN_BRACKET;
729 return Token.CLOSE_BRACKET;
731 if (!lambda_arguments_parsing) {
732 lambda_arguments_parsing = true;
734 bool lambda_start = IsLambdaOpenParens ();
736 lambda_arguments_parsing = false;
738 if (RootContext.Version <= LanguageVersion.ISO_2)
739 Report.FeatureIsNotAvailable (Location, "lambda expressions");
741 return Token.OPEN_PARENS_LAMBDA;
744 return Token.OPEN_PARENS;
746 if (deambiguate_close_parens == 0)
747 return Token.CLOSE_PARENS;
749 --deambiguate_close_parens;
753 int new_token = xtoken ();
757 if (new_token == Token.OPEN_PARENS)
758 return Token.CLOSE_PARENS_OPEN_PARENS;
759 else if (new_token == Token.MINUS)
760 return Token.CLOSE_PARENS_MINUS;
761 else if (IsCastToken (new_token))
762 return Token.CLOSE_PARENS_CAST;
764 return Token.CLOSE_PARENS_NO_CAST;
771 return Token.SEMICOLON;
779 return Token.OP_COALESCING;
785 if (parsing_generic_less_than++ > 0)
786 return Token.OP_GENERICS_LT;
791 if (parse_generic_dimension (out dimension)) {
794 return Token.GENERIC_DIMENSION;
799 // Save current position and parse next token.
801 bool is_generic_lt = parse_less_than ();
805 return Token.OP_GENERICS_LT;
807 parsing_generic_less_than = 0;
816 return Token.OP_SHIFT_LEFT_ASSIGN;
818 return Token.OP_SHIFT_LEFT;
819 } else if (d == '='){
824 } else if (c == '>') {
825 if (parsing_generic_less_than > 0) {
826 parsing_generic_less_than--;
827 return Token.OP_GENERICS_GT;
837 return Token.OP_SHIFT_RIGHT_ASSIGN;
839 return Token.OP_SHIFT_RIGHT;
840 } else if (d == '='){
855 t = Token.OP_ADD_ASSIGN;
869 t = Token.OP_SUB_ASSIGN;
907 } else if (d == '='){
909 return Token.OP_AND_ASSIGN;
912 return Token.BITWISE_AND;
919 } else if (d == '='){
921 return Token.OP_OR_ASSIGN;
923 return Token.BITWISE_OR;
929 return Token.OP_MULT_ASSIGN;
938 return Token.OP_DIV_ASSIGN;
946 return Token.OP_MOD_ASSIGN;
948 return Token.PERCENT;
954 return Token.OP_XOR_ASSIGN;
962 return Token.DOUBLE_COLON;
971 int deambiguate_close_parens = 0;
973 public void Deambiguate_CloseParens (object expression)
977 // When any binary operation, a conditional is used we are sure it is not a cast
980 if (expression is Binary || expression is Conditional)
983 deambiguate_close_parens++;
986 bool decimal_digits (int c)
989 bool seen_digits = false;
992 if (number_pos == max_number_size)
993 Error_NumericConstantTooLong ();
994 number_builder [number_pos++] = (char) c;
998 // We use peek_char2, because decimal_digits needs to do a
999 // 2-character look-ahead (5.ToString for example).
1001 while ((d = peek_char2 ()) != -1){
1002 if (d >= '0' && d <= '9'){
1003 if (number_pos == max_number_size)
1004 Error_NumericConstantTooLong ();
1005 number_builder [number_pos++] = (char) d;
1015 static bool is_hex (int e)
1017 return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1020 static int real_type_suffix (int c)
1026 t = Token.LITERAL_FLOAT;
1029 t = Token.LITERAL_DOUBLE;
1032 t= Token.LITERAL_DECIMAL;
1040 int integer_type_suffix (ulong ul, int c)
1042 bool is_unsigned = false;
1043 bool is_long = false;
1046 bool scanning = true;
1059 // if we have not seen anything in between
1060 // report this error
1062 Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1065 // This goto statement causes the MS CLR 2.0 beta 1 csc to report an error, so
1066 // work around that.
1090 if (is_long && is_unsigned){
1092 return Token.LITERAL_INTEGER;
1093 } else if (is_unsigned){
1094 // uint if possible, or ulong else.
1096 if ((ul & 0xffffffff00000000) == 0)
1100 } else if (is_long){
1101 // long if possible, ulong otherwise
1102 if ((ul & 0x8000000000000000) != 0)
1107 // int, uint, long or ulong in that order
1108 if ((ul & 0xffffffff00000000) == 0){
1109 uint ui = (uint) ul;
1111 if ((ui & 0x80000000) != 0)
1116 if ((ul & 0x8000000000000000) != 0)
1122 return Token.LITERAL_INTEGER;
1126 // given `c' as the next char in the input decide whether
1127 // we need to convert to a special type, and then choose
1128 // the best representation for the integer
1130 int adjust_int (int c)
1133 if (number_pos > 9){
1134 ulong ul = (uint) (number_builder [0] - '0');
1136 for (int i = 1; i < number_pos; i++){
1137 ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1139 return integer_type_suffix (ul, c);
1141 uint ui = (uint) (number_builder [0] - '0');
1143 for (int i = 1; i < number_pos; i++){
1144 ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1146 return integer_type_suffix (ui, c);
1148 } catch (OverflowException) {
1149 error_details = "Integral constant is too large";
1150 Report.Error (1021, Location, error_details);
1152 return Token.LITERAL_INTEGER;
1154 catch (FormatException) {
1155 Report.Error (1013, Location, "Invalid number");
1157 return Token.LITERAL_INTEGER;
1161 int adjust_real (int t)
1163 string s = new String (number_builder, 0, number_pos);
1164 const string error_details = "Floating-point constant is outside the range of type `{0}'";
1167 case Token.LITERAL_DECIMAL:
1169 val = System.Decimal.Parse (s, styles, csharp_format_info);
1170 } catch (OverflowException) {
1172 Report.Error (594, Location, error_details, "decimal");
1175 case Token.LITERAL_FLOAT:
1177 val = float.Parse (s, styles, csharp_format_info);
1178 } catch (OverflowException) {
1180 Report.Error (594, Location, error_details, "float");
1184 case Token.LITERAL_DOUBLE:
1186 t = Token.LITERAL_DOUBLE;
1188 val = System.Double.Parse (s, styles, csharp_format_info);
1189 } catch (OverflowException) {
1191 Report.Error (594, Location, error_details, "double");
1204 while ((d = peek_char ()) != -1){
1206 number_builder [number_pos++] = (char) d;
1212 string s = new String (number_builder, 0, number_pos);
1214 if (number_pos <= 8)
1215 ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1217 ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1218 } catch (OverflowException){
1219 error_details = "Integral constant is too large";
1220 Report.Error (1021, Location, error_details);
1222 return Token.LITERAL_INTEGER;
1224 catch (FormatException) {
1225 Report.Error (1013, Location, "Invalid number");
1227 return Token.LITERAL_INTEGER;
1230 return integer_type_suffix (ul, peek_char ());
1234 // Invoked if we know we have .digits or digits
1236 int is_number (int c)
1238 bool is_real = false;
1243 if (c >= '0' && c <= '9'){
1245 int peek = peek_char ();
1247 if (peek == 'x' || peek == 'X')
1248 return handle_hex ();
1255 // We need to handle the case of
1256 // "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1259 if (decimal_digits ('.')){
1265 return adjust_int (-1);
1269 if (c == 'e' || c == 'E'){
1271 if (number_pos == max_number_size)
1272 Error_NumericConstantTooLong ();
1273 number_builder [number_pos++] = 'e';
1277 if (number_pos == max_number_size)
1278 Error_NumericConstantTooLong ();
1279 number_builder [number_pos++] = '+';
1281 } else if (c == '-') {
1282 if (number_pos == max_number_size)
1283 Error_NumericConstantTooLong ();
1284 number_builder [number_pos++] = '-';
1287 if (number_pos == max_number_size)
1288 Error_NumericConstantTooLong ();
1289 number_builder [number_pos++] = '+';
1296 type = real_type_suffix (c);
1297 if (type == Token.NONE && !is_real){
1299 return adjust_int (c);
1303 if (type == Token.NONE){
1308 return adjust_real (type);
1310 Console.WriteLine ("This should not be reached");
1311 throw new Exception ("Is Number should never reach this point");
1315 // Accepts exactly count (4 or 8) hex, no more no less
1317 int getHex (int count, out bool error)
1322 int top = count != -1 ? count : 4;
1326 for (i = 0; i < top; i++){
1329 if (c >= '0' && c <= '9')
1330 c = (int) c - (int) '0';
1331 else if (c >= 'A' && c <= 'F')
1332 c = (int) c - (int) 'A' + 10;
1333 else if (c >= 'a' && c <= 'f')
1334 c = (int) c - (int) 'a' + 10;
1340 total = (total * 16) + c;
1342 int p = peek_char ();
1345 if (!is_hex ((char)p))
1386 v = getHex (-1, out error);
1391 v = getHex (4, out error);
1396 v = getHex (8, out error);
1401 Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1411 if (putback_char != -1) {
1424 void advance_line ()
1434 if (putback_char != -1)
1435 return putback_char;
1436 putback_char = reader.Read ();
1437 return putback_char;
1442 if (putback_char != -1)
1443 return putback_char;
1444 return reader.Peek ();
1447 void putback (int c)
1449 if (putback_char != -1){
1450 Console.WriteLine ("Col: " + col);
1451 Console.WriteLine ("Row: " + line);
1452 Console.WriteLine ("Name: " + ref_name.Name);
1453 Console.WriteLine ("Current [{0}] putting back [{1}] ", putback_char, c);
1454 throw new Exception ("This should not happen putback on putback");
1456 if (c == '\n' || col == 0) {
1457 // It won't happen though.
1467 public bool advance ()
1469 return peek_char () != -1;
1472 public Object Value {
1478 public Object value ()
1483 static bool IsCastToken (int token)
1488 case Token.IDENTIFIER:
1489 case Token.LITERAL_INTEGER:
1490 case Token.LITERAL_FLOAT:
1491 case Token.LITERAL_DOUBLE:
1492 case Token.LITERAL_DECIMAL:
1493 case Token.LITERAL_CHARACTER:
1494 case Token.LITERAL_STRING:
1497 case Token.DELEGATE:
1507 case Token.UNCHECKED:
1512 // These can be part of a member access
1534 current_token = xtoken ();
1536 if (current_token != Token.DEFAULT)
1537 return current_token;
1542 current_token = Token.ERROR;
1543 else if (c == Token.OPEN_PARENS)
1544 current_token = Token.DEFAULT_OPEN_PARENS;
1545 else if (c == Token.COLON)
1546 current_token = Token.DEFAULT_COLON;
1550 return current_token;
1553 static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
1555 void get_cmd_arg (out string cmd, out string arg)
1559 tokens_seen = false;
1561 static_cmd_arg.Length = 0;
1563 // skip over white space
1564 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1567 while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
1568 if (is_identifier_part_character ((char) c)){
1569 static_cmd_arg.Append ((char) c);
1577 cmd = static_cmd_arg.ToString ();
1579 if (c == '\n' || c == '\r'){
1583 // skip over white space
1584 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1589 } else if (c == '\r'){
1591 } else if (c == -1){
1596 static_cmd_arg.Length = 0;
1597 static_cmd_arg.Append ((char) c);
1599 while ((c = get_char ()) != -1 && (c != '\n') && (c != '\r')){
1600 static_cmd_arg.Append ((char) c);
1603 arg = static_cmd_arg.ToString ();
1607 // Handles the #line directive
1609 bool PreProcessLine (string arg)
1611 if (arg.Length == 0)
1614 if (arg == "default"){
1616 ref_name = file_name;
1617 Location.Push (ref_name);
1619 } else if (arg == "hidden"){
1621 // We ignore #line hidden
1629 if ((pos = arg.IndexOf (' ')) != -1 && pos != 0){
1630 ref_line = System.Int32.Parse (arg.Substring (0, pos));
1633 char [] quotes = { '\"' };
1635 string name = arg.Substring (pos). Trim (quotes);
1636 ref_name = Location.LookupFile (name);
1637 Location.Push (ref_name);
1639 ref_line = System.Int32.Parse (arg);
1649 // Handles #define and #undef
1651 void PreProcessDefinition (bool is_define, string arg, bool caller_is_taking)
1653 if (arg.Length == 0 || arg == "true" || arg == "false"){
1654 Report.Error (1001, Location, "Missing identifer to pre-processor directive");
1658 if (arg.IndexOfAny (simple_whitespaces) != -1){
1659 Error_EndLineExpected ();
1663 if (!is_identifier_start_character (arg [0]))
1664 Report.Error (1001, Location, "Identifier expected: " + arg);
1666 foreach (char c in arg.Substring (1)){
1667 if (!is_identifier_part_character (c)){
1668 Report.Error (1001, Location, "Identifier expected: " + arg);
1673 if (!caller_is_taking)
1677 if (defines == null)
1678 defines = new Hashtable ();
1681 if (defines == null)
1683 if (defines.Contains (arg))
1684 defines.Remove (arg);
1689 /// Handles #pragma directive
1691 void PreProcessPragma (string arg)
1693 const string warning = "warning";
1694 const string w_disable = "warning disable";
1695 const string w_restore = "warning restore";
1697 if (arg == w_disable) {
1698 Report.RegisterWarningRegion (Location).WarningDisable (Location.Row);
1702 if (arg == w_restore) {
1703 Report.RegisterWarningRegion (Location).WarningEnable (Location.Row);
1707 if (arg.StartsWith (w_disable)) {
1708 int[] codes = ParseNumbers (arg.Substring (w_disable.Length));
1709 foreach (int code in codes) {
1711 Report.RegisterWarningRegion (Location).WarningDisable (Location, code);
1716 if (arg.StartsWith (w_restore)) {
1717 int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
1718 Hashtable w_table = Report.warning_ignore_table;
1719 foreach (int code in codes) {
1720 if (w_table != null && w_table.Contains (code))
1721 Report.Warning (1635, 1, Location, String.Format ("Cannot restore warning `CS{0:0000}' because it was disabled globally", code));
1722 Report.RegisterWarningRegion (Location).WarningEnable (Location, code);
1727 if (arg.StartsWith (warning)) {
1728 Report.Warning (1634, 1, Location, "Expected disable or restore");
1732 Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
1735 int[] ParseNumbers (string text)
1737 string[] string_array = text.Split (',');
1738 int[] values = new int [string_array.Length];
1740 foreach (string string_code in string_array) {
1742 values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);
1744 catch (FormatException) {
1745 Report.Warning (1692, 1, Location, "Invalid number");
1751 bool eval_val (string s)
1758 if (defines == null)
1760 if (defines.Contains (s))
1766 bool pp_primary (ref string s)
1775 s = s.Substring (1);
1776 bool val = pp_expr (ref s, false);
1777 if (s.Length > 0 && s [0] == ')'){
1778 s = s.Substring (1);
1781 Error_InvalidDirective ();
1785 if (is_identifier_start_character (c)){
1791 if (is_identifier_part_character (c)){
1795 bool v = eval_val (s.Substring (0, j));
1796 s = s.Substring (j);
1799 bool vv = eval_val (s);
1804 Error_InvalidDirective ();
1808 bool pp_unary (ref string s)
1815 if (len > 1 && s [1] == '='){
1816 Error_InvalidDirective ();
1819 s = s.Substring (1);
1820 return ! pp_primary (ref s);
1822 return pp_primary (ref s);
1824 Error_InvalidDirective ();
1829 bool pp_eq (ref string s)
1831 bool va = pp_unary (ref s);
1837 if (len > 2 && s [1] == '='){
1838 s = s.Substring (2);
1839 return va == pp_unary (ref s);
1841 Error_InvalidDirective ();
1844 } else if (s [0] == '!' && len > 1 && s [1] == '='){
1845 s = s.Substring (2);
1847 return va != pp_unary (ref s);
1856 bool pp_and (ref string s)
1858 bool va = pp_eq (ref s);
1864 if (len > 2 && s [1] == '&'){
1865 s = s.Substring (2);
1866 return (va & pp_and (ref s));
1868 Error_InvalidDirective ();
1877 // Evaluates an expression for `#if' or `#elif'
1879 bool pp_expr (ref string s, bool isTerm)
1881 bool va = pp_and (ref s);
1888 if (len > 2 && s [1] == '|'){
1889 s = s.Substring (2);
1890 return va | pp_expr (ref s, isTerm);
1892 Error_InvalidDirective ();
1897 Error_EndLineExpected ();
1905 bool eval (string s)
1907 bool v = pp_expr (ref s, true);
1916 void Error_NumericConstantTooLong ()
1918 Report.Error (1021, Location, "Numeric constant too long");
1921 void Error_InvalidDirective ()
1923 Report.Error (1517, Location, "Invalid preprocessor directive");
1926 void Error_UnexpectedDirective (string extra)
1930 "Unexpected processor directive (" + extra + ")");
1933 void Error_TokenExpected (string token)
1935 Report.Error (1026, Location, "Expected `{0}'", token);
1938 void Error_TokensSeen ()
1940 Report.Error (1032, Location,
1941 "Cannot define or undefine preprocessor symbols after first token in file");
1944 void Eror_WrongPreprocessorLocation ()
1946 Report.Error (1040, Location,
1947 "Preprocessor directives must appear as the first non-whitespace character on a line");
1950 void Error_EndLineExpected ()
1952 Report.Error (1025, Location, "Single-line comment or end-of-line expected");
1956 // if true, then the code continues processing the code
1957 // if false, the code stays in a loop until another directive is
1959 // When caller_is_taking is false we ignore all directives except the ones
1960 // which can help us to identify where the #if block ends
1961 bool handle_preprocessing_directive (bool caller_is_taking)
1964 bool region_directive = false;
1966 get_cmd_arg (out cmd, out arg);
1968 // Eat any trailing whitespaces and single-line comments
1969 if (arg.IndexOf ("//") != -1)
1970 arg = arg.Substring (0, arg.IndexOf ("//"));
1971 arg = arg.Trim (simple_whitespaces);
1974 // The first group of pre-processing instructions is always processed
1978 region_directive = true;
1983 if (ifstack == null || ifstack.Count == 0){
1984 Error_UnexpectedDirective ("no #region for this #endregion");
1987 int pop = (int) ifstack.Pop ();
1989 if ((pop & REGION) == 0)
1990 Report.Error (1027, Location, "Expected `#endif' directive");
1992 return caller_is_taking;
1995 if (ifstack == null)
1996 ifstack = new Stack (2);
1998 int flags = region_directive ? REGION : 0;
1999 if (ifstack.Count == 0){
2000 flags |= PARENT_TAKING;
2002 int state = (int) ifstack.Peek ();
2003 if ((state & TAKING) != 0) {
2004 flags |= PARENT_TAKING;
2008 if (caller_is_taking && eval (arg)) {
2009 ifstack.Push (flags | TAKING);
2012 ifstack.Push (flags);
2016 if (ifstack == null || ifstack.Count == 0){
2017 Error_UnexpectedDirective ("no #if for this #endif");
2020 pop = (int) ifstack.Pop ();
2022 if ((pop & REGION) != 0)
2023 Report.Error (1038, Location, "#endregion directive expected");
2025 if (arg.Length != 0) {
2026 Error_EndLineExpected ();
2029 if (ifstack.Count == 0)
2032 int state = (int) ifstack.Peek ();
2033 return (state & TAKING) != 0;
2037 if (ifstack == null || ifstack.Count == 0){
2038 Error_UnexpectedDirective ("no #if for this #elif");
2041 int state = (int) ifstack.Pop ();
2043 if ((state & REGION) != 0) {
2044 Report.Error (1038, Location, "#endregion directive expected");
2048 if ((state & ELSE_SEEN) != 0){
2049 Error_UnexpectedDirective ("#elif not valid after #else");
2053 if ((state & TAKING) != 0) {
2058 if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2059 ifstack.Push (state | TAKING);
2063 ifstack.Push (state);
2068 if (ifstack == null || ifstack.Count == 0){
2069 Error_UnexpectedDirective ("no #if for this #else");
2072 int state = (int) ifstack.Peek ();
2074 if ((state & REGION) != 0) {
2075 Report.Error (1038, Location, "#endregion directive expected");
2079 if ((state & ELSE_SEEN) != 0){
2080 Error_UnexpectedDirective ("#else within #else");
2086 if (arg.Length != 0) {
2087 Error_EndLineExpected ();
2092 if ((state & PARENT_TAKING) != 0) {
2093 ret = (state & TAKING) == 0;
2101 ifstack.Push (state | ELSE_SEEN);
2106 if (any_token_seen){
2107 Error_TokensSeen ();
2108 return caller_is_taking;
2110 PreProcessDefinition (true, arg, caller_is_taking);
2111 return caller_is_taking;
2114 if (any_token_seen){
2115 Error_TokensSeen ();
2116 return caller_is_taking;
2118 PreProcessDefinition (false, arg, caller_is_taking);
2119 return caller_is_taking;
2123 // These are only processed if we are in a `taking' block
2125 if (!caller_is_taking)
2130 Report.Error (1029, Location, "#error: '" + arg + "'");
2134 Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2138 if (RootContext.Version == LanguageVersion.ISO_1) {
2139 Report.FeatureIsNotAvailable (Location, "#pragma");
2143 PreProcessPragma (arg);
2147 if (!PreProcessLine (arg))
2150 "The line number specified for #line directive is missing or invalid");
2151 return caller_is_taking;
2154 Report.Error (1024, Location, "Wrong preprocessor directive");
2159 private int consume_string (bool quoted)
2162 string_builder.Length = 0;
2165 // No need to parse full string when parsing lambda arguments
2167 if (lambda_arguments_parsing)
2168 return Token.LITERAL_STRING;
2170 while ((c = get_char ()) != -1){
2172 if (quoted && peek_char () == '"'){
2173 string_builder.Append ((char) c);
2177 val = string_builder.ToString ();
2178 return Token.LITERAL_STRING;
2184 Report.Error (1010, Location, "Newline in constant");
2192 string_builder.Append ((char) c);
2195 Report.Error (1039, Location, "Unterminated string literal");
2199 private int consume_identifier (int s)
2201 int res = consume_identifier (s, false);
2203 if (doc_state == XmlCommentState.Allowed)
2204 doc_state = XmlCommentState.NotAllowed;
2207 case Token.NAMESPACE:
2208 check_incorrect_doc_comment ();
2212 if (res == Token.PARTIAL) {
2213 if (parsing_block > 0) {
2214 val = new LocatedToken (Location, "partial");
2215 return Token.IDENTIFIER;
2218 // Save current position and parse next token.
2221 int next_token = token ();
2222 bool ok = (next_token == Token.CLASS) ||
2223 (next_token == Token.STRUCT) ||
2224 (next_token == Token.INTERFACE) ||
2225 (next_token == Token.VOID);
2230 if (next_token == Token.VOID) {
2231 if (RootContext.Version <= LanguageVersion.ISO_2)
2232 Report.FeatureIsNotAvailable (Location, "partial methods");
2233 } else if (RootContext.Version == LanguageVersion.ISO_1)
2234 Report.FeatureIsNotAvailable (Location, "partial types");
2239 if (next_token < Token.LAST_KEYWORD)
2240 Report.Error (267, Location, "The `partial' modifier can be used only immediately before `class', `struct', `interface', or `void' keyword");
2242 val = new LocatedToken (Location, "partial");
2243 return Token.IDENTIFIER;
2249 private int consume_identifier (int s, bool quoted)
2254 id_builder [0] = (char) s;
2256 current_location = new Location (ref_line, Col);
2258 while ((c = get_char ()) != -1) {
2260 if (is_identifier_part_character ((char) c)){
2261 if (pos == max_id_size){
2262 Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
2266 id_builder [pos++] = (char) c;
2267 // putback_char = -1;
2268 } else if (c == '\\') {
2272 // putback_char = c;
2279 // Optimization: avoids doing the keyword lookup
2280 // on uppercase letters and _
2282 if (!quoted && (s >= 'a' || s == '_')){
2283 int keyword = GetKeyword (id_builder, pos);
2284 if (keyword != -1) {
2291 // Keep identifiers in an array of hashtables to avoid needless
2295 if (identifiers [pos] != null) {
2296 val = identifiers [pos][id_builder];
2298 val = new LocatedToken (Location, (string) val);
2300 escaped_identifiers.Add (val);
2301 return Token.IDENTIFIER;
2305 identifiers [pos] = new CharArrayHashtable (pos);
2307 val = new String (id_builder, 0, pos);
2308 if (RootContext.Version == LanguageVersion.ISO_1) {
2309 for (int i = 1; i < id_builder.Length; i += 3) {
2310 if (id_builder [i] == '_' && (id_builder [i - 1] == '_' || id_builder [i + 1] == '_')) {
2311 Report.Error (1638, Location,
2312 "`{0}': Any identifier with double underscores cannot be used when ISO language version mode is specified", val.ToString ());
2318 char [] chars = new char [pos];
2319 Array.Copy (id_builder, chars, pos);
2321 identifiers [pos] [chars] = val;
2323 val = new LocatedToken (Location, (string) val);
2325 escaped_identifiers.Add (val);
2326 return Token.IDENTIFIER;
2329 public int xtoken ()
2332 bool doread = false;
2335 // Whether we have seen comments on the current line
2336 bool comments_seen = false;
2338 for (;(c = get_char ()) != -1;) {
2340 col = ((col + 8) / 8) * 8;
2344 if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
2348 if (peek_char () != '\n')
2353 any_token_seen |= tokens_seen;
2354 tokens_seen = false;
2355 comments_seen = false;
2359 // Handle double-slash comments.
2361 int d = peek_char ();
2365 if (RootContext.Documentation != null && peek_char () == '/') {
2367 // Don't allow ////.
2368 if ((d = peek_char ()) != '/') {
2369 update_comment_location ();
2370 if (doc_state == XmlCommentState.Allowed)
2371 handle_one_line_xml_comment ();
2372 else if (doc_state == XmlCommentState.NotAllowed)
2373 warn_incorrect_doc_comment ();
2376 while ((d = get_char ()) != -1 && (d != '\n') && d != '\r')
2379 any_token_seen |= tokens_seen;
2380 tokens_seen = false;
2381 comments_seen = false;
2383 } else if (d == '*'){
2385 bool docAppend = false;
2386 if (RootContext.Documentation != null && peek_char () == '*') {
2388 update_comment_location ();
2389 // But when it is /**/, just do nothing.
2390 if (peek_char () == '/') {
2394 if (doc_state == XmlCommentState.Allowed)
2396 else if (doc_state == XmlCommentState.NotAllowed)
2397 warn_incorrect_doc_comment ();
2400 int current_comment_start = 0;
2402 current_comment_start = xml_comment_buffer.Length;
2403 xml_comment_buffer.Append (Environment.NewLine);
2406 Location start_location = Location;
2408 while ((d = get_char ()) != -1){
2409 if (d == '*' && peek_char () == '/'){
2411 comments_seen = true;
2415 xml_comment_buffer.Append ((char) d);
2418 any_token_seen |= tokens_seen;
2419 tokens_seen = false;
2421 // Reset 'comments_seen' just to be consistent.
2422 // It doesn't matter either way, here.
2424 comments_seen = false;
2428 Report.Error (1035, start_location, "End-of-file found, '*/' expected");
2431 update_formatted_doc_comment (current_comment_start);
2434 goto is_punct_label;
2438 if (c == '\\' || is_identifier_start_character ((char)c)){
2440 return consume_identifier (c);
2444 current_location = new Location (ref_line, Col);
2445 if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
2455 any_token_seen |= tokens_seen;
2456 tokens_seen = false;
2457 comments_seen = false;
2461 if (c >= '0' && c <= '9'){
2463 return is_number (c);
2468 int peek = peek_char ();
2469 if (peek >= '0' && peek <= '9')
2470 return is_number (c);
2475 if (tokens_seen || comments_seen) {
2476 Eror_WrongPreprocessorLocation ();
2480 if (handle_preprocessing_directive (true))
2483 bool directive_expected = false;
2484 while ((c = get_char ()) != -1) {
2486 directive_expected = true;
2487 } else if (!directive_expected) {
2488 // TODO: Implement comment support for disabled code and uncomment this code
2490 // Eror_WrongPreprocessorLocation ();
2491 // return Token.ERROR;
2496 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || c == '\v' )
2500 if (handle_preprocessing_directive (false))
2503 directive_expected = false;
2507 tokens_seen = false;
2515 return consume_string (false);
2521 error_details = "Empty character literal";
2522 Report.Error (1011, Location, error_details);
2525 if (c == '\r' || c == '\n') {
2526 Report.Error (1010, Location, "Newline in constant");
2532 val = new System.Char ();
2537 error_details = "Too many characters in character literal";
2538 Report.Error (1012, Location, error_details);
2540 // Try to recover, read until newline or next "'"
2541 while ((c = get_char ()) != -1){
2550 return Token.LITERAL_CHARACTER;
2557 return consume_string (true);
2558 } else if (is_identifier_start_character ((char) c)){
2559 return consume_identifier (c, true);
2561 Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
2565 error_details = ((char)c).ToString ();
2574 // Handles one line xml comment
2576 private void handle_one_line_xml_comment ()
2579 while ((c = peek_char ()) == ' ')
2580 get_char (); // skip heading whitespaces.
2581 while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
2582 xml_comment_buffer.Append ((char) get_char ());
2584 if (c == '\r' || c == '\n')
2585 xml_comment_buffer.Append (Environment.NewLine);
2589 // Remove heading "*" in Javadoc-like xml documentation.
2591 private void update_formatted_doc_comment (int current_comment_start)
2593 int length = xml_comment_buffer.Length - current_comment_start;
2594 string [] lines = xml_comment_buffer.ToString (
2595 current_comment_start,
2596 length).Replace ("\r", "").Split ('\n');
2598 // The first line starts with /**, thus it is not target
2599 // for the format check.
2600 for (int i = 1; i < lines.Length; i++) {
2601 string s = lines [i];
2602 int idx = s.IndexOf ('*');
2605 if (i < lines.Length - 1)
2609 head = s.Substring (0, idx);
2610 foreach (char c in head)
2613 lines [i] = s.Substring (idx + 1);
2615 xml_comment_buffer.Remove (current_comment_start, length);
2616 xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
2620 // Updates current comment location.
2622 private void update_comment_location ()
2624 if (current_comment_location.IsNull) {
2625 // "-2" is for heading "//" or "/*"
2626 current_comment_location =
2627 new Location (ref_line, col - 2);
2632 // Checks if there was incorrect doc comments and raise
2635 public void check_incorrect_doc_comment ()
2637 if (xml_comment_buffer.Length > 0)
2638 warn_incorrect_doc_comment ();
2642 // Raises a warning when tokenizer found incorrect doccomment
2645 private void warn_incorrect_doc_comment ()
2647 if (doc_state != XmlCommentState.Error) {
2648 doc_state = XmlCommentState.Error;
2649 // in csc, it is 'XML comment is not placed on
2650 // a valid language element'. But that does not
2652 Report.Warning (1587, 2, Location, "XML comment is not placed on a valid language element");
2657 // Consumes the saved xml comment lines (if any)
2658 // as for current target member or type.
2660 public string consume_doc_comment ()
2662 if (xml_comment_buffer.Length > 0) {
2663 string ret = xml_comment_buffer.ToString ();
2664 reset_doc_comment ();
2670 void reset_doc_comment ()
2672 xml_comment_buffer.Length = 0;
2673 current_comment_location = Location.Null;
2676 public void cleanup ()
2678 if (ifstack != null && ifstack.Count >= 1) {
2679 current_location = new Location (ref_line, Col);
2680 int state = (int) ifstack.Pop ();
2681 if ((state & REGION) != 0)
2682 Report.Error (1038, Location, "#endregion directive expected");
2684 Report.Error (1027, Location, "Expected `#endif' directive");
2690 // Indicates whether it accepts XML documentation or not.
2692 public enum XmlCommentState {
2693 // comment is allowed in this state.
2695 // comment is not allowed in this state.
2697 // once comments appeared when it is NotAllowed, then the
2698 // state is changed to it, until the state is changed to