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;
50 static bool IsLinqEnabled {
52 return RootContext.Version == LanguageVersion.LINQ;
57 // XML documentation buffer. The save point is used to divide
58 // comments on types and comments on members.
60 StringBuilder xml_comment_buffer;
63 // See comment on XmlCommentState enumeration.
65 XmlCommentState xml_doc_state = XmlCommentState.Allowed;
68 // Whether tokens have been seen on this line
70 bool tokens_seen = false;
73 // Whether a token has been seen on the file
74 // This is needed because `define' is not allowed to be used
75 // after a token has been seen.
77 bool any_token_seen = false;
79 static Hashtable token_values;
80 static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
82 private static Hashtable TokenValueName
85 if (token_values == null)
86 token_values = GetTokenValueNameHash ();
92 private static Hashtable GetTokenValueNameHash ()
94 Type t = typeof (Token);
95 FieldInfo [] fields = t.GetFields ();
96 Hashtable hash = new Hashtable ();
97 foreach (FieldInfo field in fields) {
98 if (field.IsLiteral && field.IsStatic && field.FieldType == typeof (int))
99 hash.Add (field.GetValue (null), field.Name);
105 // Returns a verbose representation of the current location
107 public string location {
111 if (current_token == Token.ERROR)
112 det = "detail: " + error_details;
116 // return "Line: "+line+" Col: "+col + "\n" +
117 // "VirtLine: "+ref_line +
118 // " Token: "+current_token + " " + det;
119 string current_token_name = TokenValueName [current_token] as string;
120 if (current_token_name == null)
121 current_token_name = current_token.ToString ();
123 return String.Format ("{0} ({1},{2}), Token: {3} {4}", ref_name.Name,
131 public bool PropertyParsing {
132 get { return handle_get_set; }
133 set { handle_get_set = value; }
136 public bool AssemblyTargetParsing {
137 get { return handle_assembly; }
138 set { handle_assembly = value; }
141 public bool EventParsing {
142 get { return handle_remove_add; }
143 set { handle_remove_add = value; }
146 public bool ConstraintsParsing {
147 get { return handle_where; }
148 set { handle_where = value; }
151 public bool TypeOfParsing {
152 get { return handle_typeof; }
153 set { handle_typeof = value; }
156 public XmlCommentState doc_state {
157 get { return xml_doc_state; }
159 if (value == XmlCommentState.Allowed) {
160 check_incorrect_doc_comment ();
161 reset_doc_comment ();
163 xml_doc_state = value;
167 public bool IsEscapedIdentifier (Location loc)
169 foreach (LocatedToken lt in escaped_identifiers)
170 if (lt.Location.Equals (loc))
178 static CharArrayHashtable[] keywords;
179 static Hashtable keyword_strings;
180 static NumberStyles styles;
181 static NumberFormatInfo csharp_format_info;
184 // Values for the associated token returned
194 const int TAKING = 1;
195 const int ELSE_SEEN = 4;
196 const int PARENT_TAKING = 8;
197 const int REGION = 16;
200 // pre-processor if stack state:
204 static System.Text.StringBuilder string_builder;
206 const int max_id_size = 512;
207 static char [] id_builder = new char [max_id_size];
209 static CharArrayHashtable [] identifiers = new CharArrayHashtable [max_id_size + 1];
211 const int max_number_size = 512;
212 static char [] number_builder = new char [max_number_size];
213 static int number_pos;
216 // Details about the error encoutered by the tokenizer
218 string error_details;
220 public string error {
222 return error_details;
239 // This is used when the tokenizer needs to save
240 // the current position as it needs to do some parsing
241 // on its own to deamiguate a token in behalf of the
244 Stack position_stack = new Stack (2);
249 public int putback_char;
250 public int previous_col;
251 public Stack ifstack;
252 public int parsing_generic_less_than;
253 public int current_token;
255 public Position (Tokenizer t)
257 position = t.reader.Position;
258 ref_line = t.ref_line;
260 putback_char = t.putback_char;
261 previous_col = t.previous_col;
262 if (t.ifstack != null && t.ifstack.Count != 0)
263 ifstack = (Stack)t.ifstack.Clone ();
264 parsing_generic_less_than = t.parsing_generic_less_than;
265 current_token = t.current_token;
269 public void PushPosition ()
271 position_stack.Push (new Position (this));
274 public void PopPosition ()
276 Position p = (Position) position_stack.Pop ();
278 reader.Position = p.position;
279 ref_line = p.ref_line;
281 putback_char = p.putback_char;
282 previous_col = p.previous_col;
284 parsing_generic_less_than = p.parsing_generic_less_than;
285 current_token = p.current_token;
288 // Do not reset the position, ignore it.
289 public void DiscardPosition ()
291 position_stack.Pop ();
294 static void AddKeyword (string kw, int token)
296 keyword_strings.Add (kw, kw);
297 if (keywords [kw.Length] == null) {
298 keywords [kw.Length] = new CharArrayHashtable (kw.Length);
300 keywords [kw.Length] [kw.ToCharArray ()] = token;
303 static void InitTokens ()
305 keyword_strings = new Hashtable ();
306 keywords = new CharArrayHashtable [64];
308 AddKeyword ("__arglist", Token.ARGLIST);
309 AddKeyword ("abstract", Token.ABSTRACT);
310 AddKeyword ("as", Token.AS);
311 AddKeyword ("add", Token.ADD);
312 AddKeyword ("assembly", Token.ASSEMBLY);
313 AddKeyword ("base", Token.BASE);
314 AddKeyword ("bool", Token.BOOL);
315 AddKeyword ("break", Token.BREAK);
316 AddKeyword ("byte", Token.BYTE);
317 AddKeyword ("case", Token.CASE);
318 AddKeyword ("catch", Token.CATCH);
319 AddKeyword ("char", Token.CHAR);
320 AddKeyword ("checked", Token.CHECKED);
321 AddKeyword ("class", Token.CLASS);
322 AddKeyword ("const", Token.CONST);
323 AddKeyword ("continue", Token.CONTINUE);
324 AddKeyword ("decimal", Token.DECIMAL);
325 AddKeyword ("default", Token.DEFAULT);
326 AddKeyword ("delegate", Token.DELEGATE);
327 AddKeyword ("do", Token.DO);
328 AddKeyword ("double", Token.DOUBLE);
329 AddKeyword ("else", Token.ELSE);
330 AddKeyword ("enum", Token.ENUM);
331 AddKeyword ("event", Token.EVENT);
332 AddKeyword ("explicit", Token.EXPLICIT);
333 AddKeyword ("extern", Token.EXTERN);
334 AddKeyword ("false", Token.FALSE);
335 AddKeyword ("finally", Token.FINALLY);
336 AddKeyword ("fixed", Token.FIXED);
337 AddKeyword ("float", Token.FLOAT);
338 AddKeyword ("for", Token.FOR);
339 AddKeyword ("foreach", Token.FOREACH);
340 AddKeyword ("goto", Token.GOTO);
341 AddKeyword ("get", Token.GET);
342 AddKeyword ("if", Token.IF);
343 AddKeyword ("implicit", Token.IMPLICIT);
344 AddKeyword ("in", Token.IN);
345 AddKeyword ("int", Token.INT);
346 AddKeyword ("interface", Token.INTERFACE);
347 AddKeyword ("internal", Token.INTERNAL);
348 AddKeyword ("is", Token.IS);
349 AddKeyword ("lock", Token.LOCK);
350 AddKeyword ("long", Token.LONG);
351 AddKeyword ("namespace", Token.NAMESPACE);
352 AddKeyword ("new", Token.NEW);
353 AddKeyword ("null", Token.NULL);
354 AddKeyword ("object", Token.OBJECT);
355 AddKeyword ("operator", Token.OPERATOR);
356 AddKeyword ("out", Token.OUT);
357 AddKeyword ("override", Token.OVERRIDE);
358 AddKeyword ("params", Token.PARAMS);
359 AddKeyword ("private", Token.PRIVATE);
360 AddKeyword ("protected", Token.PROTECTED);
361 AddKeyword ("public", Token.PUBLIC);
362 AddKeyword ("readonly", Token.READONLY);
363 AddKeyword ("ref", Token.REF);
364 AddKeyword ("remove", Token.REMOVE);
365 AddKeyword ("return", Token.RETURN);
366 AddKeyword ("sbyte", Token.SBYTE);
367 AddKeyword ("sealed", Token.SEALED);
368 AddKeyword ("set", Token.SET);
369 AddKeyword ("short", Token.SHORT);
370 AddKeyword ("sizeof", Token.SIZEOF);
371 AddKeyword ("stackalloc", Token.STACKALLOC);
372 AddKeyword ("static", Token.STATIC);
373 AddKeyword ("string", Token.STRING);
374 AddKeyword ("struct", Token.STRUCT);
375 AddKeyword ("switch", Token.SWITCH);
376 AddKeyword ("this", Token.THIS);
377 AddKeyword ("throw", Token.THROW);
378 AddKeyword ("true", Token.TRUE);
379 AddKeyword ("try", Token.TRY);
380 AddKeyword ("typeof", Token.TYPEOF);
381 AddKeyword ("uint", Token.UINT);
382 AddKeyword ("ulong", Token.ULONG);
383 AddKeyword ("unchecked", Token.UNCHECKED);
384 AddKeyword ("unsafe", Token.UNSAFE);
385 AddKeyword ("ushort", Token.USHORT);
386 AddKeyword ("using", Token.USING);
387 AddKeyword ("virtual", Token.VIRTUAL);
388 AddKeyword ("void", Token.VOID);
389 AddKeyword ("volatile", Token.VOLATILE);
390 AddKeyword ("while", Token.WHILE);
391 AddKeyword ("partial", Token.PARTIAL);
392 AddKeyword ("where", Token.WHERE);
395 AddKeyword ("from", Token.FROM);
396 AddKeyword ("join", Token.JOIN);
397 AddKeyword ("on", Token.ON);
398 AddKeyword ("equals", Token.EQUALS);
399 AddKeyword ("select", Token.SELECT);
400 AddKeyword ("group", Token.GROUP);
401 AddKeyword ("by", Token.BY);
402 AddKeyword ("let", Token.LET);
403 AddKeyword ("orderby", Token.ORDERBY);
404 AddKeyword ("ascending", Token.ASCENDING);
405 AddKeyword ("descending", Token.DESCENDING);
406 AddKeyword ("into", Token.INTO);
417 public static void Reset ()
420 csharp_format_info = NumberFormatInfo.InvariantInfo;
421 styles = NumberStyles.Float;
423 string_builder = new System.Text.StringBuilder ();
426 int GetKeyword (char[] id, int id_len)
429 * Keywords are stored in an array of hashtables grouped by their
433 if ((id_len >= keywords.Length) || (keywords [id_len] == null))
435 object o = keywords [id_len] [id];
442 if (!handle_get_set && (res == Token.GET || res == Token.SET))
444 if (!handle_remove_add && (res == Token.REMOVE || res == Token.ADD))
446 if (!handle_assembly && res == Token.ASSEMBLY)
450 // A query expression is any expression that starts with `from identifier'
451 // followed by any token except ; , =
453 if (query_parsing == 0) {
454 if (res == Token.FROM && !lambda_arguments_parsing) {
456 // HACK: to disable generics micro-parser, because PushPosition does not
457 // store identifiers array
458 parsing_generic_less_than = 1;
460 case Token.IDENTIFIER:
472 int next_token = xtoken ();
473 if (next_token == Token.SEMICOLON || next_token == Token.COMMA || next_token == Token.EQUALS)
477 if (RootContext.Version <= LanguageVersion.ISO_2)
478 Report.FeatureIsNotAvailable (Location, "query expressions");
481 Expression.Error_VoidInvalidInTheContext (Location);
485 // HACK: A token is not a keyword so we need to restore identifiers buffer
486 // which has been overwritten before we grabbed the identifier
487 id_builder [0] = 'f'; id_builder [1] = 'r'; id_builder [2] = 'o'; id_builder [3] = 'm';
494 if (res > Token.QUERY_FIRST_TOKEN && res < Token.QUERY_LAST_TOKEN)
498 if (res == Token.WHERE && !handle_where && query_parsing == 0)
504 public Location Location {
505 get { return current_location; }
508 void define (string def)
510 if (!RootContext.AllDefines.Contains (def)){
511 RootContext.AllDefines [def] = true;
513 if (defines.Contains (def))
515 defines [def] = true;
518 public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
520 this.ref_name = file;
521 this.file_name = file;
527 defines = new Hashtable ();
528 foreach (string def in defs)
532 xml_comment_buffer = new StringBuilder ();
535 // FIXME: This could be `Location.Push' but we have to
536 // find out why the MS compiler allows this
538 Mono.CSharp.Location.Push (file);
541 static bool is_identifier_start_character (char c)
543 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
546 static bool is_identifier_part_character (char c)
548 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') ||
549 Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
552 public static bool IsKeyword (string s)
554 return keyword_strings [s] != null;
558 // Tests whether '(' is beggining of lambda parameters
560 bool IsLambdaOpenParens ()
563 while ((ntoken = xtoken ()) != Token.EOF) {
565 case Token.CLOSE_PARENS:
566 return xtoken () == Token.ARROW;
569 case Token.SEMICOLON:
570 case Token.OPEN_PARENS:
575 Error_TokenExpected (",' or `)");
579 public static bool IsValidIdentifier (string s)
581 if (s == null || s.Length == 0)
584 if (!is_identifier_start_character (s [0]))
587 for (int i = 1; i < s.Length; i ++)
588 if (! is_identifier_part_character (s [i]))
594 bool parse_less_than ()
597 int the_token = token ();
598 if (the_token == Token.OPEN_BRACKET) {
600 the_token = token ();
601 } while (the_token != Token.CLOSE_BRACKET);
602 the_token = token ();
605 case Token.IDENTIFIER:
628 the_token = token ();
630 if (the_token == Token.OP_GENERICS_GT)
632 else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
634 else if (the_token == Token.INTERR || the_token == Token.STAR)
636 else if (the_token == Token.OP_GENERICS_LT) {
637 if (!parse_less_than ())
640 } else if (the_token == Token.OPEN_BRACKET) {
642 the_token = token ();
643 if (the_token == Token.CLOSE_BRACKET)
645 else if (the_token == Token.COMMA)
646 goto rank_specifiers;
653 public void PutbackNullable ()
655 if (nullable_pos < 0)
656 throw new Exception ();
660 reader.Position = nullable_pos;
665 public void PutbackCloseParens ()
671 int nullable_pos = -1;
673 public void CheckNullable (bool is_nullable)
676 nullable_pos = reader.Position;
681 bool parse_generic_dimension (out int dimension)
686 int the_token = token ();
687 if (the_token == Token.OP_GENERICS_GT)
689 else if (the_token == Token.COMMA) {
697 public int peek_token ()
702 the_token = token ();
708 int parsing_generic_less_than = 0;
710 int is_punct (char c, ref bool doread)
720 return Token.OPEN_BRACE;
723 return Token.CLOSE_BRACE;
725 // To block doccomment inside attribute declaration.
726 if (doc_state == XmlCommentState.Allowed)
727 doc_state = XmlCommentState.NotAllowed;
728 return Token.OPEN_BRACKET;
730 return Token.CLOSE_BRACKET;
732 if (IsLinqEnabled && !lambda_arguments_parsing) {
733 lambda_arguments_parsing = true;
735 bool lambda_start = IsLambdaOpenParens ();
737 lambda_arguments_parsing = false;
739 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 is used we are sure it is not a cast
975 if (expression is Binary)
978 deambiguate_close_parens++;
981 bool decimal_digits (int c)
984 bool seen_digits = false;
987 if (number_pos == max_number_size)
988 Error_NumericConstantTooLong ();
989 number_builder [number_pos++] = (char) c;
993 // We use peek_char2, because decimal_digits needs to do a
994 // 2-character look-ahead (5.ToString for example).
996 while ((d = peek_char2 ()) != -1){
997 if (d >= '0' && d <= '9'){
998 if (number_pos == max_number_size)
999 Error_NumericConstantTooLong ();
1000 number_builder [number_pos++] = (char) d;
1010 static bool is_hex (int e)
1012 return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1015 static int real_type_suffix (int c)
1021 t = Token.LITERAL_FLOAT;
1024 t = Token.LITERAL_DOUBLE;
1027 t= Token.LITERAL_DECIMAL;
1035 int integer_type_suffix (ulong ul, int c)
1037 bool is_unsigned = false;
1038 bool is_long = false;
1041 bool scanning = true;
1054 // if we have not seen anything in between
1055 // report this error
1057 Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1060 // This goto statement causes the MS CLR 2.0 beta 1 csc to report an error, so
1061 // work around that.
1085 if (is_long && is_unsigned){
1087 return Token.LITERAL_INTEGER;
1088 } else if (is_unsigned){
1089 // uint if possible, or ulong else.
1091 if ((ul & 0xffffffff00000000) == 0)
1095 } else if (is_long){
1096 // long if possible, ulong otherwise
1097 if ((ul & 0x8000000000000000) != 0)
1102 // int, uint, long or ulong in that order
1103 if ((ul & 0xffffffff00000000) == 0){
1104 uint ui = (uint) ul;
1106 if ((ui & 0x80000000) != 0)
1111 if ((ul & 0x8000000000000000) != 0)
1117 return Token.LITERAL_INTEGER;
1121 // given `c' as the next char in the input decide whether
1122 // we need to convert to a special type, and then choose
1123 // the best representation for the integer
1125 int adjust_int (int c)
1128 if (number_pos > 9){
1129 ulong ul = (uint) (number_builder [0] - '0');
1131 for (int i = 1; i < number_pos; i++){
1132 ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1134 return integer_type_suffix (ul, c);
1136 uint ui = (uint) (number_builder [0] - '0');
1138 for (int i = 1; i < number_pos; i++){
1139 ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1141 return integer_type_suffix (ui, c);
1143 } catch (OverflowException) {
1144 error_details = "Integral constant is too large";
1145 Report.Error (1021, Location, error_details);
1147 return Token.LITERAL_INTEGER;
1149 catch (FormatException) {
1150 Report.Error (1013, Location, "Invalid number");
1152 return Token.LITERAL_INTEGER;
1156 int adjust_real (int t)
1158 string s = new String (number_builder, 0, number_pos);
1159 const string error_details = "Floating-point constant is outside the range of type `{0}'";
1162 case Token.LITERAL_DECIMAL:
1164 val = System.Decimal.Parse (s, styles, csharp_format_info);
1165 } catch (OverflowException) {
1167 Report.Error (594, Location, error_details, "decimal");
1170 case Token.LITERAL_FLOAT:
1172 val = float.Parse (s, styles, csharp_format_info);
1173 } catch (OverflowException) {
1175 Report.Error (594, Location, error_details, "float");
1179 case Token.LITERAL_DOUBLE:
1181 t = Token.LITERAL_DOUBLE;
1183 val = System.Double.Parse (s, styles, csharp_format_info);
1184 } catch (OverflowException) {
1186 Report.Error (594, Location, error_details, "double");
1199 while ((d = peek_char ()) != -1){
1201 number_builder [number_pos++] = (char) d;
1207 string s = new String (number_builder, 0, number_pos);
1209 if (number_pos <= 8)
1210 ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1212 ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1213 } catch (OverflowException){
1214 error_details = "Integral constant is too large";
1215 Report.Error (1021, Location, error_details);
1217 return Token.LITERAL_INTEGER;
1219 catch (FormatException) {
1220 Report.Error (1013, Location, "Invalid number");
1222 return Token.LITERAL_INTEGER;
1225 return integer_type_suffix (ul, peek_char ());
1229 // Invoked if we know we have .digits or digits
1231 int is_number (int c)
1233 bool is_real = false;
1238 if (c >= '0' && c <= '9'){
1240 int peek = peek_char ();
1242 if (peek == 'x' || peek == 'X')
1243 return handle_hex ();
1250 // We need to handle the case of
1251 // "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1254 if (decimal_digits ('.')){
1260 return adjust_int (-1);
1264 if (c == 'e' || c == 'E'){
1266 if (number_pos == max_number_size)
1267 Error_NumericConstantTooLong ();
1268 number_builder [number_pos++] = 'e';
1272 if (number_pos == max_number_size)
1273 Error_NumericConstantTooLong ();
1274 number_builder [number_pos++] = '+';
1276 } else if (c == '-') {
1277 if (number_pos == max_number_size)
1278 Error_NumericConstantTooLong ();
1279 number_builder [number_pos++] = '-';
1282 if (number_pos == max_number_size)
1283 Error_NumericConstantTooLong ();
1284 number_builder [number_pos++] = '+';
1291 type = real_type_suffix (c);
1292 if (type == Token.NONE && !is_real){
1294 return adjust_int (c);
1298 if (type == Token.NONE){
1303 return adjust_real (type);
1305 Console.WriteLine ("This should not be reached");
1306 throw new Exception ("Is Number should never reach this point");
1310 // Accepts exactly count (4 or 8) hex, no more no less
1312 int getHex (int count, out bool error)
1317 int top = count != -1 ? count : 4;
1321 for (i = 0; i < top; i++){
1324 if (c >= '0' && c <= '9')
1325 c = (int) c - (int) '0';
1326 else if (c >= 'A' && c <= 'F')
1327 c = (int) c - (int) 'A' + 10;
1328 else if (c >= 'a' && c <= 'f')
1329 c = (int) c - (int) 'a' + 10;
1335 total = (total * 16) + c;
1337 int p = peek_char ();
1340 if (!is_hex ((char)p))
1381 v = getHex (-1, out error);
1386 v = getHex (4, out error);
1391 v = getHex (8, out error);
1396 Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1406 if (putback_char != -1) {
1419 void advance_line ()
1429 if (putback_char != -1)
1430 return putback_char;
1431 putback_char = reader.Read ();
1432 return putback_char;
1437 if (putback_char != -1)
1438 return putback_char;
1439 return reader.Peek ();
1442 void putback (int c)
1444 if (putback_char != -1){
1445 Console.WriteLine ("Col: " + col);
1446 Console.WriteLine ("Row: " + line);
1447 Console.WriteLine ("Name: " + ref_name.Name);
1448 Console.WriteLine ("Current [{0}] putting back [{1}] ", putback_char, c);
1449 throw new Exception ("This should not happen putback on putback");
1451 if (c == '\n' || col == 0) {
1452 // It won't happen though.
1462 public bool advance ()
1464 return peek_char () != -1;
1467 public Object Value {
1473 public Object value ()
1478 static bool IsCastToken (int token)
1483 case Token.IDENTIFIER:
1484 case Token.LITERAL_INTEGER:
1485 case Token.LITERAL_FLOAT:
1486 case Token.LITERAL_DOUBLE:
1487 case Token.LITERAL_DECIMAL:
1488 case Token.LITERAL_CHARACTER:
1489 case Token.LITERAL_STRING:
1492 case Token.DELEGATE:
1502 case Token.UNCHECKED:
1507 // These can be part of a member access
1527 current_token = xtoken ();
1529 if (current_token != Token.DEFAULT)
1530 return current_token;
1535 current_token = Token.ERROR;
1536 else if (c == Token.OPEN_PARENS)
1537 current_token = Token.DEFAULT_OPEN_PARENS;
1538 else if (c == Token.COLON)
1539 current_token = Token.DEFAULT_COLON;
1543 return current_token;
1546 static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
1548 void get_cmd_arg (out string cmd, out string arg)
1552 tokens_seen = false;
1554 static_cmd_arg.Length = 0;
1556 // skip over white space
1557 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1560 while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
1561 if (is_identifier_part_character ((char) c)){
1562 static_cmd_arg.Append ((char) c);
1570 cmd = static_cmd_arg.ToString ();
1572 if (c == '\n' || c == '\r'){
1576 // skip over white space
1577 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1582 } else if (c == '\r'){
1584 } else if (c == -1){
1589 static_cmd_arg.Length = 0;
1590 static_cmd_arg.Append ((char) c);
1592 while ((c = get_char ()) != -1 && (c != '\n') && (c != '\r')){
1593 static_cmd_arg.Append ((char) c);
1596 arg = static_cmd_arg.ToString ();
1600 // Handles the #line directive
1602 bool PreProcessLine (string arg)
1604 if (arg.Length == 0)
1607 if (arg == "default"){
1609 ref_name = file_name;
1610 Location.Push (ref_name);
1612 } else if (arg == "hidden"){
1614 // We ignore #line hidden
1622 if ((pos = arg.IndexOf (' ')) != -1 && pos != 0){
1623 ref_line = System.Int32.Parse (arg.Substring (0, pos));
1626 char [] quotes = { '\"' };
1628 string name = arg.Substring (pos). Trim (quotes);
1629 ref_name = Location.LookupFile (name);
1630 file_name.HasLineDirective = true;
1631 ref_name.HasLineDirective = true;
1632 Location.Push (ref_name);
1634 ref_line = System.Int32.Parse (arg);
1644 // Handles #define and #undef
1646 void PreProcessDefinition (bool is_define, string arg, bool caller_is_taking)
1648 if (arg.Length == 0 || arg == "true" || arg == "false"){
1649 Report.Error (1001, Location, "Missing identifer to pre-processor directive");
1653 if (arg.IndexOfAny (simple_whitespaces) != -1){
1654 Error_EndLineExpected ();
1658 if (!is_identifier_start_character (arg [0]))
1659 Report.Error (1001, Location, "Identifier expected: " + arg);
1661 foreach (char c in arg.Substring (1)){
1662 if (!is_identifier_part_character (c)){
1663 Report.Error (1001, Location, "Identifier expected: " + arg);
1668 if (!caller_is_taking)
1672 if (defines == null)
1673 defines = new Hashtable ();
1676 if (defines == null)
1678 if (defines.Contains (arg))
1679 defines.Remove (arg);
1684 /// Handles #pragma directive
1686 void PreProcessPragma (string arg)
1688 const string warning = "warning";
1689 const string w_disable = "warning disable";
1690 const string w_restore = "warning restore";
1692 if (arg == w_disable) {
1693 Report.RegisterWarningRegion (Location).WarningDisable (Location.Row);
1697 if (arg == w_restore) {
1698 Report.RegisterWarningRegion (Location).WarningEnable (Location.Row);
1702 if (arg.StartsWith (w_disable)) {
1703 int[] codes = ParseNumbers (arg.Substring (w_disable.Length));
1704 foreach (int code in codes) {
1706 Report.RegisterWarningRegion (Location).WarningDisable (Location, code);
1711 if (arg.StartsWith (w_restore)) {
1712 int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
1713 Hashtable w_table = Report.warning_ignore_table;
1714 foreach (int code in codes) {
1715 if (w_table != null && w_table.Contains (code))
1716 Report.Warning (1635, 1, Location, String.Format ("Cannot restore warning `CS{0:0000}' because it was disabled globally", code));
1717 Report.RegisterWarningRegion (Location).WarningEnable (Location, code);
1722 if (arg.StartsWith (warning)) {
1723 Report.Warning (1634, 1, Location, "Expected disable or restore");
1727 Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
1730 int[] ParseNumbers (string text)
1732 string[] string_array = text.Split (',');
1733 int[] values = new int [string_array.Length];
1735 foreach (string string_code in string_array) {
1737 values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);
1739 catch (FormatException) {
1740 Report.Warning (1692, 1, Location, "Invalid number");
1746 bool eval_val (string s)
1753 if (defines == null)
1755 if (defines.Contains (s))
1761 bool pp_primary (ref string s)
1770 s = s.Substring (1);
1771 bool val = pp_expr (ref s, false);
1772 if (s.Length > 0 && s [0] == ')'){
1773 s = s.Substring (1);
1776 Error_InvalidDirective ();
1780 if (is_identifier_start_character (c)){
1786 if (is_identifier_part_character (c)){
1790 bool v = eval_val (s.Substring (0, j));
1791 s = s.Substring (j);
1794 bool vv = eval_val (s);
1799 Error_InvalidDirective ();
1803 bool pp_unary (ref string s)
1810 if (len > 1 && s [1] == '='){
1811 Error_InvalidDirective ();
1814 s = s.Substring (1);
1815 return ! pp_primary (ref s);
1817 return pp_primary (ref s);
1819 Error_InvalidDirective ();
1824 bool pp_eq (ref string s)
1826 bool va = pp_unary (ref s);
1832 if (len > 2 && s [1] == '='){
1833 s = s.Substring (2);
1834 return va == pp_unary (ref s);
1836 Error_InvalidDirective ();
1839 } else if (s [0] == '!' && len > 1 && s [1] == '='){
1840 s = s.Substring (2);
1842 return va != pp_unary (ref s);
1851 bool pp_and (ref string s)
1853 bool va = pp_eq (ref s);
1859 if (len > 2 && s [1] == '&'){
1860 s = s.Substring (2);
1861 return (va & pp_and (ref s));
1863 Error_InvalidDirective ();
1872 // Evaluates an expression for `#if' or `#elif'
1874 bool pp_expr (ref string s, bool isTerm)
1876 bool va = pp_and (ref s);
1883 if (len > 2 && s [1] == '|'){
1884 s = s.Substring (2);
1885 return va | pp_expr (ref s, isTerm);
1887 Error_InvalidDirective ();
1892 Error_EndLineExpected ();
1900 bool eval (string s)
1902 bool v = pp_expr (ref s, true);
1911 void Error_NumericConstantTooLong ()
1913 Report.Error (1021, Location, "Numeric constant too long");
1916 void Error_InvalidDirective ()
1918 Report.Error (1517, Location, "Invalid preprocessor directive");
1921 void Error_UnexpectedDirective (string extra)
1925 "Unexpected processor directive (" + extra + ")");
1928 void Error_TokenExpected (string token)
1930 Report.Error (1026, Location, "Expected `{0}'", token);
1933 void Error_TokensSeen ()
1935 Report.Error (1032, Location,
1936 "Cannot define or undefine preprocessor symbols after first token in file");
1939 void Eror_WrongPreprocessorLocation ()
1941 Report.Error (1040, Location,
1942 "Preprocessor directives must appear as the first non-whitespace character on a line");
1945 void Error_EndLineExpected ()
1947 Report.Error (1025, Location, "Single-line comment or end-of-line expected");
1951 // if true, then the code continues processing the code
1952 // if false, the code stays in a loop until another directive is
1954 // When caller_is_taking is false we ignore all directives except the ones
1955 // which can help us to identify where the #if block ends
1956 bool handle_preprocessing_directive (bool caller_is_taking)
1959 bool region_directive = false;
1961 get_cmd_arg (out cmd, out arg);
1963 // Eat any trailing whitespaces and single-line comments
1964 if (arg.IndexOf ("//") != -1)
1965 arg = arg.Substring (0, arg.IndexOf ("//"));
1966 arg = arg.Trim (simple_whitespaces);
1969 // The first group of pre-processing instructions is always processed
1973 region_directive = true;
1978 if (ifstack == null || ifstack.Count == 0){
1979 Error_UnexpectedDirective ("no #region for this #endregion");
1982 int pop = (int) ifstack.Pop ();
1984 if ((pop & REGION) == 0)
1985 Report.Error (1027, Location, "Expected `#endif' directive");
1987 return caller_is_taking;
1990 if (ifstack == null)
1991 ifstack = new Stack (2);
1993 int flags = region_directive ? REGION : 0;
1994 if (ifstack.Count == 0){
1995 flags |= PARENT_TAKING;
1997 int state = (int) ifstack.Peek ();
1998 if ((state & TAKING) != 0) {
1999 flags |= PARENT_TAKING;
2003 if (caller_is_taking && eval (arg)) {
2004 ifstack.Push (flags | TAKING);
2007 ifstack.Push (flags);
2011 if (ifstack == null || ifstack.Count == 0){
2012 Error_UnexpectedDirective ("no #if for this #endif");
2015 pop = (int) ifstack.Pop ();
2017 if ((pop & REGION) != 0)
2018 Report.Error (1038, Location, "#endregion directive expected");
2020 if (arg.Length != 0) {
2021 Error_EndLineExpected ();
2024 if (ifstack.Count == 0)
2027 int state = (int) ifstack.Peek ();
2028 return (state & TAKING) != 0;
2032 if (ifstack == null || ifstack.Count == 0){
2033 Error_UnexpectedDirective ("no #if for this #elif");
2036 int state = (int) ifstack.Pop ();
2038 if ((state & REGION) != 0) {
2039 Report.Error (1038, Location, "#endregion directive expected");
2043 if ((state & ELSE_SEEN) != 0){
2044 Error_UnexpectedDirective ("#elif not valid after #else");
2048 if ((state & TAKING) != 0) {
2053 if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2054 ifstack.Push (state | TAKING);
2058 ifstack.Push (state);
2063 if (ifstack == null || ifstack.Count == 0){
2064 Error_UnexpectedDirective ("no #if for this #else");
2067 int state = (int) ifstack.Peek ();
2069 if ((state & REGION) != 0) {
2070 Report.Error (1038, Location, "#endregion directive expected");
2074 if ((state & ELSE_SEEN) != 0){
2075 Error_UnexpectedDirective ("#else within #else");
2081 if (arg.Length != 0) {
2082 Error_EndLineExpected ();
2087 if ((state & PARENT_TAKING) != 0) {
2088 ret = (state & TAKING) == 0;
2096 ifstack.Push (state | ELSE_SEEN);
2101 if (any_token_seen){
2102 Error_TokensSeen ();
2103 return caller_is_taking;
2105 PreProcessDefinition (true, arg, caller_is_taking);
2106 return caller_is_taking;
2109 if (any_token_seen){
2110 Error_TokensSeen ();
2111 return caller_is_taking;
2113 PreProcessDefinition (false, arg, caller_is_taking);
2114 return caller_is_taking;
2118 // These are only processed if we are in a `taking' block
2120 if (!caller_is_taking)
2125 Report.Error (1029, Location, "#error: '" + arg + "'");
2129 Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2133 if (RootContext.Version == LanguageVersion.ISO_1) {
2134 Report.FeatureIsNotAvailable (Location, "#pragma");
2138 PreProcessPragma (arg);
2142 if (!PreProcessLine (arg))
2145 "The line number specified for #line directive is missing or invalid");
2146 return caller_is_taking;
2149 Report.Error (1024, Location, "Wrong preprocessor directive");
2154 private int consume_string (bool quoted)
2157 string_builder.Length = 0;
2159 while ((c = get_char ()) != -1){
2161 if (quoted && peek_char () == '"'){
2162 string_builder.Append ((char) c);
2166 val = string_builder.ToString ();
2167 return Token.LITERAL_STRING;
2173 Report.Error (1010, Location, "Newline in constant");
2181 string_builder.Append ((char) c);
2184 Report.Error (1039, Location, "Unterminated string literal");
2188 private int consume_identifier (int s)
2190 int res = consume_identifier (s, false);
2192 if (doc_state == XmlCommentState.Allowed)
2193 doc_state = XmlCommentState.NotAllowed;
2196 case Token.NAMESPACE:
2197 check_incorrect_doc_comment ();
2201 if (res == Token.PARTIAL) {
2202 if (parsing_block > 0) {
2203 val = new LocatedToken (Location, "partial");
2204 return Token.IDENTIFIER;
2207 // Save current position and parse next token.
2210 int next_token = token ();
2211 bool ok = (next_token == Token.CLASS) ||
2212 (next_token == Token.STRUCT) ||
2213 (next_token == Token.INTERFACE) ||
2214 (next_token == Token.VOID);
2219 if (next_token == Token.VOID) {
2220 if (RootContext.Version <= LanguageVersion.ISO_2)
2221 Report.FeatureIsNotAvailable (Location, "partial methods");
2222 } else if (RootContext.Version == LanguageVersion.ISO_1)
2223 Report.FeatureIsNotAvailable (Location, "partial types");
2228 if (next_token < Token.LAST_KEYWORD)
2229 Report.Error (267, Location, "The `partial' modifier can be used only immediately before `class', `struct', `interface', or `void' keyword");
2231 val = new LocatedToken (Location, "partial");
2232 return Token.IDENTIFIER;
2238 private int consume_identifier (int s, bool quoted)
2243 id_builder [0] = (char) s;
2245 current_location = new Location (ref_line, Col);
2247 while ((c = get_char ()) != -1) {
2249 if (is_identifier_part_character ((char) c)){
2250 if (pos == max_id_size){
2251 Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
2255 id_builder [pos++] = (char) c;
2256 // putback_char = -1;
2257 } else if (c == '\\') {
2261 // putback_char = c;
2268 // Optimization: avoids doing the keyword lookup
2269 // on uppercase letters and _
2271 if (!quoted && (s >= 'a' || s == '_')){
2272 int keyword = GetKeyword (id_builder, pos);
2273 if (keyword != -1) {
2280 // Keep identifiers in an array of hashtables to avoid needless
2284 if (identifiers [pos] != null) {
2285 val = identifiers [pos][id_builder];
2287 val = new LocatedToken (Location, (string) val);
2289 escaped_identifiers.Add (val);
2290 return Token.IDENTIFIER;
2294 identifiers [pos] = new CharArrayHashtable (pos);
2296 val = new String (id_builder, 0, pos);
2297 if (RootContext.Version == LanguageVersion.ISO_1) {
2298 for (int i = 1; i < id_builder.Length; i += 3) {
2299 if (id_builder [i] == '_' && (id_builder [i - 1] == '_' || id_builder [i + 1] == '_')) {
2300 Report.Error (1638, Location,
2301 "`{0}': Any identifier with double underscores cannot be used when ISO language version mode is specified", val.ToString ());
2307 char [] chars = new char [pos];
2308 Array.Copy (id_builder, chars, pos);
2310 identifiers [pos] [chars] = val;
2312 val = new LocatedToken (Location, (string) val);
2314 escaped_identifiers.Add (val);
2315 return Token.IDENTIFIER;
2318 public int xtoken ()
2321 bool doread = false;
2324 // Whether we have seen comments on the current line
2325 bool comments_seen = false;
2327 for (;(c = get_char ()) != -1;) {
2329 col = ((col + 8) / 8) * 8;
2333 if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
2337 if (peek_char () != '\n')
2342 any_token_seen |= tokens_seen;
2343 tokens_seen = false;
2344 comments_seen = false;
2348 // Handle double-slash comments.
2350 int d = peek_char ();
2354 if (RootContext.Documentation != null && peek_char () == '/') {
2356 // Don't allow ////.
2357 if ((d = peek_char ()) != '/') {
2358 update_comment_location ();
2359 if (doc_state == XmlCommentState.Allowed)
2360 handle_one_line_xml_comment ();
2361 else if (doc_state == XmlCommentState.NotAllowed)
2362 warn_incorrect_doc_comment ();
2365 while ((d = get_char ()) != -1 && (d != '\n') && d != '\r')
2368 any_token_seen |= tokens_seen;
2369 tokens_seen = false;
2370 comments_seen = false;
2372 } else if (d == '*'){
2374 bool docAppend = false;
2375 if (RootContext.Documentation != null && peek_char () == '*') {
2377 update_comment_location ();
2378 // But when it is /**/, just do nothing.
2379 if (peek_char () == '/') {
2383 if (doc_state == XmlCommentState.Allowed)
2385 else if (doc_state == XmlCommentState.NotAllowed)
2386 warn_incorrect_doc_comment ();
2389 int current_comment_start = 0;
2391 current_comment_start = xml_comment_buffer.Length;
2392 xml_comment_buffer.Append (Environment.NewLine);
2395 Location start_location = Location;
2397 while ((d = get_char ()) != -1){
2398 if (d == '*' && peek_char () == '/'){
2400 comments_seen = true;
2404 xml_comment_buffer.Append ((char) d);
2407 any_token_seen |= tokens_seen;
2408 tokens_seen = false;
2410 // Reset 'comments_seen' just to be consistent.
2411 // It doesn't matter either way, here.
2413 comments_seen = false;
2417 Report.Error (1035, start_location, "End-of-file found, '*/' expected");
2420 update_formatted_doc_comment (current_comment_start);
2423 goto is_punct_label;
2427 if (c == '\\' || is_identifier_start_character ((char)c)){
2429 return consume_identifier (c);
2433 current_location = new Location (ref_line, Col);
2434 if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
2444 any_token_seen |= tokens_seen;
2445 tokens_seen = false;
2446 comments_seen = false;
2450 if (c >= '0' && c <= '9'){
2452 return is_number (c);
2457 int peek = peek_char ();
2458 if (peek >= '0' && peek <= '9')
2459 return is_number (c);
2464 if (tokens_seen || comments_seen) {
2465 Eror_WrongPreprocessorLocation ();
2469 if (handle_preprocessing_directive (true))
2472 bool directive_expected = false;
2473 while ((c = get_char ()) != -1) {
2475 directive_expected = true;
2476 } else if (!directive_expected) {
2477 // TODO: Implement comment support for disabled code and uncomment this code
2479 // Eror_WrongPreprocessorLocation ();
2480 // return Token.ERROR;
2485 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || c == '\v' )
2489 if (handle_preprocessing_directive (false))
2492 directive_expected = false;
2496 tokens_seen = false;
2504 return consume_string (false);
2510 error_details = "Empty character literal";
2511 Report.Error (1011, Location, error_details);
2514 if (c == '\r' || c == '\n') {
2515 Report.Error (1010, Location, "Newline in constant");
2521 val = new System.Char ();
2526 error_details = "Too many characters in character literal";
2527 Report.Error (1012, Location, error_details);
2529 // Try to recover, read until newline or next "'"
2530 while ((c = get_char ()) != -1){
2539 return Token.LITERAL_CHARACTER;
2546 return consume_string (true);
2547 } else if (is_identifier_start_character ((char) c)){
2548 return consume_identifier (c, true);
2550 Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
2554 error_details = ((char)c).ToString ();
2563 // Handles one line xml comment
2565 private void handle_one_line_xml_comment ()
2568 while ((c = peek_char ()) == ' ')
2569 get_char (); // skip heading whitespaces.
2570 while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
2571 xml_comment_buffer.Append ((char) get_char ());
2573 if (c == '\r' || c == '\n')
2574 xml_comment_buffer.Append (Environment.NewLine);
2578 // Remove heading "*" in Javadoc-like xml documentation.
2580 private void update_formatted_doc_comment (int current_comment_start)
2582 int length = xml_comment_buffer.Length - current_comment_start;
2583 string [] lines = xml_comment_buffer.ToString (
2584 current_comment_start,
2585 length).Replace ("\r", "").Split ('\n');
2587 // The first line starts with /**, thus it is not target
2588 // for the format check.
2589 for (int i = 1; i < lines.Length; i++) {
2590 string s = lines [i];
2591 int idx = s.IndexOf ('*');
2594 if (i < lines.Length - 1)
2598 head = s.Substring (0, idx);
2599 foreach (char c in head)
2602 lines [i] = s.Substring (idx + 1);
2604 xml_comment_buffer.Remove (current_comment_start, length);
2605 xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
2609 // Updates current comment location.
2611 private void update_comment_location ()
2613 if (current_comment_location.IsNull) {
2614 // "-2" is for heading "//" or "/*"
2615 current_comment_location =
2616 new Location (ref_line, col - 2);
2621 // Checks if there was incorrect doc comments and raise
2624 public void check_incorrect_doc_comment ()
2626 if (xml_comment_buffer.Length > 0)
2627 warn_incorrect_doc_comment ();
2631 // Raises a warning when tokenizer found incorrect doccomment
2634 private void warn_incorrect_doc_comment ()
2636 if (doc_state != XmlCommentState.Error) {
2637 doc_state = XmlCommentState.Error;
2638 // in csc, it is 'XML comment is not placed on
2639 // a valid language element'. But that does not
2641 Report.Warning (1587, 2, Location, "XML comment is not placed on a valid language element");
2646 // Consumes the saved xml comment lines (if any)
2647 // as for current target member or type.
2649 public string consume_doc_comment ()
2651 if (xml_comment_buffer.Length > 0) {
2652 string ret = xml_comment_buffer.ToString ();
2653 reset_doc_comment ();
2659 void reset_doc_comment ()
2661 xml_comment_buffer.Length = 0;
2662 current_comment_location = Location.Null;
2665 public void cleanup ()
2667 if (ifstack != null && ifstack.Count >= 1) {
2668 current_location = new Location (ref_line, Col);
2669 int state = (int) ifstack.Pop ();
2670 if ((state & REGION) != 0)
2671 Report.Error (1038, Location, "#endregion directive expected");
2673 Report.Error (1027, Location, "Expected `#endif' directive");
2679 // Indicates whether it accepts XML documentation or not.
2681 public enum XmlCommentState {
2682 // comment is allowed in this state.
2684 // comment is not allowed in this state.
2686 // once comments appeared when it is NotAllowed, then the
2687 // state is changed to it, until the state is changed to