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_constraints = false;
42 bool handle_typeof = false;
44 Location current_location;
45 Location current_comment_location = Location.Null;
46 ArrayList escapedIdentifiers = new ArrayList ();
49 // XML documentation buffer. The save point is used to divide
50 // comments on types and comments on members.
52 StringBuilder xml_comment_buffer;
55 // See comment on XmlCommentState enumeration.
57 XmlCommentState xmlDocState = XmlCommentState.Allowed;
60 // Whether tokens have been seen on this line
62 bool tokens_seen = false;
65 // Whether a token has been seen on the file
66 // This is needed because `define' is not allowed to be used
67 // after a token has been seen.
69 bool any_token_seen = false;
71 static Hashtable tokenValues;
72 static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
74 private static Hashtable TokenValueName
77 if (tokenValues == null)
78 tokenValues = GetTokenValueNameHash ();
84 private static Hashtable GetTokenValueNameHash ()
86 Type t = typeof (Token);
87 FieldInfo [] fields = t.GetFields ();
88 Hashtable hash = new Hashtable ();
89 foreach (FieldInfo field in fields) {
90 if (field.IsLiteral && field.IsStatic && field.FieldType == typeof (int))
91 hash.Add (field.GetValue (null), field.Name);
97 // Returns a verbose representation of the current location
99 public string location {
103 if (current_token == Token.ERROR)
104 det = "detail: " + error_details;
108 // return "Line: "+line+" Col: "+col + "\n" +
109 // "VirtLine: "+ref_line +
110 // " Token: "+current_token + " " + det;
111 string current_token_name = TokenValueName [current_token] as string;
112 if (current_token_name == null)
113 current_token_name = current_token.ToString ();
115 return String.Format ("{0} ({1},{2}), Token: {3} {4}", ref_name.Name,
123 public bool PropertyParsing {
125 return handle_get_set;
129 handle_get_set = value;
133 public bool AssemblyTargetParsing {
135 return handle_assembly;
139 handle_assembly = value;
143 public bool EventParsing {
145 return handle_remove_add;
149 handle_remove_add = value;
153 public bool ConstraintsParsing {
155 return handle_constraints;
159 handle_constraints = value;
163 public bool TypeOfParsing {
165 return handle_typeof;
169 handle_typeof = value;
173 public XmlCommentState doc_state {
174 get { return xmlDocState; }
176 if (value == XmlCommentState.Allowed) {
177 check_incorrect_doc_comment ();
178 reset_doc_comment ();
184 public bool IsEscapedIdentifier (Location loc)
186 foreach (LocatedToken lt in escapedIdentifiers)
187 if (lt.Location.Equals (loc))
195 static CharArrayHashtable[] keywords;
196 static Hashtable keywordStrings = new Hashtable ();
197 static NumberStyles styles;
198 static NumberFormatInfo csharp_format_info;
201 // Values for the associated token returned
211 const int TAKING = 1;
212 const int ELSE_SEEN = 4;
213 const int PARENT_TAKING = 8;
214 const int REGION = 16;
217 // pre-processor if stack state:
221 static System.Text.StringBuilder string_builder;
223 const int max_id_size = 512;
224 static char [] id_builder = new char [max_id_size];
226 static CharArrayHashtable [] identifiers = new CharArrayHashtable [max_id_size + 1];
228 const int max_number_size = 512;
229 static char [] number_builder = new char [max_number_size];
230 static int number_pos;
233 // Details about the error encoutered by the tokenizer
235 string error_details;
237 public string error {
239 return error_details;
256 // This is used when the tokenizer needs to save
257 // the current position as it needs to do some parsing
258 // on its own to deamiguate a token in behalf of the
261 Stack position_stack = new Stack (2);
266 public int putback_char;
267 public int previous_col;
268 public Stack ifstack;
269 public int parsing_generic_less_than;
270 public int current_token;
272 public Position (Tokenizer t)
274 position = t.reader.Position;
275 ref_line = t.ref_line;
277 putback_char = t.putback_char;
278 previous_col = t.previous_col;
279 if (t.ifstack != null && t.ifstack.Count != 0)
280 ifstack = (Stack)t.ifstack.Clone ();
281 parsing_generic_less_than = t.parsing_generic_less_than;
282 current_token = t.current_token;
286 public void PushPosition ()
288 position_stack.Push (new Position (this));
291 public void PopPosition ()
293 Position p = (Position) position_stack.Pop ();
295 reader.Position = p.position;
296 ref_line = p.ref_line;
298 putback_char = p.putback_char;
299 previous_col = p.previous_col;
301 parsing_generic_less_than = p.parsing_generic_less_than;
302 current_token = p.current_token;
305 // Do not reset the position, ignore it.
306 public void DiscardPosition ()
308 position_stack.Pop ();
311 static void AddKeyword (string kw, int token) {
312 keywordStrings.Add (kw, kw);
313 if (keywords [kw.Length] == null) {
314 keywords [kw.Length] = new CharArrayHashtable (kw.Length);
316 keywords [kw.Length] [kw.ToCharArray ()] = token;
319 static void InitTokens ()
321 keywords = new CharArrayHashtable [64];
323 AddKeyword ("__arglist", Token.ARGLIST);
324 AddKeyword ("abstract", Token.ABSTRACT);
325 AddKeyword ("as", Token.AS);
326 AddKeyword ("add", Token.ADD);
327 AddKeyword ("assembly", Token.ASSEMBLY);
328 AddKeyword ("base", Token.BASE);
329 AddKeyword ("bool", Token.BOOL);
330 AddKeyword ("break", Token.BREAK);
331 AddKeyword ("byte", Token.BYTE);
332 AddKeyword ("case", Token.CASE);
333 AddKeyword ("catch", Token.CATCH);
334 AddKeyword ("char", Token.CHAR);
335 AddKeyword ("checked", Token.CHECKED);
336 AddKeyword ("class", Token.CLASS);
337 AddKeyword ("const", Token.CONST);
338 AddKeyword ("continue", Token.CONTINUE);
339 AddKeyword ("decimal", Token.DECIMAL);
340 AddKeyword ("default", Token.DEFAULT);
341 AddKeyword ("delegate", Token.DELEGATE);
342 AddKeyword ("do", Token.DO);
343 AddKeyword ("double", Token.DOUBLE);
344 AddKeyword ("else", Token.ELSE);
345 AddKeyword ("enum", Token.ENUM);
346 AddKeyword ("event", Token.EVENT);
347 AddKeyword ("explicit", Token.EXPLICIT);
348 AddKeyword ("extern", Token.EXTERN);
349 AddKeyword ("false", Token.FALSE);
350 AddKeyword ("finally", Token.FINALLY);
351 AddKeyword ("fixed", Token.FIXED);
352 AddKeyword ("float", Token.FLOAT);
353 AddKeyword ("for", Token.FOR);
354 AddKeyword ("foreach", Token.FOREACH);
355 AddKeyword ("goto", Token.GOTO);
356 AddKeyword ("get", Token.GET);
357 AddKeyword ("if", Token.IF);
358 AddKeyword ("implicit", Token.IMPLICIT);
359 AddKeyword ("in", Token.IN);
360 AddKeyword ("int", Token.INT);
361 AddKeyword ("interface", Token.INTERFACE);
362 AddKeyword ("internal", Token.INTERNAL);
363 AddKeyword ("is", Token.IS);
364 AddKeyword ("lock", Token.LOCK);
365 AddKeyword ("long", Token.LONG);
366 AddKeyword ("namespace", Token.NAMESPACE);
367 AddKeyword ("new", Token.NEW);
368 AddKeyword ("null", Token.NULL);
369 AddKeyword ("object", Token.OBJECT);
370 AddKeyword ("operator", Token.OPERATOR);
371 AddKeyword ("out", Token.OUT);
372 AddKeyword ("override", Token.OVERRIDE);
373 AddKeyword ("params", Token.PARAMS);
374 AddKeyword ("private", Token.PRIVATE);
375 AddKeyword ("protected", Token.PROTECTED);
376 AddKeyword ("public", Token.PUBLIC);
377 AddKeyword ("readonly", Token.READONLY);
378 AddKeyword ("ref", Token.REF);
379 AddKeyword ("remove", Token.REMOVE);
380 AddKeyword ("return", Token.RETURN);
381 AddKeyword ("sbyte", Token.SBYTE);
382 AddKeyword ("sealed", Token.SEALED);
383 AddKeyword ("set", Token.SET);
384 AddKeyword ("short", Token.SHORT);
385 AddKeyword ("sizeof", Token.SIZEOF);
386 AddKeyword ("stackalloc", Token.STACKALLOC);
387 AddKeyword ("static", Token.STATIC);
388 AddKeyword ("string", Token.STRING);
389 AddKeyword ("struct", Token.STRUCT);
390 AddKeyword ("switch", Token.SWITCH);
391 AddKeyword ("this", Token.THIS);
392 AddKeyword ("throw", Token.THROW);
393 AddKeyword ("true", Token.TRUE);
394 AddKeyword ("try", Token.TRY);
395 AddKeyword ("typeof", Token.TYPEOF);
396 AddKeyword ("uint", Token.UINT);
397 AddKeyword ("ulong", Token.ULONG);
398 AddKeyword ("unchecked", Token.UNCHECKED);
399 AddKeyword ("unsafe", Token.UNSAFE);
400 AddKeyword ("ushort", Token.USHORT);
401 AddKeyword ("using", Token.USING);
402 AddKeyword ("virtual", Token.VIRTUAL);
403 AddKeyword ("void", Token.VOID);
404 AddKeyword ("volatile", Token.VOLATILE);
405 AddKeyword ("while", Token.WHILE);
406 AddKeyword ("partial", Token.PARTIAL);
408 AddKeyword ("where", Token.WHERE);
418 csharp_format_info = NumberFormatInfo.InvariantInfo;
419 styles = NumberStyles.Float;
421 string_builder = new System.Text.StringBuilder ();
424 int GetKeyword (char[] id, int id_len)
427 * Keywords are stored in an array of hashtables grouped by their
431 if ((id_len >= keywords.Length) || (keywords [id_len] == null))
433 object o = keywords [id_len] [id];
440 if (handle_get_set == false && (res == Token.GET || res == Token.SET))
442 if (handle_remove_add == false && (res == Token.REMOVE || res == Token.ADD))
444 if (handle_assembly == false && res == Token.ASSEMBLY)
447 if (handle_constraints == false && res == Token.WHERE)
454 public Location Location {
455 get { return current_location; }
458 void define (string def)
460 if (!RootContext.AllDefines.Contains (def)){
461 RootContext.AllDefines [def] = true;
463 if (defines.Contains (def))
465 defines [def] = true;
468 public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
470 this.ref_name = file;
471 this.file_name = file;
472 linq = RootContext.Version == LanguageVersion.LINQ;
478 defines = new Hashtable ();
479 foreach (string def in defs)
483 xml_comment_buffer = new StringBuilder ();
486 // FIXME: This could be `Location.Push' but we have to
487 // find out why the MS compiler allows this
489 Mono.CSharp.Location.Push (file);
492 static bool is_identifier_start_character (char c)
494 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
497 static bool is_identifier_part_character (char c)
499 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') ||
500 Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
503 public static bool IsKeyword (string s)
505 return keywordStrings [s] != null;
508 public static bool IsValidIdentifier (string s)
510 if (s == null || s.Length == 0)
513 if (!is_identifier_start_character (s [0]))
516 for (int i = 1; i < s.Length; i ++)
517 if (! is_identifier_part_character (s [i]))
523 bool parse_generic_dimension (out int dimension)
528 int the_token = token ();
529 if (the_token == Token.OP_GENERICS_GT)
531 else if (the_token == Token.COMMA) {
539 bool parse_less_than ()
542 int the_token = token ();
543 if (the_token == Token.OPEN_BRACKET) {
545 the_token = token ();
546 } while (the_token != Token.CLOSE_BRACKET);
547 the_token = token ();
550 case Token.IDENTIFIER:
573 the_token = token ();
575 if (the_token == Token.OP_GENERICS_GT)
577 else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
579 else if (the_token == Token.INTERR || the_token == Token.STAR)
581 else if (the_token == Token.OP_GENERICS_LT) {
582 if (!parse_less_than ())
585 } else if (the_token == Token.OPEN_BRACKET) {
587 the_token = token ();
588 if (the_token == Token.CLOSE_BRACKET)
590 else if (the_token == Token.COMMA)
591 goto rank_specifiers;
599 public void PutbackNullable ()
601 if (nullable_pos < 0)
602 throw new Exception ();
606 reader.Position = nullable_pos;
611 public void PutbackCloseParens ()
617 int nullable_pos = -1;
619 public void CheckNullable (bool is_nullable)
622 nullable_pos = reader.Position;
628 public int peek_token ()
633 the_token = token ();
639 bool parse_namespace_or_typename (int next)
642 next = peek_token ();
643 while (next == Token.IDENTIFIER){
646 next = peek_token ();
647 if (next == Token.DOT || next == Token.DOUBLE_COLON){
649 next = peek_token ();
652 if (next == Token.OP_GENERICS_LT){
654 if (!parse_less_than ())
664 bool is_simple_type (int token)
666 return (token == Token.BOOL ||
667 token == Token.DECIMAL ||
668 token == Token.SBYTE ||
669 token == Token.BYTE ||
670 token == Token.SHORT ||
671 token == Token.USHORT ||
672 token == Token.INT ||
673 token == Token.UINT ||
674 token == Token.LONG ||
675 token == Token.ULONG ||
676 token == Token.CHAR ||
677 token == Token.FLOAT ||
678 token == Token.DOUBLE);
681 bool is_builtin_reference_type (int token)
683 return (token == Token.OBJECT || token == Token.STRING);
686 bool parse_opt_rank (int next)
689 if (next != Token.OPEN_BRACKET)
695 if (next == Token.CLOSE_BRACKET){
696 next = peek_token ();
699 if (next == Token.COMMA)
709 int next = peek_token ();
711 if (is_simple_type (next)){
713 next = peek_token ();
714 if (next == Token.INTERR)
716 return parse_opt_rank (peek_token ());
718 if (parse_namespace_or_typename (next)){
719 next = peek_token ();
720 if (next == Token.INTERR)
722 return parse_opt_rank (peek_token ());
723 } else if (is_builtin_reference_type (next)){
725 return parse_opt_rank (peek_token ());
732 // Invoked after '(' has been seen and tries to parse:
733 // type identifier [, type identifier]*
735 // if this is the case, instead of returning an
736 // OPEN_PARENS token we return a special token that
737 // triggers lambda parsing.
739 // This is needed because we can not introduce the
740 // explicitly_typed_lambda_parameter_list after a '(' in the
741 // grammar without introducing reduce/reduce conflicts.
743 // We need to parse a type and if it is followed by an
744 // identifier, we know it has to be parsed as a lambda
747 // the type expression can be prefixed with `ref' or `out'
749 public bool parse_lambda_parameters ()
752 int next = peek_token ();
754 if (next == Token.REF || next == Token.OUT)
758 next = peek_token ();
759 if (next == Token.IDENTIFIER){
761 next = peek_token ();
762 if (next == Token.COMMA){
766 if (next == Token.CLOSE_PARENS)
774 int parsing_generic_less_than = 0;
776 int is_punct (char c, ref bool doread)
786 return Token.OPEN_BRACE;
789 return Token.CLOSE_BRACE;
791 // To block doccomment inside attribute declaration.
792 if (doc_state == XmlCommentState.Allowed)
793 doc_state = XmlCommentState.NotAllowed;
794 return Token.OPEN_BRACKET;
796 return Token.CLOSE_BRACKET;
800 bool have_lambda_parameter = parse_lambda_parameters ();
803 if (have_lambda_parameter)
804 return Token.OPEN_PARENS_LAMBDA;
806 return Token.OPEN_PARENS;
808 return Token.OPEN_PARENS;
810 if (deambiguate_close_parens == 0)
811 return Token.CLOSE_PARENS;
813 --deambiguate_close_parens;
817 int new_token = xtoken ();
821 if (new_token == Token.OPEN_PARENS)
822 return Token.CLOSE_PARENS_OPEN_PARENS;
823 else if (new_token == Token.MINUS)
824 return Token.CLOSE_PARENS_MINUS;
825 else if (IsCastToken (new_token))
826 return Token.CLOSE_PARENS_CAST;
828 return Token.CLOSE_PARENS_NO_CAST;
835 return Token.SEMICOLON;
844 if (parsing_generic_less_than++ > 0)
845 return Token.OP_GENERICS_LT;
850 if (parse_generic_dimension (out dimension)) {
853 return Token.GENERIC_DIMENSION;
858 // Save current position and parse next token.
860 bool is_generic_lt = parse_less_than ();
864 return Token.OP_GENERICS_LT;
866 parsing_generic_less_than = 0;
875 return Token.OP_SHIFT_LEFT_ASSIGN;
877 return Token.OP_SHIFT_LEFT;
878 } else if (d == '='){
883 } else if (c == '>') {
884 if (parsing_generic_less_than > 0) {
885 parsing_generic_less_than--;
886 return Token.OP_GENERICS_GT;
896 return Token.OP_SHIFT_RIGHT_ASSIGN;
898 return Token.OP_SHIFT_RIGHT;
899 } else if (d == '='){
914 t = Token.OP_ADD_ASSIGN;
928 t = Token.OP_SUB_ASSIGN;
965 } else if (d == '='){
967 return Token.OP_AND_ASSIGN;
970 return Token.BITWISE_AND;
977 } else if (d == '='){
979 return Token.OP_OR_ASSIGN;
981 return Token.BITWISE_OR;
987 return Token.OP_MULT_ASSIGN;
996 return Token.OP_DIV_ASSIGN;
1004 return Token.OP_MOD_ASSIGN;
1006 return Token.PERCENT;
1012 return Token.OP_XOR_ASSIGN;
1014 return Token.CARRET;
1025 return Token.OP_SHIFT_LEFT_ASSIGN;
1027 return Token.OP_SHIFT_LEFT;
1028 } else if (d == '='){
1042 return Token.OP_SHIFT_RIGHT_ASSIGN;
1044 return Token.OP_SHIFT_RIGHT;
1045 } else if (d == '='){
1055 return Token.DOUBLE_COLON;
1064 int deambiguate_close_parens = 0;
1066 public void Deambiguate_CloseParens (object expression)
1070 // When any binary operation is used we are sure it is not a cast
1071 if (expression is Binary)
1074 deambiguate_close_parens++;
1077 bool decimal_digits (int c)
1080 bool seen_digits = false;
1083 if (number_pos == max_number_size)
1084 Error_NumericConstantTooLong ();
1085 number_builder [number_pos++] = (char) c;
1089 // We use peekChar2, because decimal_digits needs to do a
1090 // 2-character look-ahead (5.ToString for example).
1092 while ((d = peekChar2 ()) != -1){
1093 if (d >= '0' && d <= '9'){
1094 if (number_pos == max_number_size)
1095 Error_NumericConstantTooLong ();
1096 number_builder [number_pos++] = (char) d;
1106 static bool is_hex (int e)
1108 return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1111 static int real_type_suffix (int c)
1117 t = Token.LITERAL_FLOAT;
1120 t = Token.LITERAL_DOUBLE;
1123 t= Token.LITERAL_DECIMAL;
1131 int integer_type_suffix (ulong ul, int c)
1133 bool is_unsigned = false;
1134 bool is_long = false;
1137 bool scanning = true;
1148 if (!is_unsigned && (RootContext.WarningLevel >= 4)){
1150 // if we have not seen anything in between
1151 // report this error
1153 Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1156 // This goto statement causes the MS CLR 2.0 beta 1 csc to report an error, so
1157 // work around that.
1181 if (is_long && is_unsigned){
1183 return Token.LITERAL_INTEGER;
1184 } else if (is_unsigned){
1185 // uint if possible, or ulong else.
1187 if ((ul & 0xffffffff00000000) == 0)
1191 } else if (is_long){
1192 // long if possible, ulong otherwise
1193 if ((ul & 0x8000000000000000) != 0)
1198 // int, uint, long or ulong in that order
1199 if ((ul & 0xffffffff00000000) == 0){
1200 uint ui = (uint) ul;
1202 if ((ui & 0x80000000) != 0)
1207 if ((ul & 0x8000000000000000) != 0)
1213 return Token.LITERAL_INTEGER;
1217 // given `c' as the next char in the input decide whether
1218 // we need to convert to a special type, and then choose
1219 // the best representation for the integer
1221 int adjust_int (int c)
1224 if (number_pos > 9){
1225 ulong ul = (uint) (number_builder [0] - '0');
1227 for (int i = 1; i < number_pos; i++){
1228 ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1230 return integer_type_suffix (ul, c);
1232 uint ui = (uint) (number_builder [0] - '0');
1234 for (int i = 1; i < number_pos; i++){
1235 ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1237 return integer_type_suffix (ui, c);
1239 } catch (OverflowException) {
1240 error_details = "Integral constant is too large";
1241 Report.Error (1021, Location, error_details);
1243 return Token.LITERAL_INTEGER;
1245 catch (FormatException) {
1246 Report.Error (1013, Location, "Invalid number");
1248 return Token.LITERAL_INTEGER;
1252 int adjust_real (int t)
1254 string s = new String (number_builder, 0, number_pos);
1255 const string error_details = "Floating-point constant is outside the range of type `{0}'";
1258 case Token.LITERAL_DECIMAL:
1260 val = System.Decimal.Parse (s, styles, csharp_format_info);
1261 } catch (OverflowException) {
1263 Report.Error (594, Location, error_details, "decimal");
1266 case Token.LITERAL_FLOAT:
1268 val = float.Parse (s, styles, csharp_format_info);
1269 } catch (OverflowException) {
1271 Report.Error (594, Location, error_details, "float");
1275 case Token.LITERAL_DOUBLE:
1277 t = Token.LITERAL_DOUBLE;
1279 val = System.Double.Parse (s, styles, csharp_format_info);
1280 } catch (OverflowException) {
1282 Report.Error (594, Location, error_details, "double");
1295 while ((d = peekChar ()) != -1){
1297 number_builder [number_pos++] = (char) d;
1303 string s = new String (number_builder, 0, number_pos);
1305 if (number_pos <= 8)
1306 ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1308 ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1309 } catch (OverflowException){
1310 error_details = "Integral constant is too large";
1311 Report.Error (1021, Location, error_details);
1313 return Token.LITERAL_INTEGER;
1315 catch (FormatException) {
1316 Report.Error (1013, Location, "Invalid number");
1318 return Token.LITERAL_INTEGER;
1321 return integer_type_suffix (ul, peekChar ());
1325 // Invoked if we know we have .digits or digits
1327 int is_number (int c)
1329 bool is_real = false;
1334 if (c >= '0' && c <= '9'){
1336 int peek = peekChar ();
1338 if (peek == 'x' || peek == 'X')
1339 return handle_hex ();
1346 // We need to handle the case of
1347 // "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1350 if (decimal_digits ('.')){
1356 return adjust_int (-1);
1360 if (c == 'e' || c == 'E'){
1362 if (number_pos == max_number_size)
1363 Error_NumericConstantTooLong ();
1364 number_builder [number_pos++] = 'e';
1368 if (number_pos == max_number_size)
1369 Error_NumericConstantTooLong ();
1370 number_builder [number_pos++] = '+';
1372 } else if (c == '-') {
1373 if (number_pos == max_number_size)
1374 Error_NumericConstantTooLong ();
1375 number_builder [number_pos++] = '-';
1378 if (number_pos == max_number_size)
1379 Error_NumericConstantTooLong ();
1380 number_builder [number_pos++] = '+';
1387 type = real_type_suffix (c);
1388 if (type == Token.NONE && !is_real){
1390 return adjust_int (c);
1394 if (type == Token.NONE){
1399 return adjust_real (type);
1401 Console.WriteLine ("This should not be reached");
1402 throw new Exception ("Is Number should never reach this point");
1406 // Accepts exactly count (4 or 8) hex, no more no less
1408 int getHex (int count, out bool error)
1413 int top = count != -1 ? count : 4;
1417 for (i = 0; i < top; i++){
1420 if (c >= '0' && c <= '9')
1421 c = (int) c - (int) '0';
1422 else if (c >= 'A' && c <= 'F')
1423 c = (int) c - (int) 'A' + 10;
1424 else if (c >= 'a' && c <= 'f')
1425 c = (int) c - (int) 'a' + 10;
1431 total = (total * 16) + c;
1433 int p = peekChar ();
1436 if (!is_hex ((char)p))
1477 v = getHex (-1, out error);
1482 v = getHex (4, out error);
1487 v = getHex (8, out error);
1492 Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1502 if (putback_char != -1) {
1520 if (putback_char != -1)
1521 return putback_char;
1522 putback_char = reader.Read ();
1523 return putback_char;
1528 if (putback_char != -1)
1529 return putback_char;
1530 return reader.Peek ();
1533 void putback (int c)
1535 if (putback_char != -1){
1536 Console.WriteLine ("Col: " + col);
1537 Console.WriteLine ("Row: " + line);
1538 Console.WriteLine ("Name: " + ref_name.Name);
1539 Console.WriteLine ("Current [{0}] putting back [{1}] ", putback_char, c);
1540 throw new Exception ("This should not happen putback on putback");
1542 if (c == '\n' || col == 0) {
1543 // It won't happen though.
1553 public bool advance ()
1555 return peekChar () != -1;
1558 public Object Value {
1564 public Object value ()
1569 static bool IsCastToken (int token)
1574 case Token.IDENTIFIER:
1575 case Token.LITERAL_INTEGER:
1576 case Token.LITERAL_FLOAT:
1577 case Token.LITERAL_DOUBLE:
1578 case Token.LITERAL_DECIMAL:
1579 case Token.LITERAL_CHARACTER:
1580 case Token.LITERAL_STRING:
1583 case Token.DELEGATE:
1593 case Token.UNCHECKED:
1600 // These can be part of a member access
1620 current_token = xtoken ();
1623 if (current_token != Token.DEFAULT)
1624 return current_token;
1629 current_token = Token.ERROR;
1630 else if (c == Token.OPEN_PARENS)
1631 current_token = Token.DEFAULT_OPEN_PARENS;
1632 else if (c == Token.COLON)
1633 current_token = Token.DEFAULT_COLON;
1637 return current_token;
1640 static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
1642 void get_cmd_arg (out string cmd, out string arg)
1646 tokens_seen = false;
1648 static_cmd_arg.Length = 0;
1650 // skip over white space
1651 while ((c = getChar ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1654 while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
1655 if (is_identifier_part_character ((char) c)){
1656 static_cmd_arg.Append ((char) c);
1664 cmd = static_cmd_arg.ToString ();
1666 if (c == '\n' || c == '\r'){
1670 // skip over white space
1671 while ((c = getChar ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1676 } else if (c == '\r'){
1678 } else if (c == -1){
1683 static_cmd_arg.Length = 0;
1684 static_cmd_arg.Append ((char) c);
1686 while ((c = getChar ()) != -1 && (c != '\n') && (c != '\r')){
1687 static_cmd_arg.Append ((char) c);
1690 arg = static_cmd_arg.ToString ();
1694 // Handles the #line directive
1696 bool PreProcessLine (string arg)
1698 if (arg.Length == 0)
1701 if (arg == "default"){
1703 ref_name = file_name;
1704 Location.Push (ref_name);
1706 } else if (arg == "hidden"){
1708 // We ignore #line hidden
1716 if ((pos = arg.IndexOf (' ')) != -1 && pos != 0){
1717 ref_line = System.Int32.Parse (arg.Substring (0, pos));
1720 char [] quotes = { '\"' };
1722 string name = arg.Substring (pos). Trim (quotes);
1723 ref_name = Location.LookupFile (name);
1724 file_name.HasLineDirective = true;
1725 ref_name.HasLineDirective = true;
1726 Location.Push (ref_name);
1728 ref_line = System.Int32.Parse (arg);
1738 // Handles #define and #undef
1740 void PreProcessDefinition (bool is_define, string arg, bool caller_is_taking)
1742 if (arg.Length == 0 || arg == "true" || arg == "false"){
1743 Report.Error (1001, Location, "Missing identifer to pre-processor directive");
1747 if (arg.IndexOfAny (simple_whitespaces) != -1){
1748 Error_EndLineExpected ();
1752 if (!is_identifier_start_character (arg [0]))
1753 Report.Error (1001, Location, "Identifier expected: " + arg);
1755 foreach (char c in arg.Substring (1)){
1756 if (!is_identifier_part_character (c)){
1757 Report.Error (1001, Location, "Identifier expected: " + arg);
1762 if (!caller_is_taking)
1766 if (defines == null)
1767 defines = new Hashtable ();
1770 if (defines == null)
1772 if (defines.Contains (arg))
1773 defines.Remove (arg);
1778 /// Handles #pragma directive
1780 void PreProcessPragma (string arg)
1782 const string warning = "warning";
1783 const string w_disable = "warning disable";
1784 const string w_restore = "warning restore";
1786 if (arg == w_disable) {
1787 Report.RegisterWarningRegion (Location).WarningDisable (line);
1791 if (arg == w_restore) {
1792 Report.RegisterWarningRegion (Location).WarningEnable (line);
1796 if (arg.StartsWith (w_disable)) {
1797 int[] codes = ParseNumbers (arg.Substring (w_disable.Length));
1798 foreach (int code in codes) {
1800 Report.RegisterWarningRegion (Location).WarningDisable (Location, code);
1805 if (arg.StartsWith (w_restore)) {
1806 int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
1807 Hashtable w_table = Report.warning_ignore_table;
1808 foreach (int code in codes) {
1809 if (w_table != null && w_table.Contains (code))
1810 Report.Warning (1635, 1, Location, String.Format ("Cannot restore warning `CS{0:0000}' because it was disabled globally", code));
1811 Report.RegisterWarningRegion (Location).WarningEnable (Location, code);
1816 if (arg.StartsWith (warning)) {
1817 Report.Warning (1634, 1, Location, "Expected disable or restore");
1821 Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
1824 int[] ParseNumbers (string text)
1826 string[] string_array = text.Split (',');
1827 int[] values = new int [string_array.Length];
1829 foreach (string string_code in string_array) {
1831 values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);
1833 catch (FormatException) {
1834 Report.Warning (1692, 1, Location, "Invalid number");
1840 bool eval_val (string s)
1847 if (defines == null)
1849 if (defines.Contains (s))
1855 bool pp_primary (ref string s)
1864 s = s.Substring (1);
1865 bool val = pp_expr (ref s, false);
1866 if (s.Length > 0 && s [0] == ')'){
1867 s = s.Substring (1);
1870 Error_InvalidDirective ();
1874 if (is_identifier_start_character (c)){
1880 if (is_identifier_part_character (c)){
1884 bool v = eval_val (s.Substring (0, j));
1885 s = s.Substring (j);
1888 bool vv = eval_val (s);
1893 Error_InvalidDirective ();
1897 bool pp_unary (ref string s)
1904 if (len > 1 && s [1] == '='){
1905 Error_InvalidDirective ();
1908 s = s.Substring (1);
1909 return ! pp_primary (ref s);
1911 return pp_primary (ref s);
1913 Error_InvalidDirective ();
1918 bool pp_eq (ref string s)
1920 bool va = pp_unary (ref s);
1926 if (len > 2 && s [1] == '='){
1927 s = s.Substring (2);
1928 return va == pp_unary (ref s);
1930 Error_InvalidDirective ();
1933 } else if (s [0] == '!' && len > 1 && s [1] == '='){
1934 s = s.Substring (2);
1936 return va != pp_unary (ref s);
1945 bool pp_and (ref string s)
1947 bool va = pp_eq (ref s);
1953 if (len > 2 && s [1] == '&'){
1954 s = s.Substring (2);
1955 return (va & pp_and (ref s));
1957 Error_InvalidDirective ();
1966 // Evaluates an expression for `#if' or `#elif'
1968 bool pp_expr (ref string s, bool isTerm)
1970 bool va = pp_and (ref s);
1977 if (len > 2 && s [1] == '|'){
1978 s = s.Substring (2);
1979 return va | pp_expr (ref s, isTerm);
1981 Error_InvalidDirective ();
1986 Error_EndLineExpected ();
1994 bool eval (string s)
1996 bool v = pp_expr (ref s, true);
2005 void Error_NumericConstantTooLong ()
2007 Report.Error (1021, Location, "Numeric constant too long");
2010 void Error_InvalidDirective ()
2012 Report.Error (1517, Location, "Invalid preprocessor directive");
2015 void Error_UnexpectedDirective (string extra)
2019 "Unexpected processor directive (" + extra + ")");
2022 void Error_TokensSeen ()
2024 Report.Error (1032, Location,
2025 "Cannot define or undefine preprocessor symbols after first token in file");
2028 void Eror_WrongPreprocessorLocation ()
2030 Report.Error (1040, Location,
2031 "Preprocessor directives must appear as the first non-whitespace character on a line");
2034 void Error_EndLineExpected ()
2036 Report.Error (1025, Location, "Single-line comment or end-of-line expected");
2040 // if true, then the code continues processing the code
2041 // if false, the code stays in a loop until another directive is
2043 // When caller_is_taking is false we ignore all directives except the ones
2044 // which can help us to identify where the #if block ends
2045 bool handle_preprocessing_directive (bool caller_is_taking)
2048 bool region_directive = false;
2050 get_cmd_arg (out cmd, out arg);
2052 // Eat any trailing whitespaces and single-line comments
2053 if (arg.IndexOf ("//") != -1)
2054 arg = arg.Substring (0, arg.IndexOf ("//"));
2055 arg = arg.Trim (simple_whitespaces);
2058 // The first group of pre-processing instructions is always processed
2062 region_directive = true;
2067 if (ifstack == null || ifstack.Count == 0){
2068 Error_UnexpectedDirective ("no #region for this #endregion");
2071 int pop = (int) ifstack.Pop ();
2073 if ((pop & REGION) == 0)
2074 Report.Error (1027, Location, "Expected `#endif' directive");
2076 return caller_is_taking;
2079 if (ifstack == null)
2080 ifstack = new Stack (2);
2082 int flags = region_directive ? REGION : 0;
2083 if (ifstack.Count == 0){
2084 flags |= PARENT_TAKING;
2086 int state = (int) ifstack.Peek ();
2087 if ((state & TAKING) != 0) {
2088 flags |= PARENT_TAKING;
2092 if (caller_is_taking && eval (arg)) {
2093 ifstack.Push (flags | TAKING);
2096 ifstack.Push (flags);
2100 if (ifstack == null || ifstack.Count == 0){
2101 Error_UnexpectedDirective ("no #if for this #endif");
2104 pop = (int) ifstack.Pop ();
2106 if ((pop & REGION) != 0)
2107 Report.Error (1038, Location, "#endregion directive expected");
2109 if (arg.Length != 0) {
2110 Error_EndLineExpected ();
2113 if (ifstack.Count == 0)
2116 int state = (int) ifstack.Peek ();
2117 return (state & TAKING) != 0;
2121 if (ifstack == null || ifstack.Count == 0){
2122 Error_UnexpectedDirective ("no #if for this #elif");
2125 int state = (int) ifstack.Pop ();
2127 if ((state & REGION) != 0) {
2128 Report.Error (1038, Location, "#endregion directive expected");
2132 if ((state & ELSE_SEEN) != 0){
2133 Error_UnexpectedDirective ("#elif not valid after #else");
2137 if ((state & TAKING) != 0) {
2142 if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2143 ifstack.Push (state | TAKING);
2147 ifstack.Push (state);
2152 if (ifstack == null || ifstack.Count == 0){
2153 Error_UnexpectedDirective ("no #if for this #else");
2156 int state = (int) ifstack.Peek ();
2158 if ((state & REGION) != 0) {
2159 Report.Error (1038, Location, "#endregion directive expected");
2163 if ((state & ELSE_SEEN) != 0){
2164 Error_UnexpectedDirective ("#else within #else");
2170 if (arg.Length != 0) {
2171 Error_EndLineExpected ();
2176 if ((state & PARENT_TAKING) != 0) {
2177 ret = (state & TAKING) == 0;
2185 ifstack.Push (state | ELSE_SEEN);
2190 if (any_token_seen){
2191 Error_TokensSeen ();
2192 return caller_is_taking;
2194 PreProcessDefinition (true, arg, caller_is_taking);
2195 return caller_is_taking;
2198 if (any_token_seen){
2199 Error_TokensSeen ();
2200 return caller_is_taking;
2202 PreProcessDefinition (false, arg, caller_is_taking);
2203 return caller_is_taking;
2207 // These are only processed if we are in a `taking' block
2209 if (!caller_is_taking)
2214 Report.Error (1029, Location, "#error: '" + arg + "'");
2218 Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2222 if (RootContext.Version == LanguageVersion.ISO_1) {
2223 Report.FeatureIsNotISO1 (Location, "#pragma");
2227 PreProcessPragma (arg);
2231 if (!PreProcessLine (arg))
2234 "The line number specified for #line directive is missing or invalid");
2235 return caller_is_taking;
2238 Report.Error (1024, Location, "Wrong preprocessor directive");
2243 private int consume_string (bool quoted)
2246 string_builder.Length = 0;
2248 while ((c = getChar ()) != -1){
2250 if (quoted && peekChar () == '"'){
2251 string_builder.Append ((char) c);
2255 val = string_builder.ToString ();
2256 return Token.LITERAL_STRING;
2262 Report.Error (1010, Location, "Newline in constant");
2270 string_builder.Append ((char) c);
2273 Report.Error (1039, Location, "Unterminated string literal");
2277 private int consume_identifier (int s)
2279 int res = consume_identifier (s, false);
2281 if (doc_state == XmlCommentState.Allowed)
2282 doc_state = XmlCommentState.NotAllowed;
2285 case Token.NAMESPACE:
2286 check_incorrect_doc_comment ();
2290 if (res == Token.PARTIAL) {
2291 // Save current position and parse next token.
2294 int next_token = token ();
2295 bool ok = (next_token == Token.CLASS) ||
2296 (next_token == Token.STRUCT) ||
2297 (next_token == Token.INTERFACE);
2304 if (next_token < Token.LAST_KEYWORD)
2305 Report.Error (267, Location, "The `partial' modifier can be used only immediately before keyword `class', `struct', or `interface'");
2307 val = new LocatedToken (Location, "partial");
2308 return Token.IDENTIFIER;
2314 private int consume_identifier (int s, bool quoted)
2319 id_builder [0] = (char) s;
2321 current_location = new Location (ref_line, Col);
2323 while ((c = getChar ()) != -1) {
2325 if (is_identifier_part_character ((char) c)){
2326 if (pos == max_id_size){
2327 Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
2331 id_builder [pos++] = (char) c;
2332 // putback_char = -1;
2333 } else if (c == '\\') {
2337 // putback_char = c;
2344 // Optimization: avoids doing the keyword lookup
2345 // on uppercase letters and _
2347 if (!quoted && (s >= 'a' || s == '_')){
2348 int keyword = GetKeyword (id_builder, pos);
2349 if (keyword != -1) {
2356 // Keep identifiers in an array of hashtables to avoid needless
2360 if (identifiers [pos] != null) {
2361 val = identifiers [pos][id_builder];
2363 val = new LocatedToken (Location, (string) val);
2365 escapedIdentifiers.Add (val);
2366 return Token.IDENTIFIER;
2370 identifiers [pos] = new CharArrayHashtable (pos);
2372 val = new String (id_builder, 0, pos);
2373 if (RootContext.Version == LanguageVersion.ISO_1) {
2374 for (int i = 1; i < id_builder.Length; i += 3) {
2375 if (id_builder [i] == '_' && (id_builder [i - 1] == '_' || id_builder [i + 1] == '_')) {
2376 Report.Error (1638, Location,
2377 "`{0}': Any identifier with double underscores cannot be used when ISO language version mode is specified", val.ToString ());
2383 char [] chars = new char [pos];
2384 Array.Copy (id_builder, chars, pos);
2386 identifiers [pos] [chars] = val;
2388 val = new LocatedToken (Location, (string) val);
2390 escapedIdentifiers.Add (val);
2391 return Token.IDENTIFIER;
2394 public int xtoken ()
2397 bool doread = false;
2400 // Whether we have seen comments on the current line
2401 bool comments_seen = false;
2403 for (;(c = getChar ()) != -1;) {
2405 col = ((col + 8) / 8) * 8;
2409 if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
2413 if (peekChar () == '\n')
2416 any_token_seen |= tokens_seen;
2417 tokens_seen = false;
2418 comments_seen = false;
2422 // Handle double-slash comments.
2424 int d = peekChar ();
2428 if (RootContext.Documentation != null && peekChar () == '/') {
2430 // Don't allow ////.
2431 if ((d = peekChar ()) != '/') {
2432 update_comment_location ();
2433 if (doc_state == XmlCommentState.Allowed)
2434 handle_one_line_xml_comment ();
2435 else if (doc_state == XmlCommentState.NotAllowed)
2436 warn_incorrect_doc_comment ();
2439 while ((d = getChar ()) != -1 && (d != '\n') && d != '\r')
2442 any_token_seen |= tokens_seen;
2443 tokens_seen = false;
2444 comments_seen = false;
2446 } else if (d == '*'){
2448 bool docAppend = false;
2449 if (RootContext.Documentation != null && peekChar () == '*') {
2451 update_comment_location ();
2452 // But when it is /**/, just do nothing.
2453 if (peekChar () == '/') {
2457 if (doc_state == XmlCommentState.Allowed)
2459 else if (doc_state == XmlCommentState.NotAllowed)
2460 warn_incorrect_doc_comment ();
2463 int current_comment_start = 0;
2465 current_comment_start = xml_comment_buffer.Length;
2466 xml_comment_buffer.Append (Environment.NewLine);
2469 Location start_location = Location;
2471 while ((d = getChar ()) != -1){
2472 if (d == '*' && peekChar () == '/'){
2474 comments_seen = true;
2478 xml_comment_buffer.Append ((char) d);
2481 any_token_seen |= tokens_seen;
2482 tokens_seen = false;
2484 // Reset 'comments_seen' just to be consistent.
2485 // It doesn't matter either way, here.
2487 comments_seen = false;
2491 Report.Error (1035, start_location, "End-of-file found, '*/' expected");
2494 update_formatted_doc_comment (current_comment_start);
2497 goto is_punct_label;
2501 if (c == '\\' || is_identifier_start_character ((char)c)){
2503 return consume_identifier (c);
2507 current_location = new Location (ref_line, Col);
2508 if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
2518 any_token_seen |= tokens_seen;
2519 tokens_seen = false;
2520 comments_seen = false;
2524 if (c >= '0' && c <= '9'){
2526 return is_number (c);
2531 int peek = peekChar ();
2532 if (peek >= '0' && peek <= '9')
2533 return is_number (c);
2538 if (tokens_seen || comments_seen) {
2539 Eror_WrongPreprocessorLocation ();
2543 if (handle_preprocessing_directive (true))
2546 bool directive_expected = false;
2547 while ((c = getChar ()) != -1) {
2549 directive_expected = true;
2550 } else if (!directive_expected) {
2551 // TODO: Implement comment support for disabled code and uncomment this code
2553 // Eror_WrongPreprocessorLocation ();
2554 // return Token.ERROR;
2559 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || c == '\v' )
2563 if (handle_preprocessing_directive (false))
2566 directive_expected = false;
2570 tokens_seen = false;
2578 return consume_string (false);
2584 error_details = "Empty character literal";
2585 Report.Error (1011, Location, error_details);
2588 if (c == '\r' || c == '\n') {
2589 Report.Error (1010, Location, "Newline in constant");
2595 val = new System.Char ();
2600 error_details = "Too many characters in character literal";
2601 Report.Error (1012, Location, error_details);
2603 // Try to recover, read until newline or next "'"
2604 while ((c = getChar ()) != -1){
2613 return Token.LITERAL_CHARACTER;
2620 return consume_string (true);
2621 } else if (is_identifier_start_character ((char) c)){
2622 return consume_identifier (c, true);
2624 Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
2628 error_details = ((char)c).ToString ();
2637 // Handles one line xml comment
2639 private void handle_one_line_xml_comment ()
2642 while ((c = peekChar ()) == ' ')
2643 getChar (); // skip heading whitespaces.
2644 while ((c = peekChar ()) != -1 && c != '\n' && c != '\r') {
2645 xml_comment_buffer.Append ((char) getChar ());
2647 if (c == '\r' || c == '\n')
2648 xml_comment_buffer.Append (Environment.NewLine);
2652 // Remove heading "*" in Javadoc-like xml documentation.
2654 private void update_formatted_doc_comment (int current_comment_start)
2656 int length = xml_comment_buffer.Length - current_comment_start;
2657 string [] lines = xml_comment_buffer.ToString (
2658 current_comment_start,
2659 length).Replace ("\r", "").Split ('\n');
2661 // The first line starts with /**, thus it is not target
2662 // for the format check.
2663 for (int i = 1; i < lines.Length; i++) {
2664 string s = lines [i];
2665 int idx = s.IndexOf ('*');
2668 if (i < lines.Length - 1)
2672 head = s.Substring (0, idx);
2673 foreach (char c in head)
2676 lines [i] = s.Substring (idx + 1);
2678 xml_comment_buffer.Remove (current_comment_start, length);
2679 xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
2683 // Updates current comment location.
2685 private void update_comment_location ()
2687 if (current_comment_location.IsNull) {
2688 // "-2" is for heading "//" or "/*"
2689 current_comment_location =
2690 new Location (ref_line, col - 2);
2695 // Checks if there was incorrect doc comments and raise
2698 public void check_incorrect_doc_comment ()
2700 if (xml_comment_buffer.Length > 0)
2701 warn_incorrect_doc_comment ();
2705 // Raises a warning when tokenizer found incorrect doccomment
2708 private void warn_incorrect_doc_comment ()
2710 if (doc_state != XmlCommentState.Error) {
2711 doc_state = XmlCommentState.Error;
2712 // in csc, it is 'XML comment is not placed on
2713 // a valid language element'. But that does not
2715 Report.Warning (1587, 2, Location, "XML comment is not placed on a valid language element");
2720 // Consumes the saved xml comment lines (if any)
2721 // as for current target member or type.
2723 public string consume_doc_comment ()
2725 if (xml_comment_buffer.Length > 0) {
2726 string ret = xml_comment_buffer.ToString ();
2727 reset_doc_comment ();
2733 void reset_doc_comment ()
2735 xml_comment_buffer.Length = 0;
2736 current_comment_location = Location.Null;
2739 public void cleanup ()
2741 if (ifstack != null && ifstack.Count >= 1) {
2742 current_location = new Location (ref_line, Col);
2743 int state = (int) ifstack.Pop ();
2744 if ((state & REGION) != 0)
2745 Report.Error (1038, Location, "#endregion directive expected");
2747 Report.Error (1027, Location, "Expected `#endif' directive");
2753 // Indicates whether it accepts XML documentation or not.
2755 public enum XmlCommentState {
2756 // comment is allowed in this state.
2758 // comment is not allowed in this state.
2760 // once comments appeared when it is NotAllowed, then the
2761 // state is changed to it, until the state is changed to