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;
50 internal int query_parsing;
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);
399 AddKeyword ("from", Token.FROM);
400 AddKeyword ("join", Token.JOIN);
401 AddKeyword ("on", Token.ON);
402 AddKeyword ("equals", Token.EQUALS);
403 AddKeyword ("select", Token.SELECT);
404 AddKeyword ("group", Token.GROUP);
405 AddKeyword ("by", Token.BY);
406 AddKeyword ("let", Token.LET);
407 AddKeyword ("orderby", Token.ORDERBY);
408 AddKeyword ("ascending", Token.ASCENDING);
409 AddKeyword ("descending", Token.DESCENDING);
410 AddKeyword ("into", Token.INTO);
422 public static void Reset ()
425 csharp_format_info = NumberFormatInfo.InvariantInfo;
426 styles = NumberStyles.Float;
428 string_builder = new System.Text.StringBuilder ();
431 int GetKeyword (char[] id, int id_len)
434 * Keywords are stored in an array of hashtables grouped by their
438 if ((id_len >= keywords.Length) || (keywords [id_len] == null))
440 object o = keywords [id_len] [id];
447 if (!handle_get_set && (res == Token.GET || res == Token.SET))
449 if (!handle_remove_add && (res == Token.REMOVE || res == Token.ADD))
451 if (!handle_assembly && res == Token.ASSEMBLY)
455 // A query expression is any expression that starts with `from identifier'
456 // followed by any token except ; , =
458 if (query_parsing == 0) {
459 if (res == Token.FROM && !lambda_arguments_parsing) {
461 // HACK: to disable generics micro-parser, because PushPosition does not
462 // store identifiers array
463 parsing_generic_less_than = 1;
465 case Token.IDENTIFIER:
477 int next_token = xtoken ();
478 if (next_token == Token.SEMICOLON || next_token == Token.COMMA || next_token == Token.EQUALS)
482 if (RootContext.Version <= LanguageVersion.ISO_2)
483 Report.FeatureIsNotAvailable (Location, "query expressions");
486 Expression.Error_VoidInvalidInTheContext (Location);
490 // HACK: A token is not a keyword so we need to restore identifiers buffer
491 // which has been overwritten before we grabbed the identifier
492 id_builder [0] = 'f'; id_builder [1] = 'r'; id_builder [2] = 'o'; id_builder [3] = 'm';
499 if (res > Token.QUERY_FIRST_TOKEN && res < Token.QUERY_LAST_TOKEN)
503 if (res == Token.WHERE && !handle_where && query_parsing == 0)
510 public Location Location {
511 get { return current_location; }
514 void define (string def)
516 if (!RootContext.AllDefines.Contains (def)){
517 RootContext.AllDefines [def] = true;
519 if (defines.Contains (def))
521 defines [def] = true;
524 public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
526 this.ref_name = file;
527 this.file_name = file;
533 defines = new Hashtable ();
534 foreach (string def in defs)
538 xml_comment_buffer = new StringBuilder ();
541 // FIXME: This could be `Location.Push' but we have to
542 // find out why the MS compiler allows this
544 Mono.CSharp.Location.Push (file);
547 static bool is_identifier_start_character (char c)
549 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter (c);
552 static bool is_identifier_part_character (char c)
554 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') ||
555 Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
558 public static bool IsKeyword (string s)
560 return keyword_strings [s] != null;
564 // Tests whether '(' is beggining of lambda parameters
566 bool IsLambdaOpenParens ()
569 while ((ntoken = xtoken ()) != Token.EOF) {
571 case Token.CLOSE_PARENS:
572 return xtoken () == Token.ARROW;
575 case Token.SEMICOLON:
576 case Token.OPEN_PARENS:
581 Error_TokenExpected (")");
585 public static bool IsValidIdentifier (string s)
587 if (s == null || s.Length == 0)
590 if (!is_identifier_start_character (s [0]))
593 for (int i = 1; i < s.Length; i ++)
594 if (! is_identifier_part_character (s [i]))
600 bool parse_less_than ()
603 int the_token = token ();
604 if (the_token == Token.OPEN_BRACKET) {
606 the_token = token ();
607 } while (the_token != Token.CLOSE_BRACKET);
608 the_token = token ();
611 case Token.IDENTIFIER:
634 the_token = token ();
636 if (the_token == Token.OP_GENERICS_GT)
638 else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
640 else if (the_token == Token.INTERR || the_token == Token.STAR)
642 else if (the_token == Token.OP_GENERICS_LT) {
643 if (!parse_less_than ())
646 } else if (the_token == Token.OPEN_BRACKET) {
648 the_token = token ();
649 if (the_token == Token.CLOSE_BRACKET)
651 else if (the_token == Token.COMMA)
652 goto rank_specifiers;
660 public void PutbackNullable ()
662 if (nullable_pos < 0)
663 throw new Exception ();
667 reader.Position = nullable_pos;
672 public void PutbackCloseParens ()
678 int nullable_pos = -1;
680 public void CheckNullable (bool is_nullable)
683 nullable_pos = reader.Position;
688 bool parse_generic_dimension (out int dimension)
693 int the_token = token ();
694 if (the_token == Token.OP_GENERICS_GT)
696 else if (the_token == Token.COMMA) {
705 public int peek_token ()
710 the_token = token ();
716 int parsing_generic_less_than = 0;
718 int is_punct (char c, ref bool doread)
728 return Token.OPEN_BRACE;
731 return Token.CLOSE_BRACE;
733 // To block doccomment inside attribute declaration.
734 if (doc_state == XmlCommentState.Allowed)
735 doc_state = XmlCommentState.NotAllowed;
736 return Token.OPEN_BRACKET;
738 return Token.CLOSE_BRACKET;
740 if (IsLinqEnabled && !lambda_arguments_parsing) {
741 lambda_arguments_parsing = true;
743 bool lambda_start = IsLambdaOpenParens ();
745 lambda_arguments_parsing = false;
747 return Token.OPEN_PARENS_LAMBDA;
749 return Token.OPEN_PARENS;
751 if (deambiguate_close_parens == 0)
752 return Token.CLOSE_PARENS;
754 --deambiguate_close_parens;
758 int new_token = xtoken ();
762 if (new_token == Token.OPEN_PARENS)
763 return Token.CLOSE_PARENS_OPEN_PARENS;
764 else if (new_token == Token.MINUS)
765 return Token.CLOSE_PARENS_MINUS;
766 else if (IsCastToken (new_token))
767 return Token.CLOSE_PARENS_CAST;
769 return Token.CLOSE_PARENS_NO_CAST;
776 return Token.SEMICOLON;
785 return Token.OP_COALESCING;
792 if (parsing_generic_less_than++ > 0)
793 return Token.OP_GENERICS_LT;
798 if (parse_generic_dimension (out dimension)) {
801 return Token.GENERIC_DIMENSION;
806 // Save current position and parse next token.
808 bool is_generic_lt = parse_less_than ();
812 return Token.OP_GENERICS_LT;
814 parsing_generic_less_than = 0;
823 return Token.OP_SHIFT_LEFT_ASSIGN;
825 return Token.OP_SHIFT_LEFT;
826 } else if (d == '='){
831 } else if (c == '>') {
832 if (parsing_generic_less_than > 0) {
833 parsing_generic_less_than--;
834 return Token.OP_GENERICS_GT;
844 return Token.OP_SHIFT_RIGHT_ASSIGN;
846 return Token.OP_SHIFT_RIGHT;
847 } else if (d == '='){
862 t = Token.OP_ADD_ASSIGN;
876 t = Token.OP_SUB_ASSIGN;
914 } else if (d == '='){
916 return Token.OP_AND_ASSIGN;
919 return Token.BITWISE_AND;
926 } else if (d == '='){
928 return Token.OP_OR_ASSIGN;
930 return Token.BITWISE_OR;
936 return Token.OP_MULT_ASSIGN;
945 return Token.OP_DIV_ASSIGN;
953 return Token.OP_MOD_ASSIGN;
955 return Token.PERCENT;
961 return Token.OP_XOR_ASSIGN;
974 return Token.OP_SHIFT_LEFT_ASSIGN;
976 return Token.OP_SHIFT_LEFT;
977 } else if (d == '='){
991 return Token.OP_SHIFT_RIGHT_ASSIGN;
993 return Token.OP_SHIFT_RIGHT;
994 } else if (d == '='){
1004 return Token.DOUBLE_COLON;
1013 int deambiguate_close_parens = 0;
1015 public void Deambiguate_CloseParens (object expression)
1019 // When any binary operation is used we are sure it is not a cast
1020 if (expression is Binary)
1023 deambiguate_close_parens++;
1026 bool decimal_digits (int c)
1029 bool seen_digits = false;
1032 if (number_pos == max_number_size)
1033 Error_NumericConstantTooLong ();
1034 number_builder [number_pos++] = (char) c;
1038 // We use peek_char2, because decimal_digits needs to do a
1039 // 2-character look-ahead (5.ToString for example).
1041 while ((d = peek_char2 ()) != -1){
1042 if (d >= '0' && d <= '9'){
1043 if (number_pos == max_number_size)
1044 Error_NumericConstantTooLong ();
1045 number_builder [number_pos++] = (char) d;
1055 static bool is_hex (int e)
1057 return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1060 static int real_type_suffix (int c)
1066 t = Token.LITERAL_FLOAT;
1069 t = Token.LITERAL_DOUBLE;
1072 t= Token.LITERAL_DECIMAL;
1080 int integer_type_suffix (ulong ul, int c)
1082 bool is_unsigned = false;
1083 bool is_long = false;
1086 bool scanning = true;
1099 // if we have not seen anything in between
1100 // report this error
1102 Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1105 // This goto statement causes the MS CLR 2.0 beta 1 csc to report an error, so
1106 // work around that.
1130 if (is_long && is_unsigned){
1132 return Token.LITERAL_INTEGER;
1133 } else if (is_unsigned){
1134 // uint if possible, or ulong else.
1136 if ((ul & 0xffffffff00000000) == 0)
1140 } else if (is_long){
1141 // long if possible, ulong otherwise
1142 if ((ul & 0x8000000000000000) != 0)
1147 // int, uint, long or ulong in that order
1148 if ((ul & 0xffffffff00000000) == 0){
1149 uint ui = (uint) ul;
1151 if ((ui & 0x80000000) != 0)
1156 if ((ul & 0x8000000000000000) != 0)
1162 return Token.LITERAL_INTEGER;
1166 // given `c' as the next char in the input decide whether
1167 // we need to convert to a special type, and then choose
1168 // the best representation for the integer
1170 int adjust_int (int c)
1173 if (number_pos > 9){
1174 ulong ul = (uint) (number_builder [0] - '0');
1176 for (int i = 1; i < number_pos; i++){
1177 ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1179 return integer_type_suffix (ul, c);
1181 uint ui = (uint) (number_builder [0] - '0');
1183 for (int i = 1; i < number_pos; i++){
1184 ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1186 return integer_type_suffix (ui, c);
1188 } catch (OverflowException) {
1189 error_details = "Integral constant is too large";
1190 Report.Error (1021, Location, error_details);
1192 return Token.LITERAL_INTEGER;
1194 catch (FormatException) {
1195 Report.Error (1013, Location, "Invalid number");
1197 return Token.LITERAL_INTEGER;
1201 int adjust_real (int t)
1203 string s = new String (number_builder, 0, number_pos);
1204 const string error_details = "Floating-point constant is outside the range of type `{0}'";
1207 case Token.LITERAL_DECIMAL:
1209 val = System.Decimal.Parse (s, styles, csharp_format_info);
1210 } catch (OverflowException) {
1212 Report.Error (594, Location, error_details, "decimal");
1215 case Token.LITERAL_FLOAT:
1217 val = float.Parse (s, styles, csharp_format_info);
1218 } catch (OverflowException) {
1220 Report.Error (594, Location, error_details, "float");
1224 case Token.LITERAL_DOUBLE:
1226 t = Token.LITERAL_DOUBLE;
1228 val = System.Double.Parse (s, styles, csharp_format_info);
1229 } catch (OverflowException) {
1231 Report.Error (594, Location, error_details, "double");
1244 while ((d = peek_char ()) != -1){
1246 number_builder [number_pos++] = (char) d;
1252 string s = new String (number_builder, 0, number_pos);
1254 if (number_pos <= 8)
1255 ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1257 ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1258 } catch (OverflowException){
1259 error_details = "Integral constant is too large";
1260 Report.Error (1021, Location, error_details);
1262 return Token.LITERAL_INTEGER;
1264 catch (FormatException) {
1265 Report.Error (1013, Location, "Invalid number");
1267 return Token.LITERAL_INTEGER;
1270 return integer_type_suffix (ul, peek_char ());
1274 // Invoked if we know we have .digits or digits
1276 int is_number (int c)
1278 bool is_real = false;
1283 if (c >= '0' && c <= '9'){
1285 int peek = peek_char ();
1287 if (peek == 'x' || peek == 'X')
1288 return handle_hex ();
1295 // We need to handle the case of
1296 // "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1299 if (decimal_digits ('.')){
1305 return adjust_int (-1);
1309 if (c == 'e' || c == 'E'){
1311 if (number_pos == max_number_size)
1312 Error_NumericConstantTooLong ();
1313 number_builder [number_pos++] = 'e';
1317 if (number_pos == max_number_size)
1318 Error_NumericConstantTooLong ();
1319 number_builder [number_pos++] = '+';
1321 } else if (c == '-') {
1322 if (number_pos == max_number_size)
1323 Error_NumericConstantTooLong ();
1324 number_builder [number_pos++] = '-';
1327 if (number_pos == max_number_size)
1328 Error_NumericConstantTooLong ();
1329 number_builder [number_pos++] = '+';
1336 type = real_type_suffix (c);
1337 if (type == Token.NONE && !is_real){
1339 return adjust_int (c);
1343 if (type == Token.NONE){
1348 return adjust_real (type);
1350 Console.WriteLine ("This should not be reached");
1351 throw new Exception ("Is Number should never reach this point");
1355 // Accepts exactly count (4 or 8) hex, no more no less
1357 int getHex (int count, out bool error)
1362 int top = count != -1 ? count : 4;
1366 for (i = 0; i < top; i++){
1369 if (c >= '0' && c <= '9')
1370 c = (int) c - (int) '0';
1371 else if (c >= 'A' && c <= 'F')
1372 c = (int) c - (int) 'A' + 10;
1373 else if (c >= 'a' && c <= 'f')
1374 c = (int) c - (int) 'a' + 10;
1380 total = (total * 16) + c;
1382 int p = peek_char ();
1385 if (!is_hex ((char)p))
1426 v = getHex (-1, out error);
1431 v = getHex (4, out error);
1436 v = getHex (8, out error);
1441 Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1451 if (putback_char != -1) {
1469 if (putback_char != -1)
1470 return putback_char;
1471 putback_char = reader.Read ();
1472 return putback_char;
1477 if (putback_char != -1)
1478 return putback_char;
1479 return reader.Peek ();
1482 void putback (int c)
1484 if (putback_char != -1){
1485 Console.WriteLine ("Col: " + col);
1486 Console.WriteLine ("Row: " + line);
1487 Console.WriteLine ("Name: " + ref_name.Name);
1488 Console.WriteLine ("Current [{0}] putting back [{1}] ", putback_char, c);
1489 throw new Exception ("This should not happen putback on putback");
1491 if (c == '\n' || col == 0) {
1492 // It won't happen though.
1502 public bool advance ()
1504 return peek_char () != -1;
1507 public Object Value {
1513 public Object value ()
1518 static bool IsCastToken (int token)
1523 case Token.IDENTIFIER:
1524 case Token.LITERAL_INTEGER:
1525 case Token.LITERAL_FLOAT:
1526 case Token.LITERAL_DOUBLE:
1527 case Token.LITERAL_DECIMAL:
1528 case Token.LITERAL_CHARACTER:
1529 case Token.LITERAL_STRING:
1532 case Token.DELEGATE:
1542 case Token.UNCHECKED:
1549 // These can be part of a member access
1569 current_token = xtoken ();
1572 if (current_token != Token.DEFAULT)
1573 return current_token;
1578 current_token = Token.ERROR;
1579 else if (c == Token.OPEN_PARENS)
1580 current_token = Token.DEFAULT_OPEN_PARENS;
1581 else if (c == Token.COLON)
1582 current_token = Token.DEFAULT_COLON;
1586 return current_token;
1589 static StringBuilder static_cmd_arg = new System.Text.StringBuilder ();
1591 void get_cmd_arg (out string cmd, out string arg)
1595 tokens_seen = false;
1597 static_cmd_arg.Length = 0;
1599 // skip over white space
1600 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1603 while ((c != -1) && (c != '\n') && (c != ' ') && (c != '\t') && (c != '\r')){
1604 if (is_identifier_part_character ((char) c)){
1605 static_cmd_arg.Append ((char) c);
1613 cmd = static_cmd_arg.ToString ();
1615 if (c == '\n' || c == '\r'){
1619 // skip over white space
1620 while ((c = get_char ()) != -1 && (c != '\n') && ((c == '\r') || (c == ' ') || (c == '\t')))
1625 } else if (c == '\r'){
1627 } else if (c == -1){
1632 static_cmd_arg.Length = 0;
1633 static_cmd_arg.Append ((char) c);
1635 while ((c = get_char ()) != -1 && (c != '\n') && (c != '\r')){
1636 static_cmd_arg.Append ((char) c);
1639 arg = static_cmd_arg.ToString ();
1643 // Handles the #line directive
1645 bool PreProcessLine (string arg)
1647 if (arg.Length == 0)
1650 if (arg == "default"){
1652 ref_name = file_name;
1653 Location.Push (ref_name);
1655 } else if (arg == "hidden"){
1657 // We ignore #line hidden
1665 if ((pos = arg.IndexOf (' ')) != -1 && pos != 0){
1666 ref_line = System.Int32.Parse (arg.Substring (0, pos));
1669 char [] quotes = { '\"' };
1671 string name = arg.Substring (pos). Trim (quotes);
1672 ref_name = Location.LookupFile (name);
1673 file_name.HasLineDirective = true;
1674 ref_name.HasLineDirective = true;
1675 Location.Push (ref_name);
1677 ref_line = System.Int32.Parse (arg);
1687 // Handles #define and #undef
1689 void PreProcessDefinition (bool is_define, string arg, bool caller_is_taking)
1691 if (arg.Length == 0 || arg == "true" || arg == "false"){
1692 Report.Error (1001, Location, "Missing identifer to pre-processor directive");
1696 if (arg.IndexOfAny (simple_whitespaces) != -1){
1697 Error_EndLineExpected ();
1701 if (!is_identifier_start_character (arg [0]))
1702 Report.Error (1001, Location, "Identifier expected: " + arg);
1704 foreach (char c in arg.Substring (1)){
1705 if (!is_identifier_part_character (c)){
1706 Report.Error (1001, Location, "Identifier expected: " + arg);
1711 if (!caller_is_taking)
1715 if (defines == null)
1716 defines = new Hashtable ();
1719 if (defines == null)
1721 if (defines.Contains (arg))
1722 defines.Remove (arg);
1727 /// Handles #pragma directive
1729 void PreProcessPragma (string arg)
1731 const string warning = "warning";
1732 const string w_disable = "warning disable";
1733 const string w_restore = "warning restore";
1735 if (arg == w_disable) {
1736 Report.RegisterWarningRegion (Location).WarningDisable (line);
1740 if (arg == w_restore) {
1741 Report.RegisterWarningRegion (Location).WarningEnable (line);
1745 if (arg.StartsWith (w_disable)) {
1746 int[] codes = ParseNumbers (arg.Substring (w_disable.Length));
1747 foreach (int code in codes) {
1749 Report.RegisterWarningRegion (Location).WarningDisable (Location, code);
1754 if (arg.StartsWith (w_restore)) {
1755 int[] codes = ParseNumbers (arg.Substring (w_restore.Length));
1756 Hashtable w_table = Report.warning_ignore_table;
1757 foreach (int code in codes) {
1758 if (w_table != null && w_table.Contains (code))
1759 Report.Warning (1635, 1, Location, String.Format ("Cannot restore warning `CS{0:0000}' because it was disabled globally", code));
1760 Report.RegisterWarningRegion (Location).WarningEnable (Location, code);
1765 if (arg.StartsWith (warning)) {
1766 Report.Warning (1634, 1, Location, "Expected disable or restore");
1770 Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
1773 int[] ParseNumbers (string text)
1775 string[] string_array = text.Split (',');
1776 int[] values = new int [string_array.Length];
1778 foreach (string string_code in string_array) {
1780 values[index++] = int.Parse (string_code, System.Globalization.CultureInfo.InvariantCulture);
1782 catch (FormatException) {
1783 Report.Warning (1692, 1, Location, "Invalid number");
1789 bool eval_val (string s)
1796 if (defines == null)
1798 if (defines.Contains (s))
1804 bool pp_primary (ref string s)
1813 s = s.Substring (1);
1814 bool val = pp_expr (ref s, false);
1815 if (s.Length > 0 && s [0] == ')'){
1816 s = s.Substring (1);
1819 Error_InvalidDirective ();
1823 if (is_identifier_start_character (c)){
1829 if (is_identifier_part_character (c)){
1833 bool v = eval_val (s.Substring (0, j));
1834 s = s.Substring (j);
1837 bool vv = eval_val (s);
1842 Error_InvalidDirective ();
1846 bool pp_unary (ref string s)
1853 if (len > 1 && s [1] == '='){
1854 Error_InvalidDirective ();
1857 s = s.Substring (1);
1858 return ! pp_primary (ref s);
1860 return pp_primary (ref s);
1862 Error_InvalidDirective ();
1867 bool pp_eq (ref string s)
1869 bool va = pp_unary (ref s);
1875 if (len > 2 && s [1] == '='){
1876 s = s.Substring (2);
1877 return va == pp_unary (ref s);
1879 Error_InvalidDirective ();
1882 } else if (s [0] == '!' && len > 1 && s [1] == '='){
1883 s = s.Substring (2);
1885 return va != pp_unary (ref s);
1894 bool pp_and (ref string s)
1896 bool va = pp_eq (ref s);
1902 if (len > 2 && s [1] == '&'){
1903 s = s.Substring (2);
1904 return (va & pp_and (ref s));
1906 Error_InvalidDirective ();
1915 // Evaluates an expression for `#if' or `#elif'
1917 bool pp_expr (ref string s, bool isTerm)
1919 bool va = pp_and (ref s);
1926 if (len > 2 && s [1] == '|'){
1927 s = s.Substring (2);
1928 return va | pp_expr (ref s, isTerm);
1930 Error_InvalidDirective ();
1935 Error_EndLineExpected ();
1943 bool eval (string s)
1945 bool v = pp_expr (ref s, true);
1954 void Error_NumericConstantTooLong ()
1956 Report.Error (1021, Location, "Numeric constant too long");
1959 void Error_InvalidDirective ()
1961 Report.Error (1517, Location, "Invalid preprocessor directive");
1964 void Error_UnexpectedDirective (string extra)
1968 "Unexpected processor directive (" + extra + ")");
1971 void Error_TokenExpected (string token)
1973 Report.Error (1026, Location, "Expecting `{0}'", token);
1976 void Error_TokensSeen ()
1978 Report.Error (1032, Location,
1979 "Cannot define or undefine preprocessor symbols after first token in file");
1982 void Eror_WrongPreprocessorLocation ()
1984 Report.Error (1040, Location,
1985 "Preprocessor directives must appear as the first non-whitespace character on a line");
1988 void Error_EndLineExpected ()
1990 Report.Error (1025, Location, "Single-line comment or end-of-line expected");
1994 // if true, then the code continues processing the code
1995 // if false, the code stays in a loop until another directive is
1997 // When caller_is_taking is false we ignore all directives except the ones
1998 // which can help us to identify where the #if block ends
1999 bool handle_preprocessing_directive (bool caller_is_taking)
2002 bool region_directive = false;
2004 get_cmd_arg (out cmd, out arg);
2006 // Eat any trailing whitespaces and single-line comments
2007 if (arg.IndexOf ("//") != -1)
2008 arg = arg.Substring (0, arg.IndexOf ("//"));
2009 arg = arg.Trim (simple_whitespaces);
2012 // The first group of pre-processing instructions is always processed
2016 region_directive = true;
2021 if (ifstack == null || ifstack.Count == 0){
2022 Error_UnexpectedDirective ("no #region for this #endregion");
2025 int pop = (int) ifstack.Pop ();
2027 if ((pop & REGION) == 0)
2028 Report.Error (1027, Location, "Expected `#endif' directive");
2030 return caller_is_taking;
2033 if (ifstack == null)
2034 ifstack = new Stack (2);
2036 int flags = region_directive ? REGION : 0;
2037 if (ifstack.Count == 0){
2038 flags |= PARENT_TAKING;
2040 int state = (int) ifstack.Peek ();
2041 if ((state & TAKING) != 0) {
2042 flags |= PARENT_TAKING;
2046 if (caller_is_taking && eval (arg)) {
2047 ifstack.Push (flags | TAKING);
2050 ifstack.Push (flags);
2054 if (ifstack == null || ifstack.Count == 0){
2055 Error_UnexpectedDirective ("no #if for this #endif");
2058 pop = (int) ifstack.Pop ();
2060 if ((pop & REGION) != 0)
2061 Report.Error (1038, Location, "#endregion directive expected");
2063 if (arg.Length != 0) {
2064 Error_EndLineExpected ();
2067 if (ifstack.Count == 0)
2070 int state = (int) ifstack.Peek ();
2071 return (state & TAKING) != 0;
2075 if (ifstack == null || ifstack.Count == 0){
2076 Error_UnexpectedDirective ("no #if for this #elif");
2079 int state = (int) ifstack.Pop ();
2081 if ((state & REGION) != 0) {
2082 Report.Error (1038, Location, "#endregion directive expected");
2086 if ((state & ELSE_SEEN) != 0){
2087 Error_UnexpectedDirective ("#elif not valid after #else");
2091 if ((state & TAKING) != 0) {
2096 if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2097 ifstack.Push (state | TAKING);
2101 ifstack.Push (state);
2106 if (ifstack == null || ifstack.Count == 0){
2107 Error_UnexpectedDirective ("no #if for this #else");
2110 int state = (int) ifstack.Peek ();
2112 if ((state & REGION) != 0) {
2113 Report.Error (1038, Location, "#endregion directive expected");
2117 if ((state & ELSE_SEEN) != 0){
2118 Error_UnexpectedDirective ("#else within #else");
2124 if (arg.Length != 0) {
2125 Error_EndLineExpected ();
2130 if ((state & PARENT_TAKING) != 0) {
2131 ret = (state & TAKING) == 0;
2139 ifstack.Push (state | ELSE_SEEN);
2144 if (any_token_seen){
2145 Error_TokensSeen ();
2146 return caller_is_taking;
2148 PreProcessDefinition (true, arg, caller_is_taking);
2149 return caller_is_taking;
2152 if (any_token_seen){
2153 Error_TokensSeen ();
2154 return caller_is_taking;
2156 PreProcessDefinition (false, arg, caller_is_taking);
2157 return caller_is_taking;
2161 // These are only processed if we are in a `taking' block
2163 if (!caller_is_taking)
2168 Report.Error (1029, Location, "#error: '" + arg + "'");
2172 Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2176 if (RootContext.Version == LanguageVersion.ISO_1) {
2177 Report.FeatureIsNotAvailable (Location, "#pragma");
2181 PreProcessPragma (arg);
2185 if (!PreProcessLine (arg))
2188 "The line number specified for #line directive is missing or invalid");
2189 return caller_is_taking;
2192 Report.Error (1024, Location, "Wrong preprocessor directive");
2197 private int consume_string (bool quoted)
2200 string_builder.Length = 0;
2202 while ((c = get_char ()) != -1){
2204 if (quoted && peek_char () == '"'){
2205 string_builder.Append ((char) c);
2209 val = string_builder.ToString ();
2210 return Token.LITERAL_STRING;
2216 Report.Error (1010, Location, "Newline in constant");
2224 string_builder.Append ((char) c);
2227 Report.Error (1039, Location, "Unterminated string literal");
2231 private int consume_identifier (int s)
2233 int res = consume_identifier (s, false);
2235 if (doc_state == XmlCommentState.Allowed)
2236 doc_state = XmlCommentState.NotAllowed;
2239 case Token.NAMESPACE:
2240 check_incorrect_doc_comment ();
2244 if (res == Token.PARTIAL) {
2245 if (parsing_block > 0) {
2246 val = new LocatedToken (Location, "partial");
2247 return Token.IDENTIFIER;
2250 // Save current position and parse next token.
2253 int next_token = token ();
2254 bool ok = (next_token == Token.CLASS) ||
2255 (next_token == Token.STRUCT) ||
2256 (next_token == Token.INTERFACE) ||
2257 (next_token == Token.VOID);
2262 if (RootContext.Version == LanguageVersion.ISO_2 && next_token == Token.VOID) {
2263 Report.FeatureIsNotAvailable (Location, "partial methods");
2264 } else if (RootContext.Version == LanguageVersion.ISO_1)
2265 Report.FeatureIsNotAvailable (Location, "partial types");
2270 if (next_token < Token.LAST_KEYWORD)
2271 Report.Error (267, Location, "The `partial' modifier can be used only immediately before `class', `struct', `interface', or `void' keyword");
2273 val = new LocatedToken (Location, "partial");
2274 return Token.IDENTIFIER;
2280 private int consume_identifier (int s, bool quoted)
2285 id_builder [0] = (char) s;
2287 current_location = new Location (ref_line, Col);
2289 while ((c = get_char ()) != -1) {
2291 if (is_identifier_part_character ((char) c)){
2292 if (pos == max_id_size){
2293 Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
2297 id_builder [pos++] = (char) c;
2298 // putback_char = -1;
2299 } else if (c == '\\') {
2303 // putback_char = c;
2310 // Optimization: avoids doing the keyword lookup
2311 // on uppercase letters and _
2313 if (!quoted && (s >= 'a' || s == '_')){
2314 int keyword = GetKeyword (id_builder, pos);
2315 if (keyword != -1) {
2322 // Keep identifiers in an array of hashtables to avoid needless
2326 if (identifiers [pos] != null) {
2327 val = identifiers [pos][id_builder];
2329 val = new LocatedToken (Location, (string) val);
2331 escaped_identifiers.Add (val);
2332 return Token.IDENTIFIER;
2336 identifiers [pos] = new CharArrayHashtable (pos);
2338 val = new String (id_builder, 0, pos);
2339 if (RootContext.Version == LanguageVersion.ISO_1) {
2340 for (int i = 1; i < id_builder.Length; i += 3) {
2341 if (id_builder [i] == '_' && (id_builder [i - 1] == '_' || id_builder [i + 1] == '_')) {
2342 Report.Error (1638, Location,
2343 "`{0}': Any identifier with double underscores cannot be used when ISO language version mode is specified", val.ToString ());
2349 char [] chars = new char [pos];
2350 Array.Copy (id_builder, chars, pos);
2352 identifiers [pos] [chars] = val;
2354 val = new LocatedToken (Location, (string) val);
2356 escaped_identifiers.Add (val);
2357 return Token.IDENTIFIER;
2360 public int xtoken ()
2363 bool doread = false;
2366 // Whether we have seen comments on the current line
2367 bool comments_seen = false;
2369 for (;(c = get_char ()) != -1;) {
2371 col = ((col + 8) / 8) * 8;
2375 if (c == ' ' || c == '\f' || c == '\v' || c == 0xa0 || c == 0)
2379 if (peek_char () == '\n')
2382 any_token_seen |= tokens_seen;
2383 tokens_seen = false;
2384 comments_seen = false;
2388 // Handle double-slash comments.
2390 int d = peek_char ();
2394 if (RootContext.Documentation != null && peek_char () == '/') {
2396 // Don't allow ////.
2397 if ((d = peek_char ()) != '/') {
2398 update_comment_location ();
2399 if (doc_state == XmlCommentState.Allowed)
2400 handle_one_line_xml_comment ();
2401 else if (doc_state == XmlCommentState.NotAllowed)
2402 warn_incorrect_doc_comment ();
2405 while ((d = get_char ()) != -1 && (d != '\n') && d != '\r')
2408 any_token_seen |= tokens_seen;
2409 tokens_seen = false;
2410 comments_seen = false;
2412 } else if (d == '*'){
2414 bool docAppend = false;
2415 if (RootContext.Documentation != null && peek_char () == '*') {
2417 update_comment_location ();
2418 // But when it is /**/, just do nothing.
2419 if (peek_char () == '/') {
2423 if (doc_state == XmlCommentState.Allowed)
2425 else if (doc_state == XmlCommentState.NotAllowed)
2426 warn_incorrect_doc_comment ();
2429 int current_comment_start = 0;
2431 current_comment_start = xml_comment_buffer.Length;
2432 xml_comment_buffer.Append (Environment.NewLine);
2435 Location start_location = Location;
2437 while ((d = get_char ()) != -1){
2438 if (d == '*' && peek_char () == '/'){
2440 comments_seen = true;
2444 xml_comment_buffer.Append ((char) d);
2447 any_token_seen |= tokens_seen;
2448 tokens_seen = false;
2450 // Reset 'comments_seen' just to be consistent.
2451 // It doesn't matter either way, here.
2453 comments_seen = false;
2457 Report.Error (1035, start_location, "End-of-file found, '*/' expected");
2460 update_formatted_doc_comment (current_comment_start);
2463 goto is_punct_label;
2467 if (c == '\\' || is_identifier_start_character ((char)c)){
2469 return consume_identifier (c);
2473 current_location = new Location (ref_line, Col);
2474 if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
2484 any_token_seen |= tokens_seen;
2485 tokens_seen = false;
2486 comments_seen = false;
2490 if (c >= '0' && c <= '9'){
2492 return is_number (c);
2497 int peek = peek_char ();
2498 if (peek >= '0' && peek <= '9')
2499 return is_number (c);
2504 if (tokens_seen || comments_seen) {
2505 Eror_WrongPreprocessorLocation ();
2509 if (handle_preprocessing_directive (true))
2512 bool directive_expected = false;
2513 while ((c = get_char ()) != -1) {
2515 directive_expected = true;
2516 } else if (!directive_expected) {
2517 // TODO: Implement comment support for disabled code and uncomment this code
2519 // Eror_WrongPreprocessorLocation ();
2520 // return Token.ERROR;
2525 if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f' || c == '\v' )
2529 if (handle_preprocessing_directive (false))
2532 directive_expected = false;
2536 tokens_seen = false;
2544 return consume_string (false);
2550 error_details = "Empty character literal";
2551 Report.Error (1011, Location, error_details);
2554 if (c == '\r' || c == '\n') {
2555 Report.Error (1010, Location, "Newline in constant");
2561 val = new System.Char ();
2566 error_details = "Too many characters in character literal";
2567 Report.Error (1012, Location, error_details);
2569 // Try to recover, read until newline or next "'"
2570 while ((c = get_char ()) != -1){
2579 return Token.LITERAL_CHARACTER;
2586 return consume_string (true);
2587 } else if (is_identifier_start_character ((char) c)){
2588 return consume_identifier (c, true);
2590 Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
2594 error_details = ((char)c).ToString ();
2603 // Handles one line xml comment
2605 private void handle_one_line_xml_comment ()
2608 while ((c = peek_char ()) == ' ')
2609 get_char (); // skip heading whitespaces.
2610 while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
2611 xml_comment_buffer.Append ((char) get_char ());
2613 if (c == '\r' || c == '\n')
2614 xml_comment_buffer.Append (Environment.NewLine);
2618 // Remove heading "*" in Javadoc-like xml documentation.
2620 private void update_formatted_doc_comment (int current_comment_start)
2622 int length = xml_comment_buffer.Length - current_comment_start;
2623 string [] lines = xml_comment_buffer.ToString (
2624 current_comment_start,
2625 length).Replace ("\r", "").Split ('\n');
2627 // The first line starts with /**, thus it is not target
2628 // for the format check.
2629 for (int i = 1; i < lines.Length; i++) {
2630 string s = lines [i];
2631 int idx = s.IndexOf ('*');
2634 if (i < lines.Length - 1)
2638 head = s.Substring (0, idx);
2639 foreach (char c in head)
2642 lines [i] = s.Substring (idx + 1);
2644 xml_comment_buffer.Remove (current_comment_start, length);
2645 xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
2649 // Updates current comment location.
2651 private void update_comment_location ()
2653 if (current_comment_location.IsNull) {
2654 // "-2" is for heading "//" or "/*"
2655 current_comment_location =
2656 new Location (ref_line, col - 2);
2661 // Checks if there was incorrect doc comments and raise
2664 public void check_incorrect_doc_comment ()
2666 if (xml_comment_buffer.Length > 0)
2667 warn_incorrect_doc_comment ();
2671 // Raises a warning when tokenizer found incorrect doccomment
2674 private void warn_incorrect_doc_comment ()
2676 if (doc_state != XmlCommentState.Error) {
2677 doc_state = XmlCommentState.Error;
2678 // in csc, it is 'XML comment is not placed on
2679 // a valid language element'. But that does not
2681 Report.Warning (1587, 2, Location, "XML comment is not placed on a valid language element");
2686 // Consumes the saved xml comment lines (if any)
2687 // as for current target member or type.
2689 public string consume_doc_comment ()
2691 if (xml_comment_buffer.Length > 0) {
2692 string ret = xml_comment_buffer.ToString ();
2693 reset_doc_comment ();
2699 void reset_doc_comment ()
2701 xml_comment_buffer.Length = 0;
2702 current_comment_location = Location.Null;
2705 public void cleanup ()
2707 if (ifstack != null && ifstack.Count >= 1) {
2708 current_location = new Location (ref_line, Col);
2709 int state = (int) ifstack.Pop ();
2710 if ((state & REGION) != 0)
2711 Report.Error (1038, Location, "#endregion directive expected");
2713 Report.Error (1027, Location, "Expected `#endif' directive");
2719 // Indicates whether it accepts XML documentation or not.
2721 public enum XmlCommentState {
2722 // comment is allowed in this state.
2724 // comment is not allowed in this state.
2726 // once comments appeared when it is NotAllowed, then the
2727 // state is changed to it, until the state is changed to