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 // Licensed under the terms of the GNU GPL
10 // (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
11 // (C) 2004 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);
243 public int putback_char;
244 public int previous_col;
245 public Stack ifstack;
246 public int parsing_generic_less_than;
247 public int current_token;
249 public Position (Tokenizer t)
251 position = t.reader.Position;
252 ref_line = t.ref_line;
254 putback_char = t.putback_char;
255 previous_col = t.previous_col;
256 if (t.ifstack != null && t.ifstack.Count != 0)
257 ifstack = (Stack)t.ifstack.Clone ();
258 parsing_generic_less_than = t.parsing_generic_less_than;
259 current_token = t.current_token;
263 public void PushPosition ()
265 position_stack.Push (new Position (this));
268 public void PopPosition ()
270 Position p = (Position) position_stack.Pop ();
272 reader.Position = p.position;
273 ref_line = p.ref_line;
275 putback_char = p.putback_char;
276 previous_col = p.previous_col;
278 parsing_generic_less_than = p.parsing_generic_less_than;
279 current_token = p.current_token;
282 // Do not reset the position, ignore it.
283 public void DiscardPosition ()
285 position_stack.Pop ();
288 static void AddKeyword (string kw, int token)
290 keyword_strings.Add (kw, kw);
291 if (keywords [kw.Length] == null) {
292 keywords [kw.Length] = new CharArrayHashtable (kw.Length);
294 keywords [kw.Length] [kw.ToCharArray ()] = token;
297 static void InitTokens ()
299 keyword_strings = new Hashtable ();
300 keywords = new CharArrayHashtable [64];
302 AddKeyword ("__arglist", Token.ARGLIST);
303 AddKeyword ("abstract", Token.ABSTRACT);
304 AddKeyword ("as", Token.AS);
305 AddKeyword ("add", Token.ADD);
306 AddKeyword ("assembly", Token.ASSEMBLY);
307 AddKeyword ("base", Token.BASE);
308 AddKeyword ("bool", Token.BOOL);
309 AddKeyword ("break", Token.BREAK);
310 AddKeyword ("byte", Token.BYTE);
311 AddKeyword ("case", Token.CASE);
312 AddKeyword ("catch", Token.CATCH);
313 AddKeyword ("char", Token.CHAR);
314 AddKeyword ("checked", Token.CHECKED);
315 AddKeyword ("class", Token.CLASS);
316 AddKeyword ("const", Token.CONST);
317 AddKeyword ("continue", Token.CONTINUE);
318 AddKeyword ("decimal", Token.DECIMAL);
319 AddKeyword ("default", Token.DEFAULT);
320 AddKeyword ("delegate", Token.DELEGATE);
321 AddKeyword ("do", Token.DO);
322 AddKeyword ("double", Token.DOUBLE);
323 AddKeyword ("else", Token.ELSE);
324 AddKeyword ("enum", Token.ENUM);
325 AddKeyword ("event", Token.EVENT);
326 AddKeyword ("explicit", Token.EXPLICIT);
327 AddKeyword ("extern", Token.EXTERN);
328 AddKeyword ("false", Token.FALSE);
329 AddKeyword ("finally", Token.FINALLY);
330 AddKeyword ("fixed", Token.FIXED);
331 AddKeyword ("float", Token.FLOAT);
332 AddKeyword ("for", Token.FOR);
333 AddKeyword ("foreach", Token.FOREACH);
334 AddKeyword ("goto", Token.GOTO);
335 AddKeyword ("get", Token.GET);
336 AddKeyword ("if", Token.IF);
337 AddKeyword ("implicit", Token.IMPLICIT);
338 AddKeyword ("in", Token.IN);
339 AddKeyword ("int", Token.INT);
340 AddKeyword ("interface", Token.INTERFACE);
341 AddKeyword ("internal", Token.INTERNAL);
342 AddKeyword ("is", Token.IS);
343 AddKeyword ("lock", Token.LOCK);
344 AddKeyword ("long", Token.LONG);
345 AddKeyword ("namespace", Token.NAMESPACE);
346 AddKeyword ("new", Token.NEW);
347 AddKeyword ("null", Token.NULL);
348 AddKeyword ("object", Token.OBJECT);
349 AddKeyword ("operator", Token.OPERATOR);
350 AddKeyword ("out", Token.OUT);
351 AddKeyword ("override", Token.OVERRIDE);
352 AddKeyword ("params", Token.PARAMS);
353 AddKeyword ("private", Token.PRIVATE);
354 AddKeyword ("protected", Token.PROTECTED);
355 AddKeyword ("public", Token.PUBLIC);
356 AddKeyword ("readonly", Token.READONLY);
357 AddKeyword ("ref", Token.REF);
358 AddKeyword ("remove", Token.REMOVE);
359 AddKeyword ("return", Token.RETURN);
360 AddKeyword ("sbyte", Token.SBYTE);
361 AddKeyword ("sealed", Token.SEALED);
362 AddKeyword ("set", Token.SET);
363 AddKeyword ("short", Token.SHORT);
364 AddKeyword ("sizeof", Token.SIZEOF);
365 AddKeyword ("stackalloc", Token.STACKALLOC);
366 AddKeyword ("static", Token.STATIC);
367 AddKeyword ("string", Token.STRING);
368 AddKeyword ("struct", Token.STRUCT);
369 AddKeyword ("switch", Token.SWITCH);
370 AddKeyword ("this", Token.THIS);
371 AddKeyword ("throw", Token.THROW);
372 AddKeyword ("true", Token.TRUE);
373 AddKeyword ("try", Token.TRY);
374 AddKeyword ("typeof", Token.TYPEOF);
375 AddKeyword ("uint", Token.UINT);
376 AddKeyword ("ulong", Token.ULONG);
377 AddKeyword ("unchecked", Token.UNCHECKED);
378 AddKeyword ("unsafe", Token.UNSAFE);
379 AddKeyword ("ushort", Token.USHORT);
380 AddKeyword ("using", Token.USING);
381 AddKeyword ("virtual", Token.VIRTUAL);
382 AddKeyword ("void", Token.VOID);
383 AddKeyword ("volatile", Token.VOLATILE);
384 AddKeyword ("while", Token.WHILE);
385 AddKeyword ("partial", Token.PARTIAL);
386 AddKeyword ("where", Token.WHERE);
389 AddKeyword ("from", Token.FROM);
390 AddKeyword ("join", Token.JOIN);
391 AddKeyword ("on", Token.ON);
392 AddKeyword ("equals", Token.EQUALS);
393 AddKeyword ("select", Token.SELECT);
394 AddKeyword ("group", Token.GROUP);
395 AddKeyword ("by", Token.BY);
396 AddKeyword ("let", Token.LET);
397 AddKeyword ("orderby", Token.ORDERBY);
398 AddKeyword ("ascending", Token.ASCENDING);
399 AddKeyword ("descending", Token.DESCENDING);
400 AddKeyword ("into", Token.INTO);
411 public static void Reset ()
414 csharp_format_info = NumberFormatInfo.InvariantInfo;
415 styles = NumberStyles.Float;
417 string_builder = new System.Text.StringBuilder ();
420 int GetKeyword (char[] id, int id_len)
423 * Keywords are stored in an array of hashtables grouped by their
427 if ((id_len >= keywords.Length) || (keywords [id_len] == null))
429 object o = keywords [id_len] [id];
436 if (!handle_get_set && (res == Token.GET || res == Token.SET))
438 if (!handle_remove_add && (res == Token.REMOVE || res == Token.ADD))
440 if (!handle_assembly && res == Token.ASSEMBLY)
444 // A query expression is any expression that starts with `from identifier'
445 // followed by any token except ; , =
447 if (query_parsing == 0) {
448 if (res == Token.FROM && !lambda_arguments_parsing) {
450 // HACK: to disable generics micro-parser, because PushPosition does not
451 // store identifiers array
452 parsing_generic_less_than = 1;
454 case Token.IDENTIFIER:
466 int next_token = xtoken ();
467 if (next_token == Token.SEMICOLON || next_token == Token.COMMA || next_token == Token.EQUALS)
471 if (RootContext.Version <= LanguageVersion.ISO_2)
472 Report.FeatureIsNotAvailable (Location, "query expressions");
475 Expression.Error_VoidInvalidInTheContext (Location);
479 // HACK: A token is not a keyword so we need to restore identifiers buffer
480 // which has been overwritten before we grabbed the identifier
481 id_builder [0] = 'f'; id_builder [1] = 'r'; id_builder [2] = 'o'; id_builder [3] = 'm';
488 if (res > Token.QUERY_FIRST_TOKEN && res < Token.QUERY_LAST_TOKEN)
492 if (res == Token.WHERE && !handle_where && query_parsing == 0)
498 public Location Location {
499 get { return current_location; }
502 void define (string def)
504 if (!RootContext.AllDefines.Contains (def)){
505 RootContext.AllDefines [def] = true;
507 if (defines.Contains (def))
509 defines [def] = true;
512 public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
514 this.ref_name = file;
515 this.file_name = file;
521 defines = new Hashtable ();
522 foreach (string def in defs)
526 xml_comment_buffer = new StringBuilder ();
529 // FIXME: This could be `Location.Push' but we have to
530 // find out why the MS compiler allows this
532 Mono.CSharp.Location.Push (file);
535 static bool is_identifier_start_character (char c)
537 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
540 static bool is_identifier_part_character (char c)
542 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') ||
543 Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
546 public static bool IsKeyword (string s)
548 return keyword_strings [s] != null;
552 // Tests whether '(' is beggining of lambda parameters
554 bool IsLambdaOpenParens ()
557 while ((ntoken = xtoken ()) != Token.EOF) {
559 case Token.CLOSE_PARENS:
560 return xtoken () == Token.ARROW;
563 case Token.SEMICOLON:
564 case Token.OPEN_BRACE:
565 case Token.OPEN_PARENS:
566 case Token.LITERAL_STRING:
571 Error_TokenExpected (",' or `)");
575 public static bool IsValidIdentifier (string s)
577 if (s == null || s.Length == 0)
580 if (!is_identifier_start_character (s [0]))
583 for (int i = 1; i < s.Length; i ++)
584 if (! is_identifier_part_character (s [i]))
590 bool parse_less_than ()
593 int the_token = token ();
594 if (the_token == Token.OPEN_BRACKET) {
596 the_token = token ();
597 } while (the_token != Token.CLOSE_BRACKET);
598 the_token = token ();
601 case Token.IDENTIFIER:
624 the_token = token ();
626 if (the_token == Token.OP_GENERICS_GT)
628 else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
630 else if (the_token == Token.INTERR || the_token == Token.STAR)
632 else if (the_token == Token.OP_GENERICS_LT) {
633 if (!parse_less_than ())
636 } else if (the_token == Token.OPEN_BRACKET) {
638 the_token = token ();
639 if (the_token == Token.CLOSE_BRACKET)
641 else if (the_token == Token.COMMA)
642 goto rank_specifiers;
649 public void PutbackNullable ()
651 if (nullable_pos < 0)
652 throw new Exception ();
656 reader.Position = nullable_pos;
661 public void PutbackCloseParens ()
667 int nullable_pos = -1;
669 public void CheckNullable (bool is_nullable)
672 nullable_pos = reader.Position;
677 bool parse_generic_dimension (out int dimension)
682 int the_token = token ();
683 if (the_token == Token.OP_GENERICS_GT)
685 else if (the_token == Token.COMMA) {
693 public int peek_token ()
698 the_token = token ();
704 int parsing_generic_less_than = 0;
706 int is_punct (char c, ref bool doread)
716 return Token.OPEN_BRACE;
719 return Token.CLOSE_BRACE;
721 // To block doccomment inside attribute declaration.
722 if (doc_state == XmlCommentState.Allowed)
723 doc_state = XmlCommentState.NotAllowed;
724 return Token.OPEN_BRACKET;
726 return Token.CLOSE_BRACKET;
728 if (!lambda_arguments_parsing) {
729 lambda_arguments_parsing = true;
731 bool lambda_start = IsLambdaOpenParens ();
733 lambda_arguments_parsing = false;
735 if (RootContext.Version <= LanguageVersion.ISO_2)
736 Report.FeatureIsNotAvailable (Location, "lambda expressions");
738 return Token.OPEN_PARENS_LAMBDA;
741 return Token.OPEN_PARENS;
743 if (deambiguate_close_parens == 0)
744 return Token.CLOSE_PARENS;
746 --deambiguate_close_parens;
750 int new_token = xtoken ();
754 if (new_token == Token.OPEN_PARENS)
755 return Token.CLOSE_PARENS_OPEN_PARENS;
756 else if (new_token == Token.MINUS)
757 return Token.CLOSE_PARENS_MINUS;
758 else if (IsCastToken (new_token))
759 return Token.CLOSE_PARENS_CAST;
761 return Token.CLOSE_PARENS_NO_CAST;
768 return Token.SEMICOLON;
776 return Token.OP_COALESCING;
782 if (parsing_generic_less_than++ > 0)
783 return Token.OP_GENERICS_LT;
788 if (parse_generic_dimension (out dimension)) {
791 return Token.GENERIC_DIMENSION;
796 // Save current position and parse next token.
798 bool is_generic_lt = parse_less_than ();
802 return Token.OP_GENERICS_LT;
804 parsing_generic_less_than = 0;
813 return Token.OP_SHIFT_LEFT_ASSIGN;
815 return Token.OP_SHIFT_LEFT;
816 } else if (d == '='){
821 } else if (c == '>') {
822 if (parsing_generic_less_than > 0) {
823 parsing_generic_less_than--;
824 return Token.OP_GENERICS_GT;
834 return Token.OP_SHIFT_RIGHT_ASSIGN;
836 return Token.OP_SHIFT_RIGHT;
837 } else if (d == '='){
852 t = Token.OP_ADD_ASSIGN;
866 t = Token.OP_SUB_ASSIGN;
904 } else if (d == '='){
906 return Token.OP_AND_ASSIGN;
909 return Token.BITWISE_AND;
916 } else if (d == '='){
918 return Token.OP_OR_ASSIGN;
920 return Token.BITWISE_OR;
926 return Token.OP_MULT_ASSIGN;
935 return Token.OP_DIV_ASSIGN;
943 return Token.OP_MOD_ASSIGN;
945 return Token.PERCENT;
951 return Token.OP_XOR_ASSIGN;
959 return Token.DOUBLE_COLON;
968 int deambiguate_close_parens = 0;
970 public void Deambiguate_CloseParens (object expression)
974 // When any binary operation, a conditional is used we are sure it is not a cast
977 if (expression is Binary || expression is Conditional)
980 deambiguate_close_parens++;
983 bool decimal_digits (int c)
986 bool seen_digits = false;
989 if (number_pos == max_number_size)
990 Error_NumericConstantTooLong ();
991 number_builder [number_pos++] = (char) c;
995 // We use peek_char2, because decimal_digits needs to do a
996 // 2-character look-ahead (5.ToString for example).
998 while ((d = peek_char2 ()) != -1){
999 if (d >= '0' && d <= '9'){
1000 if (number_pos == max_number_size)
1001 Error_NumericConstantTooLong ();
1002 number_builder [number_pos++] = (char) d;
1012 static bool is_hex (int e)
1014 return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1017 static int real_type_suffix (int c)
1023 t = Token.LITERAL_FLOAT;
1026 t = Token.LITERAL_DOUBLE;
1029 t= Token.LITERAL_DECIMAL;
1037 int integer_type_suffix (ulong ul, int c)
1039 bool is_unsigned = false;
1040 bool is_long = false;
1043 bool scanning = true;
1056 // if we have not seen anything in between
1057 // report this error
1059 Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1062 // This goto statement causes the MS CLR 2.0 beta 1 csc to report an error, so
1063 // work around that.
1087 if (is_long && is_unsigned){
1089 return Token.LITERAL_INTEGER;
1090 } else if (is_unsigned){
1091 // uint if possible, or ulong else.
1093 if ((ul & 0xffffffff00000000) == 0)
1097 } else if (is_long){
1098 // long if possible, ulong otherwise
1099 if ((ul & 0x8000000000000000) != 0)
1104 // int, uint, long or ulong in that order
1105 if ((ul & 0xffffffff00000000) == 0){
1106 uint ui = (uint) ul;
1108 if ((ui & 0x80000000) != 0)
1113 if ((ul & 0x8000000000000000) != 0)
1119 return Token.LITERAL_INTEGER;
1123 // given `c' as the next char in the input decide whether
1124 // we need to convert to a special type, and then choose
1125 // the best representation for the integer
1127 int adjust_int (int c)
1130 if (number_pos > 9){
1131 ulong ul = (uint) (number_builder [0] - '0');
1133 for (int i = 1; i < number_pos; i++){
1134 ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1136 return integer_type_suffix (ul, c);
1138 uint ui = (uint) (number_builder [0] - '0');
1140 for (int i = 1; i < number_pos; i++){
1141 ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1143 return integer_type_suffix (ui, c);
1145 } catch (OverflowException) {
1146 error_details = "Integral constant is too large";
1147 Report.Error (1021, Location, error_details);
1149 return Token.LITERAL_INTEGER;
1151 catch (FormatException) {
1152 Report.Error (1013, Location, "Invalid number");
1154 return Token.LITERAL_INTEGER;
1158 int adjust_real (int t)
1160 string s = new String (number_builder, 0, number_pos);
1161 const string error_details = "Floating-point constant is outside the range of type `{0}'";
1164 case Token.LITERAL_DECIMAL:
1166 val = System.Decimal.Parse (s, styles, csharp_format_info);
1167 } catch (OverflowException) {
1169 Report.Error (594, Location, error_details, "decimal");
1172 case Token.LITERAL_FLOAT:
1174 val = float.Parse (s, styles, csharp_format_info);
1175 } catch (OverflowException) {
1177 Report.Error (594, Location, error_details, "float");
1181 case Token.LITERAL_DOUBLE:
1183 t = Token.LITERAL_DOUBLE;
1185 val = System.Double.Parse (s, styles, csharp_format_info);
1186 } catch (OverflowException) {
1188 Report.Error (594, Location, error_details, "double");
1201 while ((d = peek_char ()) != -1){
1203 number_builder [number_pos++] = (char) d;
1209 string s = new String (number_builder, 0, number_pos);
1211 if (number_pos <= 8)
1212 ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1214 ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1215 } catch (OverflowException){
1216 error_details = "Integral constant is too large";
1217 Report.Error (1021, Location, error_details);
1219 return Token.LITERAL_INTEGER;
1221 catch (FormatException) {
1222 Report.Error (1013, Location, "Invalid number");
1224 return Token.LITERAL_INTEGER;
1227 return integer_type_suffix (ul, peek_char ());
1231 // Invoked if we know we have .digits or digits
1233 int is_number (int c)
1235 bool is_real = false;
1240 if (c >= '0' && c <= '9'){
1242 int peek = peek_char ();
1244 if (peek == 'x' || peek == 'X')
1245 return handle_hex ();
1252 // We need to handle the case of
1253 // "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1256 if (decimal_digits ('.')){
1262 return adjust_int (-1);
1266 if (c == 'e' || c == 'E'){
1268 if (number_pos == max_number_size)
1269 Error_NumericConstantTooLong ();
1270 number_builder [number_pos++] = 'e';
1274 if (number_pos == max_number_size)
1275 Error_NumericConstantTooLong ();
1276 number_builder [number_pos++] = '+';
1278 } else if (c == '-') {
1279 if (number_pos == max_number_size)
1280 Error_NumericConstantTooLong ();
1281 number_builder [number_pos++] = '-';
1284 if (number_pos == max_number_size)
1285 Error_NumericConstantTooLong ();
1286 number_builder [number_pos++] = '+';
1293 type = real_type_suffix (c);
1294 if (type == Token.NONE && !is_real){
1296 return adjust_int (c);
1300 if (type == Token.NONE){
1305 return adjust_real (type);
1307 Console.WriteLine ("This should not be reached");
1308 throw new Exception ("Is Number should never reach this point");
1312 // Accepts exactly count (4 or 8) hex, no more no less
1314 int getHex (int count, out bool error)
1319 int top = count != -1 ? count : 4;
1323 for (i = 0; i < top; i++){
1326 if (c >= '0' && c <= '9')
1327 c = (int) c - (int) '0';
1328 else if (c >= 'A' && c <= 'F')
1329 c = (int) c - (int) 'A' + 10;
1330 else if (c >= 'a' && c <= 'f')
1331 c = (int) c - (int) 'a' + 10;
1337 total = (total * 16) + c;
1339 int p = peek_char ();
1342 if (!is_hex ((char)p))
1383 v = getHex (-1, out error);
1388 v = getHex (4, out error);
1393 v = getHex (8, out error);
1398 Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1408 if (putback_char != -1) {
1421 void advance_line ()
1431 if (putback_char != -1)
1432 return putback_char;
1433 putback_char = reader.Read ();
1434 return putback_char;
1439 if (putback_char != -1)
1440 return putback_char;
1441 return reader.Peek ();
1444 void putback (int c)
1446 if (putback_char != -1){
1447 Console.WriteLine ("Col: " + col);
1448 Console.WriteLine ("Row: " + line);
1449 Console.WriteLine ("Name: " + ref_name.Name);
1450 Console.WriteLine ("Current [{0}] putting back [{1}] ", putback_char, c);
1451 throw new Exception ("This should not happen putback on putback");
1453 if (c == '\n' || col == 0) {
1454 // It won't happen though.
1464 public bool advance ()
1466 return peek_char () != -1;
1469 public Object Value {
1475 public Object value ()
1480 static bool IsCastToken (int token)
1485 case Token.IDENTIFIER:
1486 case Token.LITERAL_INTEGER:
1487 case Token.LITERAL_FLOAT:
1488 case Token.LITERAL_DOUBLE:
1489 case Token.LITERAL_DECIMAL:
1490 case Token.LITERAL_CHARACTER:
1491 case Token.LITERAL_STRING:
1494 case Token.DELEGATE:
1504 case Token.UNCHECKED:
1509 // These can be part of a member access
1529 current_token = xtoken ();
1531 if (current_token != Token.DEFAULT)
1532 return current_token;
1537 current_token = Token.ERROR;
1538 else if (c == Token.OPEN_PARENS)
1539 current_token = Token.DEFAULT_OPEN_PARENS;
1540 else if (c == Token.COLON)
1541 current_token = Token.DEFAULT_COLON;
1545 return current_token;
1548 static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
1550 void get_cmd_arg (out string cmd, out string arg)
1554 tokens_seen = false;
1556 static_cmd_arg.Length = 0;
1558 // skip over white space
1559 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1562 while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
1563 if (is_identifier_part_character ((char) c)){
1564 static_cmd_arg.Append ((char) c);
1572 cmd = static_cmd_arg.ToString ();
1574 if (c == '\n' || c == '\r'){
1578 // skip over white space
1579 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1584 } else if (c == '\r'){
1586 } else if (c == -1){
1591 static_cmd_arg.Length = 0;
1592 static_cmd_arg.Append ((char) c);
1594 while ((c = get_char ()) != -1 && (c != '\n') && (c != '\r')){
1595 static_cmd_arg.Append ((char) c);
1598 arg = static_cmd_arg.ToString ();
1602 // Handles the #line directive
1604 bool PreProcessLine (string arg)
1606 if (arg.Length == 0)
1609 if (arg == "default"){
1611 ref_name = file_name;
1612 Location.Push (ref_name);
1614 } else if (arg == "hidden"){
1616 // We ignore #line hidden
1624 if ((pos = arg.IndexOf (' ')) != -1 && pos != 0){
1625 ref_line = System.Int32.Parse (arg.Substring (0, pos));
1628 char [] quotes = { '\"' };
1630 string name = arg.Substring (pos). Trim (quotes);
1631 ref_name = Location.LookupFile (name);
1632 file_name.HasLineDirective = true;
1633 ref_name.HasLineDirective = true;
1634 Location.Push (ref_name);
1636 ref_line = System.Int32.Parse (arg);
1646 // Handles #define and #undef
1648 void PreProcessDefinition (bool is_define, string arg, bool caller_is_taking)
1650 if (arg.Length == 0 || arg == "true" || arg == "false"){
1651 Report.Error (1001, Location, "Missing identifer to pre-processor directive");
1655 if (arg.IndexOfAny (simple_whitespaces) != -1){
1656 Error_EndLineExpected ();
1660 if (!is_identifier_start_character (arg [0]))
1661 Report.Error (1001, Location, "Identifier expected: " + arg);
1663 foreach (char c in arg.Substring (1)){
1664 if (!is_identifier_part_character (c)){
1665 Report.Error (1001, Location, "Identifier expected: " + arg);
1670 if (!caller_is_taking)
1674 if (defines == null)
1675 defines = new Hashtable ();
1678 if (defines == null)
1680 if (defines.Contains (arg))
1681 defines.Remove (arg);
1686 /// Handles #pragma directive
1688 void PreProcessPragma (string arg)
1690 const string warning = "warning";
1691 const string w_disable = "warning disable";
1692 const string w_restore = "warning restore";
1694 if (arg == w_disable) {
1695 Report.RegisterWarningRegion (Location).WarningDisable (Location.Row);
1699 if (arg == w_restore) {
1700 Report.RegisterWarningRegion (Location).WarningEnable (Location.Row);
1704 if (arg.StartsWith (w_disable)) {
1705 int[] codes = ParseNumbers (arg.Substring (w_disable.Length));
1706 foreach (int code in codes) {
1708 Report.RegisterWarningRegion (Location).WarningDisable (Location, code);
1713 if (arg.StartsWith (w_restore)) {
1714 int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
1715 Hashtable w_table = Report.warning_ignore_table;
1716 foreach (int code in codes) {
1717 if (w_table != null && w_table.Contains (code))
1718 Report.Warning (1635, 1, Location, String.Format ("Cannot restore warning `CS{0:0000}' because it was disabled globally", code));
1719 Report.RegisterWarningRegion (Location).WarningEnable (Location, code);
1724 if (arg.StartsWith (warning)) {
1725 Report.Warning (1634, 1, Location, "Expected disable or restore");
1729 Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
1732 int[] ParseNumbers (string text)
1734 string[] string_array = text.Split (',');
1735 int[] values = new int [string_array.Length];
1737 foreach (string string_code in string_array) {
1739 values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);
1741 catch (FormatException) {
1742 Report.Warning (1692, 1, Location, "Invalid number");
1748 bool eval_val (string s)
1755 if (defines == null)
1757 if (defines.Contains (s))
1763 bool pp_primary (ref string s)
1772 s = s.Substring (1);
1773 bool val = pp_expr (ref s, false);
1774 if (s.Length > 0 && s [0] == ')'){
1775 s = s.Substring (1);
1778 Error_InvalidDirective ();
1782 if (is_identifier_start_character (c)){
1788 if (is_identifier_part_character (c)){
1792 bool v = eval_val (s.Substring (0, j));
1793 s = s.Substring (j);
1796 bool vv = eval_val (s);
1801 Error_InvalidDirective ();
1805 bool pp_unary (ref string s)
1812 if (len > 1 && s [1] == '='){
1813 Error_InvalidDirective ();
1816 s = s.Substring (1);
1817 return ! pp_primary (ref s);
1819 return pp_primary (ref s);
1821 Error_InvalidDirective ();
1826 bool pp_eq (ref string s)
1828 bool va = pp_unary (ref s);
1834 if (len > 2 && s [1] == '='){
1835 s = s.Substring (2);
1836 return va == pp_unary (ref s);
1838 Error_InvalidDirective ();
1841 } else if (s [0] == '!' && len > 1 && s [1] == '='){
1842 s = s.Substring (2);
1844 return va != pp_unary (ref s);
1853 bool pp_and (ref string s)
1855 bool va = pp_eq (ref s);
1861 if (len > 2 && s [1] == '&'){
1862 s = s.Substring (2);
1863 return (va & pp_and (ref s));
1865 Error_InvalidDirective ();
1874 // Evaluates an expression for `#if' or `#elif'
1876 bool pp_expr (ref string s, bool isTerm)
1878 bool va = pp_and (ref s);
1885 if (len > 2 && s [1] == '|'){
1886 s = s.Substring (2);
1887 return va | pp_expr (ref s, isTerm);
1889 Error_InvalidDirective ();
1894 Error_EndLineExpected ();
1902 bool eval (string s)
1904 bool v = pp_expr (ref s, true);
1913 void Error_NumericConstantTooLong ()
1915 Report.Error (1021, Location, "Numeric constant too long");
1918 void Error_InvalidDirective ()
1920 Report.Error (1517, Location, "Invalid preprocessor directive");
1923 void Error_UnexpectedDirective (string extra)
1927 "Unexpected processor directive (" + extra + ")");
1930 void Error_TokenExpected (string token)
1932 Report.Error (1026, Location, "Expected `{0}'", token);
1935 void Error_TokensSeen ()
1937 Report.Error (1032, Location,
1938 "Cannot define or undefine preprocessor symbols after first token in file");
1941 void Eror_WrongPreprocessorLocation ()
1943 Report.Error (1040, Location,
1944 "Preprocessor directives must appear as the first non-whitespace character on a line");
1947 void Error_EndLineExpected ()
1949 Report.Error (1025, Location, "Single-line comment or end-of-line expected");
1953 // if true, then the code continues processing the code
1954 // if false, the code stays in a loop until another directive is
1956 // When caller_is_taking is false we ignore all directives except the ones
1957 // which can help us to identify where the #if block ends
1958 bool handle_preprocessing_directive (bool caller_is_taking)
1961 bool region_directive = false;
1963 get_cmd_arg (out cmd, out arg);
1965 // Eat any trailing whitespaces and single-line comments
1966 if (arg.IndexOf ("//") != -1)
1967 arg = arg.Substring (0, arg.IndexOf ("//"));
1968 arg = arg.Trim (simple_whitespaces);
1971 // The first group of pre-processing instructions is always processed
1975 region_directive = true;
1980 if (ifstack == null || ifstack.Count == 0){
1981 Error_UnexpectedDirective ("no #region for this #endregion");
1984 int pop = (int) ifstack.Pop ();
1986 if ((pop & REGION) == 0)
1987 Report.Error (1027, Location, "Expected `#endif' directive");
1989 return caller_is_taking;
1992 if (ifstack == null)
1993 ifstack = new Stack (2);
1995 int flags = region_directive ? REGION : 0;
1996 if (ifstack.Count == 0){
1997 flags |= PARENT_TAKING;
1999 int state = (int) ifstack.Peek ();
2000 if ((state & TAKING) != 0) {
2001 flags |= PARENT_TAKING;
2005 if (caller_is_taking && eval (arg)) {
2006 ifstack.Push (flags | TAKING);
2009 ifstack.Push (flags);
2013 if (ifstack == null || ifstack.Count == 0){
2014 Error_UnexpectedDirective ("no #if for this #endif");
2017 pop = (int) ifstack.Pop ();
2019 if ((pop & REGION) != 0)
2020 Report.Error (1038, Location, "#endregion directive expected");
2022 if (arg.Length != 0) {
2023 Error_EndLineExpected ();
2026 if (ifstack.Count == 0)
2029 int state = (int) ifstack.Peek ();
2030 return (state & TAKING) != 0;
2034 if (ifstack == null || ifstack.Count == 0){
2035 Error_UnexpectedDirective ("no #if for this #elif");
2038 int state = (int) ifstack.Pop ();
2040 if ((state & REGION) != 0) {
2041 Report.Error (1038, Location, "#endregion directive expected");
2045 if ((state & ELSE_SEEN) != 0){
2046 Error_UnexpectedDirective ("#elif not valid after #else");
2050 if ((state & TAKING) != 0) {
2055 if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2056 ifstack.Push (state | TAKING);
2060 ifstack.Push (state);
2065 if (ifstack == null || ifstack.Count == 0){
2066 Error_UnexpectedDirective ("no #if for this #else");
2069 int state = (int) ifstack.Peek ();
2071 if ((state & REGION) != 0) {
2072 Report.Error (1038, Location, "#endregion directive expected");
2076 if ((state & ELSE_SEEN) != 0){
2077 Error_UnexpectedDirective ("#else within #else");
2083 if (arg.Length != 0) {
2084 Error_EndLineExpected ();
2089 if ((state & PARENT_TAKING) != 0) {
2090 ret = (state & TAKING) == 0;
2098 ifstack.Push (state | ELSE_SEEN);
2103 if (any_token_seen){
2104 Error_TokensSeen ();
2105 return caller_is_taking;
2107 PreProcessDefinition (true, arg, caller_is_taking);
2108 return caller_is_taking;
2111 if (any_token_seen){
2112 Error_TokensSeen ();
2113 return caller_is_taking;
2115 PreProcessDefinition (false, arg, caller_is_taking);
2116 return caller_is_taking;
2120 // These are only processed if we are in a `taking' block
2122 if (!caller_is_taking)
2127 Report.Error (1029, Location, "#error: '" + arg + "'");
2131 Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2135 if (RootContext.Version == LanguageVersion.ISO_1) {
2136 Report.FeatureIsNotAvailable (Location, "#pragma");
2140 PreProcessPragma (arg);
2144 if (!PreProcessLine (arg))
2147 "The line number specified for #line directive is missing or invalid");
2148 return caller_is_taking;
2151 Report.Error (1024, Location, "Wrong preprocessor directive");
2156 private int consume_string (bool quoted)
2159 string_builder.Length = 0;
2162 // No need to parse full string when parsing lambda arguments
2164 if (lambda_arguments_parsing)
2165 return Token.LITERAL_STRING;
2167 while ((c = get_char ()) != -1){
2169 if (quoted && peek_char () == '"'){
2170 string_builder.Append ((char) c);
2174 val = string_builder.ToString ();
2175 return Token.LITERAL_STRING;
2181 Report.Error (1010, Location, "Newline in constant");
2189 string_builder.Append ((char) c);
2192 Report.Error (1039, Location, "Unterminated string literal");
2196 private int consume_identifier (int s)
2198 int res = consume_identifier (s, false);
2200 if (doc_state == XmlCommentState.Allowed)
2201 doc_state = XmlCommentState.NotAllowed;
2204 case Token.NAMESPACE:
2205 check_incorrect_doc_comment ();
2209 if (res == Token.PARTIAL) {
2210 if (parsing_block > 0) {
2211 val = new LocatedToken (Location, "partial");
2212 return Token.IDENTIFIER;
2215 // Save current position and parse next token.
2218 int next_token = token ();
2219 bool ok = (next_token == Token.CLASS) ||
2220 (next_token == Token.STRUCT) ||
2221 (next_token == Token.INTERFACE) ||
2222 (next_token == Token.VOID);
2227 if (next_token == Token.VOID) {
2228 if (RootContext.Version <= LanguageVersion.ISO_2)
2229 Report.FeatureIsNotAvailable (Location, "partial methods");
2230 } else if (RootContext.Version == LanguageVersion.ISO_1)
2231 Report.FeatureIsNotAvailable (Location, "partial types");
2236 if (next_token < Token.LAST_KEYWORD)
2237 Report.Error (267, Location, "The `partial' modifier can be used only immediately before `class', `struct', `interface', or `void' keyword");
2239 val = new LocatedToken (Location, "partial");
2240 return Token.IDENTIFIER;
2246 private int consume_identifier (int s, bool quoted)
2251 id_builder [0] = (char) s;
2253 current_location = new Location (ref_line, Col);
2255 while ((c = get_char ()) != -1) {
2257 if (is_identifier_part_character ((char) c)){
2258 if (pos == max_id_size){
2259 Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
2263 id_builder [pos++] = (char) c;
2264 // putback_char = -1;
2265 } else if (c == '\\') {
2269 // putback_char = c;
2276 // Optimization: avoids doing the keyword lookup
2277 // on uppercase letters and _
2279 if (!quoted && (s >= 'a' || s == '_')){
2280 int keyword = GetKeyword (id_builder, pos);
2281 if (keyword != -1) {
2288 // Keep identifiers in an array of hashtables to avoid needless
2292 if (identifiers [pos] != null) {
2293 val = identifiers [pos][id_builder];
2295 val = new LocatedToken (Location, (string) val);
2297 escaped_identifiers.Add (val);
2298 return Token.IDENTIFIER;
2302 identifiers [pos] = new CharArrayHashtable (pos);
2304 val = new String (id_builder, 0, pos);
2305 if (RootContext.Version == LanguageVersion.ISO_1) {
2306 for (int i = 1; i < id_builder.Length; i += 3) {
2307 if (id_builder [i] == '_' && (id_builder [i - 1] == '_' || id_builder [i + 1] == '_')) {
2308 Report.Error (1638, Location,
2309 "`{0}': Any identifier with double underscores cannot be used when ISO language version mode is specified", val.ToString ());
2315 char [] chars = new char [pos];
2316 Array.Copy (id_builder, chars, pos);
2318 identifiers [pos] [chars] = val;
2320 val = new LocatedToken (Location, (string) val);
2322 escaped_identifiers.Add (val);
2323 return Token.IDENTIFIER;
2326 public int xtoken ()
2329 bool doread = false;
2332 // Whether we have seen comments on the current line
2333 bool comments_seen = false;
2335 for (;(c = get_char ()) != -1;) {
2337 col = ((col + 8) / 8) * 8;
2341 if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
2345 if (peek_char () != '\n')
2350 any_token_seen |= tokens_seen;
2351 tokens_seen = false;
2352 comments_seen = false;
2356 // Handle double-slash comments.
2358 int d = peek_char ();
2362 if (RootContext.Documentation != null && peek_char () == '/') {
2364 // Don't allow ////.
2365 if ((d = peek_char ()) != '/') {
2366 update_comment_location ();
2367 if (doc_state == XmlCommentState.Allowed)
2368 handle_one_line_xml_comment ();
2369 else if (doc_state == XmlCommentState.NotAllowed)
2370 warn_incorrect_doc_comment ();
2373 while ((d = get_char ()) != -1 && (d != '\n') && d != '\r')
2376 any_token_seen |= tokens_seen;
2377 tokens_seen = false;
2378 comments_seen = false;
2380 } else if (d == '*'){
2382 bool docAppend = false;
2383 if (RootContext.Documentation != null && peek_char () == '*') {
2385 update_comment_location ();
2386 // But when it is /**/, just do nothing.
2387 if (peek_char () == '/') {
2391 if (doc_state == XmlCommentState.Allowed)
2393 else if (doc_state == XmlCommentState.NotAllowed)
2394 warn_incorrect_doc_comment ();
2397 int current_comment_start = 0;
2399 current_comment_start = xml_comment_buffer.Length;
2400 xml_comment_buffer.Append (Environment.NewLine);
2403 Location start_location = Location;
2405 while ((d = get_char ()) != -1){
2406 if (d == '*' && peek_char () == '/'){
2408 comments_seen = true;
2412 xml_comment_buffer.Append ((char) d);
2415 any_token_seen |= tokens_seen;
2416 tokens_seen = false;
2418 // Reset 'comments_seen' just to be consistent.
2419 // It doesn't matter either way, here.
2421 comments_seen = false;
2425 Report.Error (1035, start_location, "End-of-file found, '*/' expected");
2428 update_formatted_doc_comment (current_comment_start);
2431 goto is_punct_label;
2435 if (c == '\\' || is_identifier_start_character ((char)c)){
2437 return consume_identifier (c);
2441 current_location = new Location (ref_line, Col);
2442 if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
2452 any_token_seen |= tokens_seen;
2453 tokens_seen = false;
2454 comments_seen = false;
2458 if (c >= '0' && c <= '9'){
2460 return is_number (c);
2465 int peek = peek_char ();
2466 if (peek >= '0' && peek <= '9')
2467 return is_number (c);
2472 if (tokens_seen || comments_seen) {
2473 Eror_WrongPreprocessorLocation ();
2477 if (handle_preprocessing_directive (true))
2480 bool directive_expected = false;
2481 while ((c = get_char ()) != -1) {
2483 directive_expected = true;
2484 } else if (!directive_expected) {
2485 // TODO: Implement comment support for disabled code and uncomment this code
2487 // Eror_WrongPreprocessorLocation ();
2488 // return Token.ERROR;
2493 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || c == '\v' )
2497 if (handle_preprocessing_directive (false))
2500 directive_expected = false;
2504 tokens_seen = false;
2512 return consume_string (false);
2518 error_details = "Empty character literal";
2519 Report.Error (1011, Location, error_details);
2522 if (c == '\r' || c == '\n') {
2523 Report.Error (1010, Location, "Newline in constant");
2529 val = new System.Char ();
2534 error_details = "Too many characters in character literal";
2535 Report.Error (1012, Location, error_details);
2537 // Try to recover, read until newline or next "'"
2538 while ((c = get_char ()) != -1){
2547 return Token.LITERAL_CHARACTER;
2554 return consume_string (true);
2555 } else if (is_identifier_start_character ((char) c)){
2556 return consume_identifier (c, true);
2558 Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
2562 error_details = ((char)c).ToString ();
2571 // Handles one line xml comment
2573 private void handle_one_line_xml_comment ()
2576 while ((c = peek_char ()) == ' ')
2577 get_char (); // skip heading whitespaces.
2578 while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
2579 xml_comment_buffer.Append ((char) get_char ());
2581 if (c == '\r' || c == '\n')
2582 xml_comment_buffer.Append (Environment.NewLine);
2586 // Remove heading "*" in Javadoc-like xml documentation.
2588 private void update_formatted_doc_comment (int current_comment_start)
2590 int length = xml_comment_buffer.Length - current_comment_start;
2591 string [] lines = xml_comment_buffer.ToString (
2592 current_comment_start,
2593 length).Replace ("\r", "").Split ('\n');
2595 // The first line starts with /**, thus it is not target
2596 // for the format check.
2597 for (int i = 1; i < lines.Length; i++) {
2598 string s = lines [i];
2599 int idx = s.IndexOf ('*');
2602 if (i < lines.Length - 1)
2606 head = s.Substring (0, idx);
2607 foreach (char c in head)
2610 lines [i] = s.Substring (idx + 1);
2612 xml_comment_buffer.Remove (current_comment_start, length);
2613 xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
2617 // Updates current comment location.
2619 private void update_comment_location ()
2621 if (current_comment_location.IsNull) {
2622 // "-2" is for heading "//" or "/*"
2623 current_comment_location =
2624 new Location (ref_line, col - 2);
2629 // Checks if there was incorrect doc comments and raise
2632 public void check_incorrect_doc_comment ()
2634 if (xml_comment_buffer.Length > 0)
2635 warn_incorrect_doc_comment ();
2639 // Raises a warning when tokenizer found incorrect doccomment
2642 private void warn_incorrect_doc_comment ()
2644 if (doc_state != XmlCommentState.Error) {
2645 doc_state = XmlCommentState.Error;
2646 // in csc, it is 'XML comment is not placed on
2647 // a valid language element'. But that does not
2649 Report.Warning (1587, 2, Location, "XML comment is not placed on a valid language element");
2654 // Consumes the saved xml comment lines (if any)
2655 // as for current target member or type.
2657 public string consume_doc_comment ()
2659 if (xml_comment_buffer.Length > 0) {
2660 string ret = xml_comment_buffer.ToString ();
2661 reset_doc_comment ();
2667 void reset_doc_comment ()
2669 xml_comment_buffer.Length = 0;
2670 current_comment_location = Location.Null;
2673 public void cleanup ()
2675 if (ifstack != null && ifstack.Count >= 1) {
2676 current_location = new Location (ref_line, Col);
2677 int state = (int) ifstack.Pop ();
2678 if ((state & REGION) != 0)
2679 Report.Error (1038, Location, "#endregion directive expected");
2681 Report.Error (1027, Location, "Expected `#endif' directive");
2687 // Indicates whether it accepts XML documentation or not.
2689 public enum XmlCommentState {
2690 // comment is allowed in this state.
2692 // comment is not allowed in this state.
2694 // once comments appeared when it is NotAllowed, then the
2695 // state is changed to it, until the state is changed to