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;
53 static bool IsLinqEnabled {
55 return RootContext.Version == LanguageVersion.LINQ;
60 // XML documentation buffer. The save point is used to divide
61 // comments on types and comments on members.
63 StringBuilder xml_comment_buffer;
66 // See comment on XmlCommentState enumeration.
68 XmlCommentState xml_doc_state = XmlCommentState.Allowed;
71 // Whether tokens have been seen on this line
73 bool tokens_seen = false;
76 // Whether a token has been seen on the file
77 // This is needed because `define' is not allowed to be used
78 // after a token has been seen.
80 bool any_token_seen = false;
82 static Hashtable token_values;
83 static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
85 private static Hashtable TokenValueName
88 if (token_values == null)
89 token_values = GetTokenValueNameHash ();
95 private static Hashtable GetTokenValueNameHash ()
97 Type t = typeof (Token);
98 FieldInfo [] fields = t.GetFields ();
99 Hashtable hash = new Hashtable ();
100 foreach (FieldInfo field in fields) {
101 if (field.IsLiteral && field.IsStatic && field.FieldType == typeof (int))
102 hash.Add (field.GetValue (null), field.Name);
108 // Returns a verbose representation of the current location
110 public string location {
114 if (current_token == Token.ERROR)
115 det = "detail: " + error_details;
119 // return "Line: "+line+" Col: "+col + "\n" +
120 // "VirtLine: "+ref_line +
121 // " Token: "+current_token + " " + det;
122 string current_token_name = TokenValueName [current_token] as string;
123 if (current_token_name == null)
124 current_token_name = current_token.ToString ();
126 return String.Format ("{0} ({1},{2}), Token: {3} {4}", ref_name.Name,
134 public bool PropertyParsing {
135 get { return handle_get_set; }
136 set { handle_get_set = value; }
139 public bool AssemblyTargetParsing {
140 get { return handle_assembly; }
141 set { handle_assembly = value; }
144 public bool EventParsing {
145 get { return handle_remove_add; }
146 set { handle_remove_add = value; }
149 public bool ConstraintsParsing {
150 get { return handle_where; }
151 set { handle_where = value; }
154 public bool TypeOfParsing {
155 get { return handle_typeof; }
156 set { handle_typeof = value; }
159 public XmlCommentState doc_state {
160 get { return xml_doc_state; }
162 if (value == XmlCommentState.Allowed) {
163 check_incorrect_doc_comment ();
164 reset_doc_comment ();
166 xml_doc_state = value;
170 public bool IsEscapedIdentifier (Location loc)
172 foreach (LocatedToken lt in escaped_identifiers)
173 if (lt.Location.Equals (loc))
181 static CharArrayHashtable[] keywords;
182 static Hashtable keyword_strings;
183 static NumberStyles styles;
184 static NumberFormatInfo csharp_format_info;
187 // Values for the associated token returned
197 const int TAKING = 1;
198 const int ELSE_SEEN = 4;
199 const int PARENT_TAKING = 8;
200 const int REGION = 16;
203 // pre-processor if stack state:
207 static System.Text.StringBuilder string_builder;
209 const int max_id_size = 512;
210 static char [] id_builder = new char [max_id_size];
212 static CharArrayHashtable [] identifiers = new CharArrayHashtable [max_id_size + 1];
214 const int max_number_size = 512;
215 static char [] number_builder = new char [max_number_size];
216 static int number_pos;
219 // Details about the error encoutered by the tokenizer
221 string error_details;
223 public string error {
225 return error_details;
242 // This is used when the tokenizer needs to save
243 // the current position as it needs to do some parsing
244 // on its own to deamiguate a token in behalf of the
247 Stack position_stack = new Stack (2);
252 public int putback_char;
253 public int previous_col;
254 public Stack ifstack;
255 public int parsing_generic_less_than;
256 public int current_token;
258 public Position (Tokenizer t)
260 position = t.reader.Position;
261 ref_line = t.ref_line;
263 putback_char = t.putback_char;
264 previous_col = t.previous_col;
265 if (t.ifstack != null && t.ifstack.Count != 0)
266 ifstack = (Stack)t.ifstack.Clone ();
267 parsing_generic_less_than = t.parsing_generic_less_than;
268 current_token = t.current_token;
272 public void PushPosition ()
274 position_stack.Push (new Position (this));
277 public void PopPosition ()
279 Position p = (Position) position_stack.Pop ();
281 reader.Position = p.position;
282 ref_line = p.ref_line;
284 putback_char = p.putback_char;
285 previous_col = p.previous_col;
287 parsing_generic_less_than = p.parsing_generic_less_than;
288 current_token = p.current_token;
291 // Do not reset the position, ignore it.
292 public void DiscardPosition ()
294 position_stack.Pop ();
297 static void AddKeyword (string kw, int token)
299 keyword_strings.Add (kw, kw);
300 if (keywords [kw.Length] == null) {
301 keywords [kw.Length] = new CharArrayHashtable (kw.Length);
303 keywords [kw.Length] [kw.ToCharArray ()] = token;
306 static void InitTokens ()
308 keyword_strings = new Hashtable ();
309 keywords = new CharArrayHashtable [64];
311 AddKeyword ("__arglist", Token.ARGLIST);
312 AddKeyword ("abstract", Token.ABSTRACT);
313 AddKeyword ("as", Token.AS);
314 AddKeyword ("add", Token.ADD);
315 AddKeyword ("assembly", Token.ASSEMBLY);
316 AddKeyword ("base", Token.BASE);
317 AddKeyword ("bool", Token.BOOL);
318 AddKeyword ("break", Token.BREAK);
319 AddKeyword ("byte", Token.BYTE);
320 AddKeyword ("case", Token.CASE);
321 AddKeyword ("catch", Token.CATCH);
322 AddKeyword ("char", Token.CHAR);
323 AddKeyword ("checked", Token.CHECKED);
324 AddKeyword ("class", Token.CLASS);
325 AddKeyword ("const", Token.CONST);
326 AddKeyword ("continue", Token.CONTINUE);
327 AddKeyword ("decimal", Token.DECIMAL);
328 AddKeyword ("default", Token.DEFAULT);
329 AddKeyword ("delegate", Token.DELEGATE);
330 AddKeyword ("do", Token.DO);
331 AddKeyword ("double", Token.DOUBLE);
332 AddKeyword ("else", Token.ELSE);
333 AddKeyword ("enum", Token.ENUM);
334 AddKeyword ("event", Token.EVENT);
335 AddKeyword ("explicit", Token.EXPLICIT);
336 AddKeyword ("extern", Token.EXTERN);
337 AddKeyword ("false", Token.FALSE);
338 AddKeyword ("finally", Token.FINALLY);
339 AddKeyword ("fixed", Token.FIXED);
340 AddKeyword ("float", Token.FLOAT);
341 AddKeyword ("for", Token.FOR);
342 AddKeyword ("foreach", Token.FOREACH);
343 AddKeyword ("goto", Token.GOTO);
344 AddKeyword ("get", Token.GET);
345 AddKeyword ("if", Token.IF);
346 AddKeyword ("implicit", Token.IMPLICIT);
347 AddKeyword ("in", Token.IN);
348 AddKeyword ("int", Token.INT);
349 AddKeyword ("interface", Token.INTERFACE);
350 AddKeyword ("internal", Token.INTERNAL);
351 AddKeyword ("is", Token.IS);
352 AddKeyword ("lock", Token.LOCK);
353 AddKeyword ("long", Token.LONG);
354 AddKeyword ("namespace", Token.NAMESPACE);
355 AddKeyword ("new", Token.NEW);
356 AddKeyword ("null", Token.NULL);
357 AddKeyword ("object", Token.OBJECT);
358 AddKeyword ("operator", Token.OPERATOR);
359 AddKeyword ("out", Token.OUT);
360 AddKeyword ("override", Token.OVERRIDE);
361 AddKeyword ("params", Token.PARAMS);
362 AddKeyword ("private", Token.PRIVATE);
363 AddKeyword ("protected", Token.PROTECTED);
364 AddKeyword ("public", Token.PUBLIC);
365 AddKeyword ("readonly", Token.READONLY);
366 AddKeyword ("ref", Token.REF);
367 AddKeyword ("remove", Token.REMOVE);
368 AddKeyword ("return", Token.RETURN);
369 AddKeyword ("sbyte", Token.SBYTE);
370 AddKeyword ("sealed", Token.SEALED);
371 AddKeyword ("set", Token.SET);
372 AddKeyword ("short", Token.SHORT);
373 AddKeyword ("sizeof", Token.SIZEOF);
374 AddKeyword ("stackalloc", Token.STACKALLOC);
375 AddKeyword ("static", Token.STATIC);
376 AddKeyword ("string", Token.STRING);
377 AddKeyword ("struct", Token.STRUCT);
378 AddKeyword ("switch", Token.SWITCH);
379 AddKeyword ("this", Token.THIS);
380 AddKeyword ("throw", Token.THROW);
381 AddKeyword ("true", Token.TRUE);
382 AddKeyword ("try", Token.TRY);
383 AddKeyword ("typeof", Token.TYPEOF);
384 AddKeyword ("uint", Token.UINT);
385 AddKeyword ("ulong", Token.ULONG);
386 AddKeyword ("unchecked", Token.UNCHECKED);
387 AddKeyword ("unsafe", Token.UNSAFE);
388 AddKeyword ("ushort", Token.USHORT);
389 AddKeyword ("using", Token.USING);
390 AddKeyword ("virtual", Token.VIRTUAL);
391 AddKeyword ("void", Token.VOID);
392 AddKeyword ("volatile", Token.VOLATILE);
393 AddKeyword ("while", Token.WHILE);
394 AddKeyword ("partial", Token.PARTIAL);
396 AddKeyword ("where", Token.WHERE);
401 public static void InitializeLinqKeywords ()
403 AddKeyword ("from", Token.FROM);
404 AddKeyword ("join", Token.JOIN);
405 AddKeyword ("on", Token.ON);
406 AddKeyword ("equals", Token.EQUALS);
407 AddKeyword ("select", Token.SELECT);
408 AddKeyword ("group", Token.GROUP);
409 AddKeyword ("by", Token.BY);
410 AddKeyword ("let", Token.LET);
411 AddKeyword ("orderby", Token.ORDERBY);
412 AddKeyword ("ascending", Token.ASCENDING);
413 AddKeyword ("descending", Token.DESCENDING);
414 AddKeyword ("into", Token.INTO);
426 public static void Reset ()
429 csharp_format_info = NumberFormatInfo.InvariantInfo;
430 styles = NumberStyles.Float;
432 string_builder = new System.Text.StringBuilder ();
435 int GetKeyword (char[] id, int id_len)
438 * Keywords are stored in an array of hashtables grouped by their
442 if ((id_len >= keywords.Length) || (keywords [id_len] == null))
444 object o = keywords [id_len] [id];
451 if (!handle_get_set && (res == Token.GET || res == Token.SET))
453 if (!handle_remove_add && (res == Token.REMOVE || res == Token.ADD))
455 if (!handle_assembly && res == Token.ASSEMBLY)
460 // A query expression is any expression that starts with `from identifier'
461 // followed by any token except ; , =
463 if (!query_parsing && res == Token.FROM) {
466 case Token.IDENTIFIER:
478 int next_token = token ();
479 query_parsing = next_token != Token.SEMICOLON && next_token != Token.COMMA &&
480 next_token != Token.EQUALS;
483 Expression.Error_VoidInvalidInTheContext (Location);
489 if (!query_parsing && res > Token.QUERY_FIRST_TOKEN && res < Token.QUERY_LAST_TOKEN)
495 if (!handle_where && res == Token.WHERE)
502 public Location Location {
503 get { return current_location; }
506 void define (string def)
508 if (!RootContext.AllDefines.Contains (def)){
509 RootContext.AllDefines [def] = true;
511 if (defines.Contains (def))
513 defines [def] = true;
516 public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
518 this.ref_name = file;
519 this.file_name = file;
525 defines = new Hashtable ();
526 foreach (string def in defs)
530 xml_comment_buffer = new StringBuilder ();
533 // FIXME: This could be `Location.Push' but we have to
534 // find out why the MS compiler allows this
536 Mono.CSharp.Location.Push (file);
539 static bool is_identifier_start_character (char c)
541 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
544 static bool is_identifier_part_character (char c)
546 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') ||
547 Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
550 public static bool IsKeyword (string s)
552 return keyword_strings [s] != null;
556 // Tests whether '(' is beggining of lambda parameters
558 bool IsLambdaOpenParens ()
561 while ((ntoken = xtoken ()) != Token.EOF) {
563 case Token.CLOSE_PARENS:
564 return xtoken () == Token.ARROW;
567 case Token.SEMICOLON:
568 case Token.OPEN_PARENS:
573 Error_TokenExpected (")");
577 public static bool IsValidIdentifier (string s)
579 if (s == null || s.Length == 0)
582 if (!is_identifier_start_character (s [0]))
585 for (int i = 1; i < s.Length; i ++)
586 if (! is_identifier_part_character (s [i]))
592 bool parse_less_than ()
595 int the_token = token ();
596 if (the_token == Token.OPEN_BRACKET) {
598 the_token = token ();
599 } while (the_token != Token.CLOSE_BRACKET);
600 the_token = token ();
603 case Token.IDENTIFIER:
626 the_token = token ();
628 if (the_token == Token.OP_GENERICS_GT)
630 else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
632 else if (the_token == Token.INTERR || the_token == Token.STAR)
634 else if (the_token == Token.OP_GENERICS_LT) {
635 if (!parse_less_than ())
638 } else if (the_token == Token.OPEN_BRACKET) {
640 the_token = token ();
641 if (the_token == Token.CLOSE_BRACKET)
643 else if (the_token == Token.COMMA)
644 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 public bool QueryParsing {
682 query_parsing = value;
686 bool parse_generic_dimension (out int dimension)
691 int the_token = token ();
692 if (the_token == Token.OP_GENERICS_GT)
694 else if (the_token == Token.COMMA) {
703 public int peek_token ()
708 the_token = token ();
714 int parsing_generic_less_than = 0;
716 int is_punct (char c, ref bool doread)
726 return Token.OPEN_BRACE;
729 return Token.CLOSE_BRACE;
731 // To block doccomment inside attribute declaration.
732 if (doc_state == XmlCommentState.Allowed)
733 doc_state = XmlCommentState.NotAllowed;
734 return Token.OPEN_BRACKET;
736 return Token.CLOSE_BRACKET;
738 if (IsLinqEnabled && !lambda_arguments_parsing) {
739 lambda_arguments_parsing = true;
741 bool lambda_start = IsLambdaOpenParens ();
743 lambda_arguments_parsing = false;
745 return Token.OPEN_PARENS_LAMBDA;
747 return Token.OPEN_PARENS;
749 if (deambiguate_close_parens == 0)
750 return Token.CLOSE_PARENS;
752 --deambiguate_close_parens;
756 int new_token = xtoken ();
760 if (new_token == Token.OPEN_PARENS)
761 return Token.CLOSE_PARENS_OPEN_PARENS;
762 else if (new_token == Token.MINUS)
763 return Token.CLOSE_PARENS_MINUS;
764 else if (IsCastToken (new_token))
765 return Token.CLOSE_PARENS_CAST;
767 return Token.CLOSE_PARENS_NO_CAST;
774 return Token.SEMICOLON;
783 return Token.OP_COALESCING;
790 if (parsing_generic_less_than++ > 0)
791 return Token.OP_GENERICS_LT;
796 if (parse_generic_dimension (out dimension)) {
799 return Token.GENERIC_DIMENSION;
804 // Save current position and parse next token.
806 bool is_generic_lt = parse_less_than ();
810 return Token.OP_GENERICS_LT;
812 parsing_generic_less_than = 0;
821 return Token.OP_SHIFT_LEFT_ASSIGN;
823 return Token.OP_SHIFT_LEFT;
824 } else if (d == '='){
829 } else if (c == '>') {
830 if (parsing_generic_less_than > 0) {
831 parsing_generic_less_than--;
832 return Token.OP_GENERICS_GT;
842 return Token.OP_SHIFT_RIGHT_ASSIGN;
844 return Token.OP_SHIFT_RIGHT;
845 } else if (d == '='){
860 t = Token.OP_ADD_ASSIGN;
874 t = Token.OP_SUB_ASSIGN;
912 } else if (d == '='){
914 return Token.OP_AND_ASSIGN;
917 return Token.BITWISE_AND;
924 } else if (d == '='){
926 return Token.OP_OR_ASSIGN;
928 return Token.BITWISE_OR;
934 return Token.OP_MULT_ASSIGN;
943 return Token.OP_DIV_ASSIGN;
951 return Token.OP_MOD_ASSIGN;
953 return Token.PERCENT;
959 return Token.OP_XOR_ASSIGN;
972 return Token.OP_SHIFT_LEFT_ASSIGN;
974 return Token.OP_SHIFT_LEFT;
975 } else if (d == '='){
989 return Token.OP_SHIFT_RIGHT_ASSIGN;
991 return Token.OP_SHIFT_RIGHT;
992 } else if (d == '='){
1002 return Token.DOUBLE_COLON;
1011 int deambiguate_close_parens = 0;
1013 public void Deambiguate_CloseParens (object expression)
1017 // When any binary operation is used we are sure it is not a cast
1018 if (expression is Binary)
1021 deambiguate_close_parens++;
1024 bool decimal_digits (int c)
1027 bool seen_digits = false;
1030 if (number_pos == max_number_size)
1031 Error_NumericConstantTooLong ();
1032 number_builder [number_pos++] = (char) c;
1036 // We use peek_char2, because decimal_digits needs to do a
1037 // 2-character look-ahead (5.ToString for example).
1039 while ((d = peek_char2 ()) != -1){
1040 if (d >= '0' && d <= '9'){
1041 if (number_pos == max_number_size)
1042 Error_NumericConstantTooLong ();
1043 number_builder [number_pos++] = (char) d;
1053 static bool is_hex (int e)
1055 return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1058 static int real_type_suffix (int c)
1064 t = Token.LITERAL_FLOAT;
1067 t = Token.LITERAL_DOUBLE;
1070 t= Token.LITERAL_DECIMAL;
1078 int integer_type_suffix (ulong ul, int c)
1080 bool is_unsigned = false;
1081 bool is_long = false;
1084 bool scanning = true;
1097 // if we have not seen anything in between
1098 // report this error
1100 Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1103 // This goto statement causes the MS CLR 2.0 beta 1 csc to report an error, so
1104 // work around that.
1128 if (is_long && is_unsigned){
1130 return Token.LITERAL_INTEGER;
1131 } else if (is_unsigned){
1132 // uint if possible, or ulong else.
1134 if ((ul & 0xffffffff00000000) == 0)
1138 } else if (is_long){
1139 // long if possible, ulong otherwise
1140 if ((ul & 0x8000000000000000) != 0)
1145 // int, uint, long or ulong in that order
1146 if ((ul & 0xffffffff00000000) == 0){
1147 uint ui = (uint) ul;
1149 if ((ui & 0x80000000) != 0)
1154 if ((ul & 0x8000000000000000) != 0)
1160 return Token.LITERAL_INTEGER;
1164 // given `c' as the next char in the input decide whether
1165 // we need to convert to a special type, and then choose
1166 // the best representation for the integer
1168 int adjust_int (int c)
1171 if (number_pos > 9){
1172 ulong ul = (uint) (number_builder [0] - '0');
1174 for (int i = 1; i < number_pos; i++){
1175 ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1177 return integer_type_suffix (ul, c);
1179 uint ui = (uint) (number_builder [0] - '0');
1181 for (int i = 1; i < number_pos; i++){
1182 ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1184 return integer_type_suffix (ui, c);
1186 } catch (OverflowException) {
1187 error_details = "Integral constant is too large";
1188 Report.Error (1021, Location, error_details);
1190 return Token.LITERAL_INTEGER;
1192 catch (FormatException) {
1193 Report.Error (1013, Location, "Invalid number");
1195 return Token.LITERAL_INTEGER;
1199 int adjust_real (int t)
1201 string s = new String (number_builder, 0, number_pos);
1202 const string error_details = "Floating-point constant is outside the range of type `{0}'";
1205 case Token.LITERAL_DECIMAL:
1207 val = System.Decimal.Parse (s, styles, csharp_format_info);
1208 } catch (OverflowException) {
1210 Report.Error (594, Location, error_details, "decimal");
1213 case Token.LITERAL_FLOAT:
1215 val = float.Parse (s, styles, csharp_format_info);
1216 } catch (OverflowException) {
1218 Report.Error (594, Location, error_details, "float");
1222 case Token.LITERAL_DOUBLE:
1224 t = Token.LITERAL_DOUBLE;
1226 val = System.Double.Parse (s, styles, csharp_format_info);
1227 } catch (OverflowException) {
1229 Report.Error (594, Location, error_details, "double");
1242 while ((d = peek_char ()) != -1){
1244 number_builder [number_pos++] = (char) d;
1250 string s = new String (number_builder, 0, number_pos);
1252 if (number_pos <= 8)
1253 ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1255 ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1256 } catch (OverflowException){
1257 error_details = "Integral constant is too large";
1258 Report.Error (1021, Location, error_details);
1260 return Token.LITERAL_INTEGER;
1262 catch (FormatException) {
1263 Report.Error (1013, Location, "Invalid number");
1265 return Token.LITERAL_INTEGER;
1268 return integer_type_suffix (ul, peek_char ());
1272 // Invoked if we know we have .digits or digits
1274 int is_number (int c)
1276 bool is_real = false;
1281 if (c >= '0' && c <= '9'){
1283 int peek = peek_char ();
1285 if (peek == 'x' || peek == 'X')
1286 return handle_hex ();
1293 // We need to handle the case of
1294 // "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1297 if (decimal_digits ('.')){
1303 return adjust_int (-1);
1307 if (c == 'e' || c == 'E'){
1309 if (number_pos == max_number_size)
1310 Error_NumericConstantTooLong ();
1311 number_builder [number_pos++] = 'e';
1315 if (number_pos == max_number_size)
1316 Error_NumericConstantTooLong ();
1317 number_builder [number_pos++] = '+';
1319 } else if (c == '-') {
1320 if (number_pos == max_number_size)
1321 Error_NumericConstantTooLong ();
1322 number_builder [number_pos++] = '-';
1325 if (number_pos == max_number_size)
1326 Error_NumericConstantTooLong ();
1327 number_builder [number_pos++] = '+';
1334 type = real_type_suffix (c);
1335 if (type == Token.NONE && !is_real){
1337 return adjust_int (c);
1341 if (type == Token.NONE){
1346 return adjust_real (type);
1348 Console.WriteLine ("This should not be reached");
1349 throw new Exception ("Is Number should never reach this point");
1353 // Accepts exactly count (4 or 8) hex, no more no less
1355 int getHex (int count, out bool error)
1360 int top = count != -1 ? count : 4;
1364 for (i = 0; i < top; i++){
1367 if (c >= '0' && c <= '9')
1368 c = (int) c - (int) '0';
1369 else if (c >= 'A' && c <= 'F')
1370 c = (int) c - (int) 'A' + 10;
1371 else if (c >= 'a' && c <= 'f')
1372 c = (int) c - (int) 'a' + 10;
1378 total = (total * 16) + c;
1380 int p = peek_char ();
1383 if (!is_hex ((char)p))
1424 v = getHex (-1, out error);
1429 v = getHex (4, out error);
1434 v = getHex (8, out error);
1439 Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1449 if (putback_char != -1) {
1467 if (putback_char != -1)
1468 return putback_char;
1469 putback_char = reader.Read ();
1470 return putback_char;
1475 if (putback_char != -1)
1476 return putback_char;
1477 return reader.Peek ();
1480 void putback (int c)
1482 if (putback_char != -1){
1483 Console.WriteLine ("Col: " + col);
1484 Console.WriteLine ("Row: " + line);
1485 Console.WriteLine ("Name: " + ref_name.Name);
1486 Console.WriteLine ("Current [{0}] putting back [{1}] ", putback_char, c);
1487 throw new Exception ("This should not happen putback on putback");
1489 if (c == '\n' || col == 0) {
1490 // It won't happen though.
1500 public bool advance ()
1502 return peek_char () != -1;
1505 public Object Value {
1511 public Object value ()
1516 static bool IsCastToken (int token)
1521 case Token.IDENTIFIER:
1522 case Token.LITERAL_INTEGER:
1523 case Token.LITERAL_FLOAT:
1524 case Token.LITERAL_DOUBLE:
1525 case Token.LITERAL_DECIMAL:
1526 case Token.LITERAL_CHARACTER:
1527 case Token.LITERAL_STRING:
1530 case Token.DELEGATE:
1540 case Token.UNCHECKED:
1547 // These can be part of a member access
1567 current_token = xtoken ();
1570 if (current_token != Token.DEFAULT)
1571 return current_token;
1576 current_token = Token.ERROR;
1577 else if (c == Token.OPEN_PARENS)
1578 current_token = Token.DEFAULT_OPEN_PARENS;
1579 else if (c == Token.COLON)
1580 current_token = Token.DEFAULT_COLON;
1584 return current_token;
1587 static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
1589 void get_cmd_arg (out string cmd, out string arg)
1593 tokens_seen = false;
1595 static_cmd_arg.Length = 0;
1597 // skip over white space
1598 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1601 while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
1602 if (is_identifier_part_character ((char) c)){
1603 static_cmd_arg.Append ((char) c);
1611 cmd = static_cmd_arg.ToString ();
1613 if (c == '\n' || c == '\r'){
1617 // skip over white space
1618 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1623 } else if (c == '\r'){
1625 } else if (c == -1){
1630 static_cmd_arg.Length = 0;
1631 static_cmd_arg.Append ((char) c);
1633 while ((c = get_char ()) != -1 && (c != '\n') && (c != '\r')){
1634 static_cmd_arg.Append ((char) c);
1637 arg = static_cmd_arg.ToString ();
1641 // Handles the #line directive
1643 bool PreProcessLine (string arg)
1645 if (arg.Length == 0)
1648 if (arg == "default"){
1650 ref_name = file_name;
1651 Location.Push (ref_name);
1653 } else if (arg == "hidden"){
1655 // We ignore #line hidden
1663 if ((pos = arg.IndexOf (' ')) != -1 && pos != 0){
1664 ref_line = System.Int32.Parse (arg.Substring (0, pos));
1667 char [] quotes = { '\"' };
1669 string name = arg.Substring (pos). Trim (quotes);
1670 ref_name = Location.LookupFile (name);
1671 file_name.HasLineDirective = true;
1672 ref_name.HasLineDirective = true;
1673 Location.Push (ref_name);
1675 ref_line = System.Int32.Parse (arg);
1685 // Handles #define and #undef
1687 void PreProcessDefinition (bool is_define, string arg, bool caller_is_taking)
1689 if (arg.Length == 0 || arg == "true" || arg == "false"){
1690 Report.Error (1001, Location, "Missing identifer to pre-processor directive");
1694 if (arg.IndexOfAny (simple_whitespaces) != -1){
1695 Error_EndLineExpected ();
1699 if (!is_identifier_start_character (arg [0]))
1700 Report.Error (1001, Location, "Identifier expected: " + arg);
1702 foreach (char c in arg.Substring (1)){
1703 if (!is_identifier_part_character (c)){
1704 Report.Error (1001, Location, "Identifier expected: " + arg);
1709 if (!caller_is_taking)
1713 if (defines == null)
1714 defines = new Hashtable ();
1717 if (defines == null)
1719 if (defines.Contains (arg))
1720 defines.Remove (arg);
1725 /// Handles #pragma directive
1727 void PreProcessPragma (string arg)
1729 const string warning = "warning";
1730 const string w_disable = "warning disable";
1731 const string w_restore = "warning restore";
1733 if (arg == w_disable) {
1734 Report.RegisterWarningRegion (Location).WarningDisable (line);
1738 if (arg == w_restore) {
1739 Report.RegisterWarningRegion (Location).WarningEnable (line);
1743 if (arg.StartsWith (w_disable)) {
1744 int[] codes = ParseNumbers (arg.Substring (w_disable.Length));
1745 foreach (int code in codes) {
1747 Report.RegisterWarningRegion (Location).WarningDisable (Location, code);
1752 if (arg.StartsWith (w_restore)) {
1753 int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
1754 Hashtable w_table = Report.warning_ignore_table;
1755 foreach (int code in codes) {
1756 if (w_table != null && w_table.Contains (code))
1757 Report.Warning (1635, 1, Location, String.Format ("Cannot restore warning `CS{0:0000}' because it was disabled globally", code));
1758 Report.RegisterWarningRegion (Location).WarningEnable (Location, code);
1763 if (arg.StartsWith (warning)) {
1764 Report.Warning (1634, 1, Location, "Expected disable or restore");
1768 Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
1771 int[] ParseNumbers (string text)
1773 string[] string_array = text.Split (',');
1774 int[] values = new int [string_array.Length];
1776 foreach (string string_code in string_array) {
1778 values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);
1780 catch (FormatException) {
1781 Report.Warning (1692, 1, Location, "Invalid number");
1787 bool eval_val (string s)
1794 if (defines == null)
1796 if (defines.Contains (s))
1802 bool pp_primary (ref string s)
1811 s = s.Substring (1);
1812 bool val = pp_expr (ref s, false);
1813 if (s.Length > 0 && s [0] == ')'){
1814 s = s.Substring (1);
1817 Error_InvalidDirective ();
1821 if (is_identifier_start_character (c)){
1827 if (is_identifier_part_character (c)){
1831 bool v = eval_val (s.Substring (0, j));
1832 s = s.Substring (j);
1835 bool vv = eval_val (s);
1840 Error_InvalidDirective ();
1844 bool pp_unary (ref string s)
1851 if (len > 1 && s [1] == '='){
1852 Error_InvalidDirective ();
1855 s = s.Substring (1);
1856 return ! pp_primary (ref s);
1858 return pp_primary (ref s);
1860 Error_InvalidDirective ();
1865 bool pp_eq (ref string s)
1867 bool va = pp_unary (ref s);
1873 if (len > 2 && s [1] == '='){
1874 s = s.Substring (2);
1875 return va == pp_unary (ref s);
1877 Error_InvalidDirective ();
1880 } else if (s [0] == '!' && len > 1 && s [1] == '='){
1881 s = s.Substring (2);
1883 return va != pp_unary (ref s);
1892 bool pp_and (ref string s)
1894 bool va = pp_eq (ref s);
1900 if (len > 2 && s [1] == '&'){
1901 s = s.Substring (2);
1902 return (va & pp_and (ref s));
1904 Error_InvalidDirective ();
1913 // Evaluates an expression for `#if' or `#elif'
1915 bool pp_expr (ref string s, bool isTerm)
1917 bool va = pp_and (ref s);
1924 if (len > 2 && s [1] == '|'){
1925 s = s.Substring (2);
1926 return va | pp_expr (ref s, isTerm);
1928 Error_InvalidDirective ();
1933 Error_EndLineExpected ();
1941 bool eval (string s)
1943 bool v = pp_expr (ref s, true);
1952 void Error_NumericConstantTooLong ()
1954 Report.Error (1021, Location, "Numeric constant too long");
1957 void Error_InvalidDirective ()
1959 Report.Error (1517, Location, "Invalid preprocessor directive");
1962 void Error_UnexpectedDirective (string extra)
1966 "Unexpected processor directive (" + extra + ")");
1969 void Error_TokenExpected (string token)
1971 Report.Error (1026, Location, "Expecting `{0}'", token);
1974 void Error_TokensSeen ()
1976 Report.Error (1032, Location,
1977 "Cannot define or undefine preprocessor symbols after first token in file");
1980 void Eror_WrongPreprocessorLocation ()
1982 Report.Error (1040, Location,
1983 "Preprocessor directives must appear as the first non-whitespace character on a line");
1986 void Error_EndLineExpected ()
1988 Report.Error (1025, Location, "Single-line comment or end-of-line expected");
1992 // if true, then the code continues processing the code
1993 // if false, the code stays in a loop until another directive is
1995 // When caller_is_taking is false we ignore all directives except the ones
1996 // which can help us to identify where the #if block ends
1997 bool handle_preprocessing_directive (bool caller_is_taking)
2000 bool region_directive = false;
2002 get_cmd_arg (out cmd, out arg);
2004 // Eat any trailing whitespaces and single-line comments
2005 if (arg.IndexOf ("//") != -1)
2006 arg = arg.Substring (0, arg.IndexOf ("//"));
2007 arg = arg.Trim (simple_whitespaces);
2010 // The first group of pre-processing instructions is always processed
2014 region_directive = true;
2019 if (ifstack == null || ifstack.Count == 0){
2020 Error_UnexpectedDirective ("no #region for this #endregion");
2023 int pop = (int) ifstack.Pop ();
2025 if ((pop & REGION) == 0)
2026 Report.Error (1027, Location, "Expected `#endif' directive");
2028 return caller_is_taking;
2031 if (ifstack == null)
2032 ifstack = new Stack (2);
2034 int flags = region_directive ? REGION : 0;
2035 if (ifstack.Count == 0){
2036 flags |= PARENT_TAKING;
2038 int state = (int) ifstack.Peek ();
2039 if ((state & TAKING) != 0) {
2040 flags |= PARENT_TAKING;
2044 if (caller_is_taking && eval (arg)) {
2045 ifstack.Push (flags | TAKING);
2048 ifstack.Push (flags);
2052 if (ifstack == null || ifstack.Count == 0){
2053 Error_UnexpectedDirective ("no #if for this #endif");
2056 pop = (int) ifstack.Pop ();
2058 if ((pop & REGION) != 0)
2059 Report.Error (1038, Location, "#endregion directive expected");
2061 if (arg.Length != 0) {
2062 Error_EndLineExpected ();
2065 if (ifstack.Count == 0)
2068 int state = (int) ifstack.Peek ();
2069 return (state & TAKING) != 0;
2073 if (ifstack == null || ifstack.Count == 0){
2074 Error_UnexpectedDirective ("no #if for this #elif");
2077 int state = (int) ifstack.Pop ();
2079 if ((state & REGION) != 0) {
2080 Report.Error (1038, Location, "#endregion directive expected");
2084 if ((state & ELSE_SEEN) != 0){
2085 Error_UnexpectedDirective ("#elif not valid after #else");
2089 if ((state & TAKING) != 0) {
2094 if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2095 ifstack.Push (state | TAKING);
2099 ifstack.Push (state);
2104 if (ifstack == null || ifstack.Count == 0){
2105 Error_UnexpectedDirective ("no #if for this #else");
2108 int state = (int) ifstack.Peek ();
2110 if ((state & REGION) != 0) {
2111 Report.Error (1038, Location, "#endregion directive expected");
2115 if ((state & ELSE_SEEN) != 0){
2116 Error_UnexpectedDirective ("#else within #else");
2122 if (arg.Length != 0) {
2123 Error_EndLineExpected ();
2128 if ((state & PARENT_TAKING) != 0) {
2129 ret = (state & TAKING) == 0;
2137 ifstack.Push (state | ELSE_SEEN);
2142 if (any_token_seen){
2143 Error_TokensSeen ();
2144 return caller_is_taking;
2146 PreProcessDefinition (true, arg, caller_is_taking);
2147 return caller_is_taking;
2150 if (any_token_seen){
2151 Error_TokensSeen ();
2152 return caller_is_taking;
2154 PreProcessDefinition (false, arg, caller_is_taking);
2155 return caller_is_taking;
2159 // These are only processed if we are in a `taking' block
2161 if (!caller_is_taking)
2166 Report.Error (1029, Location, "#error: '" + arg + "'");
2170 Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2174 if (RootContext.Version == LanguageVersion.ISO_1) {
2175 Report.FeatureIsNotISO1 (Location, "#pragma");
2179 PreProcessPragma (arg);
2183 if (!PreProcessLine (arg))
2186 "The line number specified for #line directive is missing or invalid");
2187 return caller_is_taking;
2190 Report.Error (1024, Location, "Wrong preprocessor directive");
2195 private int consume_string (bool quoted)
2198 string_builder.Length = 0;
2200 while ((c = get_char ()) != -1){
2202 if (quoted && peek_char () == '"'){
2203 string_builder.Append ((char) c);
2207 val = string_builder.ToString ();
2208 return Token.LITERAL_STRING;
2214 Report.Error (1010, Location, "Newline in constant");
2222 string_builder.Append ((char) c);
2225 Report.Error (1039, Location, "Unterminated string literal");
2229 private int consume_identifier (int s)
2231 int res = consume_identifier (s, false);
2233 if (doc_state == XmlCommentState.Allowed)
2234 doc_state = XmlCommentState.NotAllowed;
2237 case Token.NAMESPACE:
2238 check_incorrect_doc_comment ();
2242 if (res == Token.PARTIAL) {
2243 if (parsing_block > 0) {
2244 val = new LocatedToken (Location, "partial");
2245 return Token.IDENTIFIER;
2248 // Save current position and parse next token.
2251 int next_token = token ();
2252 bool ok = (next_token == Token.CLASS) ||
2253 (next_token == Token.STRUCT) ||
2254 (next_token == Token.INTERFACE);
2259 if (RootContext.Version == LanguageVersion.ISO_1)
2260 Report.FeatureIsNotISO1 (Location, "partial types");
2265 if (next_token < Token.LAST_KEYWORD)
2266 Report.Error (267, Location, "The `partial' modifier can be used only immediately before keyword `class', `struct', or `interface'");
2268 val = new LocatedToken (Location, "partial");
2269 return Token.IDENTIFIER;
2275 private int consume_identifier (int s, bool quoted)
2280 id_builder [0] = (char) s;
2282 current_location = new Location (ref_line, Col);
2284 while ((c = get_char ()) != -1) {
2286 if (is_identifier_part_character ((char) c)){
2287 if (pos == max_id_size){
2288 Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
2292 id_builder [pos++] = (char) c;
2293 // putback_char = -1;
2294 } else if (c == '\\') {
2298 // putback_char = c;
2305 // Optimization: avoids doing the keyword lookup
2306 // on uppercase letters and _
2308 if (!quoted && (s >= 'a' || s == '_')){
2309 int keyword = GetKeyword (id_builder, pos);
2310 if (keyword != -1) {
2317 // Keep identifiers in an array of hashtables to avoid needless
2321 if (identifiers [pos] != null) {
2322 val = identifiers [pos][id_builder];
2324 val = new LocatedToken (Location, (string) val);
2326 escaped_identifiers.Add (val);
2327 return Token.IDENTIFIER;
2331 identifiers [pos] = new CharArrayHashtable (pos);
2333 val = new String (id_builder, 0, pos);
2334 if (RootContext.Version == LanguageVersion.ISO_1) {
2335 for (int i = 1; i < id_builder.Length; i += 3) {
2336 if (id_builder [i] == '_' && (id_builder [i - 1] == '_' || id_builder [i + 1] == '_')) {
2337 Report.Error (1638, Location,
2338 "`{0}': Any identifier with double underscores cannot be used when ISO language version mode is specified", val.ToString ());
2344 char [] chars = new char [pos];
2345 Array.Copy (id_builder, chars, pos);
2347 identifiers [pos] [chars] = val;
2349 val = new LocatedToken (Location, (string) val);
2351 escaped_identifiers.Add (val);
2352 return Token.IDENTIFIER;
2355 public int xtoken ()
2358 bool doread = false;
2361 // Whether we have seen comments on the current line
2362 bool comments_seen = false;
2364 for (;(c = get_char ()) != -1;) {
2366 col = ((col + 8) / 8) * 8;
2370 if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
2374 if (peek_char () == '\n')
2377 any_token_seen |= tokens_seen;
2378 tokens_seen = false;
2379 comments_seen = false;
2383 // Handle double-slash comments.
2385 int d = peek_char ();
2389 if (RootContext.Documentation != null && peek_char () == '/') {
2391 // Don't allow ////.
2392 if ((d = peek_char ()) != '/') {
2393 update_comment_location ();
2394 if (doc_state == XmlCommentState.Allowed)
2395 handle_one_line_xml_comment ();
2396 else if (doc_state == XmlCommentState.NotAllowed)
2397 warn_incorrect_doc_comment ();
2400 while ((d = get_char ()) != -1 && (d != '\n') && d != '\r')
2403 any_token_seen |= tokens_seen;
2404 tokens_seen = false;
2405 comments_seen = false;
2407 } else if (d == '*'){
2409 bool docAppend = false;
2410 if (RootContext.Documentation != null && peek_char () == '*') {
2412 update_comment_location ();
2413 // But when it is /**/, just do nothing.
2414 if (peek_char () == '/') {
2418 if (doc_state == XmlCommentState.Allowed)
2420 else if (doc_state == XmlCommentState.NotAllowed)
2421 warn_incorrect_doc_comment ();
2424 int current_comment_start = 0;
2426 current_comment_start = xml_comment_buffer.Length;
2427 xml_comment_buffer.Append (Environment.NewLine);
2430 Location start_location = Location;
2432 while ((d = get_char ()) != -1){
2433 if (d == '*' && peek_char () == '/'){
2435 comments_seen = true;
2439 xml_comment_buffer.Append ((char) d);
2442 any_token_seen |= tokens_seen;
2443 tokens_seen = false;
2445 // Reset 'comments_seen' just to be consistent.
2446 // It doesn't matter either way, here.
2448 comments_seen = false;
2452 Report.Error (1035, start_location, "End-of-file found, '*/' expected");
2455 update_formatted_doc_comment (current_comment_start);
2458 goto is_punct_label;
2462 if (c == '\\' || is_identifier_start_character ((char)c)){
2464 return consume_identifier (c);
2468 current_location = new Location (ref_line, Col);
2469 if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
2479 any_token_seen |= tokens_seen;
2480 tokens_seen = false;
2481 comments_seen = false;
2485 if (c >= '0' && c <= '9'){
2487 return is_number (c);
2492 int peek = peek_char ();
2493 if (peek >= '0' && peek <= '9')
2494 return is_number (c);
2499 if (tokens_seen || comments_seen) {
2500 Eror_WrongPreprocessorLocation ();
2504 if (handle_preprocessing_directive (true))
2507 bool directive_expected = false;
2508 while ((c = get_char ()) != -1) {
2510 directive_expected = true;
2511 } else if (!directive_expected) {
2512 // TODO: Implement comment support for disabled code and uncomment this code
2514 // Eror_WrongPreprocessorLocation ();
2515 // return Token.ERROR;
2520 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || c == '\v' )
2524 if (handle_preprocessing_directive (false))
2527 directive_expected = false;
2531 tokens_seen = false;
2539 return consume_string (false);
2545 error_details = "Empty character literal";
2546 Report.Error (1011, Location, error_details);
2549 if (c == '\r' || c == '\n') {
2550 Report.Error (1010, Location, "Newline in constant");
2556 val = new System.Char ();
2561 error_details = "Too many characters in character literal";
2562 Report.Error (1012, Location, error_details);
2564 // Try to recover, read until newline or next "'"
2565 while ((c = get_char ()) != -1){
2574 return Token.LITERAL_CHARACTER;
2581 return consume_string (true);
2582 } else if (is_identifier_start_character ((char) c)){
2583 return consume_identifier (c, true);
2585 Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
2589 error_details = ((char)c).ToString ();
2598 // Handles one line xml comment
2600 private void handle_one_line_xml_comment ()
2603 while ((c = peek_char ()) == ' ')
2604 get_char (); // skip heading whitespaces.
2605 while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
2606 xml_comment_buffer.Append ((char) get_char ());
2608 if (c == '\r' || c == '\n')
2609 xml_comment_buffer.Append (Environment.NewLine);
2613 // Remove heading "*" in Javadoc-like xml documentation.
2615 private void update_formatted_doc_comment (int current_comment_start)
2617 int length = xml_comment_buffer.Length - current_comment_start;
2618 string [] lines = xml_comment_buffer.ToString (
2619 current_comment_start,
2620 length).Replace ("\r", "").Split ('\n');
2622 // The first line starts with /**, thus it is not target
2623 // for the format check.
2624 for (int i = 1; i < lines.Length; i++) {
2625 string s = lines [i];
2626 int idx = s.IndexOf ('*');
2629 if (i < lines.Length - 1)
2633 head = s.Substring (0, idx);
2634 foreach (char c in head)
2637 lines [i] = s.Substring (idx + 1);
2639 xml_comment_buffer.Remove (current_comment_start, length);
2640 xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
2644 // Updates current comment location.
2646 private void update_comment_location ()
2648 if (current_comment_location.IsNull) {
2649 // "-2" is for heading "//" or "/*"
2650 current_comment_location =
2651 new Location (ref_line, col - 2);
2656 // Checks if there was incorrect doc comments and raise
2659 public void check_incorrect_doc_comment ()
2661 if (xml_comment_buffer.Length > 0)
2662 warn_incorrect_doc_comment ();
2666 // Raises a warning when tokenizer found incorrect doccomment
2669 private void warn_incorrect_doc_comment ()
2671 if (doc_state != XmlCommentState.Error) {
2672 doc_state = XmlCommentState.Error;
2673 // in csc, it is 'XML comment is not placed on
2674 // a valid language element'. But that does not
2676 Report.Warning (1587, 2, Location, "XML comment is not placed on a valid language element");
2681 // Consumes the saved xml comment lines (if any)
2682 // as for current target member or type.
2684 public string consume_doc_comment ()
2686 if (xml_comment_buffer.Length > 0) {
2687 string ret = xml_comment_buffer.ToString ();
2688 reset_doc_comment ();
2694 void reset_doc_comment ()
2696 xml_comment_buffer.Length = 0;
2697 current_comment_location = Location.Null;
2700 public void cleanup ()
2702 if (ifstack != null && ifstack.Count >= 1) {
2703 current_location = new Location (ref_line, Col);
2704 int state = (int) ifstack.Pop ();
2705 if ((state & REGION) != 0)
2706 Report.Error (1038, Location, "#endregion directive expected");
2708 Report.Error (1027, Location, "Expected `#endif' directive");
2714 // Indicates whether it accepts XML documentation or not.
2716 public enum XmlCommentState {
2717 // comment is allowed in this state.
2719 // comment is not allowed in this state.
2721 // once comments appeared when it is NotAllowed, then the
2722 // state is changed to it, until the state is changed to