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@gmail.com)
8
// Dual licensed under the terms of the MIT X11 or GNU GPL
10
// Copyright 2001, 2002 Ximian, Inc (http://www.ximian.com)
11
// Copyright 2004-2008 Novell, Inc
12
// Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
16
using System.Collections.Generic;
17
using System.Globalization;
18
using System.Diagnostics;
23
/// Tokenizer for C# source code.
25
public class Tokenizer : yyParser.yyInput
29
public readonly T Token;
30
public KeywordEntry<T> Next;
31
public readonly char[] Value;
33
public KeywordEntry (string value,T token)
35
this.Value = value.ToCharArray ();
40
sealed class IdentifiersComparer : IEqualityComparer<char[]>
44
public IdentifiersComparer (int length)
49
public bool Equals (char[] x, char[] y)
51
for (int i = 0; i < length; ++i)
58
public int GetHashCode (char[] obj)
61
for (int i = 0; i < length; ++i)
62
h = (h << 5) - h + obj [i];
69
// This class has to be used in the parser only, it reuses token
70
// details after each parse
72
public class LocatedToken
77
static LocatedToken[] buffer = new LocatedToken[0];
80
private LocatedToken ()
84
public static LocatedToken Create (int row, int column)
86
return Create (null, row, column);
89
public static LocatedToken Create (string value, Location loc)
91
return Create (value, loc.Row, loc.Column);
94
public static LocatedToken Create (string value, int row, int column)
97
// TODO: I am not very happy about the logic but it's the best
98
// what I could come up with for now.
99
// Ideally we should be using just tiny buffer (256 elements) which
100
// is enough to hold all details for currect stack and recycle elements
101
// poped from the stack but there is a trick needed to recycle
105
if (pos >= buffer.Length) {
106
entry = new LocatedToken ();
108
entry = buffer [pos];
110
entry = new LocatedToken ();
111
buffer [pos] = entry;
118
entry.column = column;
123
// Used for token not required by expression evaluator
125
[Conditional ("FULL_AST")]
126
public static void CreateOptional (int row, int col, ref object token)
128
token = Create (row, col);
131
public static void Initialize ()
134
if (buffer.Length == 0)
135
buffer = new LocatedToken [15000];
140
public override string ToString ()
142
return string.Format ("Token '{0}' at {1},{2}", Value, row, column);
145
public Location Location {
146
get { return new Location (row, column); }
149
public string Value {
150
get { return value; }
154
public enum PreprocessorDirective
160
If = 3 | RequiresArgument,
162
Elif = 5 | RequiresArgument,
164
Define = 7 | RequiresArgument,
165
Undef = 8 | RequiresArgument,
168
Pragma = 11 | CustomArgumentsParsing,
169
Line = 12 | CustomArgumentsParsing,
171
CustomArgumentsParsing = 1 << 10,
172
RequiresArgument = 1 << 11
175
readonly SeekableStreamReader reader;
176
readonly CompilationSourceFile source_file;
177
readonly CompilerContext context;
179
SourceFile current_source;
180
Location hidden_block_start;
186
readonly int tab_size;
187
bool handle_get_set = false;
188
bool handle_remove_add = false;
189
bool handle_where = false;
190
bool handle_typeof = false;
191
bool lambda_arguments_parsing;
192
List<Location> escaped_identifiers;
193
int parsing_generic_less_than;
194
readonly bool doc_processing;
197
// Used mainly for parser optimizations. Some expressions for instance
198
// can appear only in block (including initializer, base initializer)
201
public int parsing_block;
202
internal bool query_parsing;
205
// When parsing type only, useful for ambiguous nullable types
207
public int parsing_type;
210
// Set when parsing generic declaration (type or method header)
212
public bool parsing_generic_declaration;
213
public bool parsing_generic_declaration_doc;
216
// The value indicates that we have not reach any declaration or
219
public int parsing_declaration;
220
public bool parsing_attribute_section;
222
public bool parsing_modifiers;
225
// The special characters to inject on streams to run the unit parser
226
// in the special expression mode. Using private characters from
227
// Plane Sixteen (U+100000 to U+10FFFD)
229
// This character is only tested just before the tokenizer is about to report
230
// an error; So on the regular operation mode, this addition will have no
231
// impact on the tokenizer's performance.
234
public const int EvalStatementParserCharacter = 0x100000;
235
public const int EvalCompilationUnitParserCharacter = 0x100001;
236
public const int EvalUsingDeclarationsParserCharacter = 0x100002;
237
public const int DocumentationXref = 0x100003;
240
// XML documentation buffer. The save point is used to divide
241
// comments on types and comments on members.
243
StringBuilder xml_comment_buffer;
246
// See comment on XmlCommentState enumeration.
248
XmlCommentState xml_doc_state = XmlCommentState.Allowed;
251
// Whether tokens have been seen on this line
253
bool tokens_seen = false;
256
// Set to true once the GENERATE_COMPLETION token has bee
257
// returned. This helps produce one GENERATE_COMPLETION,
258
// as many COMPLETE_COMPLETION as necessary to complete the
259
// AST tree and one final EOF.
264
// Whether a token has been seen on the file
265
// This is needed because `define' is not allowed to be used
266
// after a token has been seen.
273
static readonly KeywordEntry<int>[][] keywords;
274
static readonly KeywordEntry<PreprocessorDirective>[][] keywords_preprocessor;
275
static readonly HashSet<string> keyword_strings;
276
static readonly NumberStyles styles;
277
static readonly NumberFormatInfo csharp_format_info;
280
static readonly char[] pragma_warning = "warning".ToCharArray ();
281
static readonly char[] pragma_warning_disable = "disable".ToCharArray ();
282
static readonly char[] pragma_warning_restore = "restore".ToCharArray ();
283
static readonly char[] pragma_checksum = "checksum".ToCharArray ();
284
static readonly char[] line_hidden = "hidden".ToCharArray ();
285
static readonly char[] line_default = "default".ToCharArray ();
287
static readonly char[] simple_whitespaces = new char[] { ' ', '\t' };
288
bool startsLine = true;
289
internal SpecialsBag sbag;
291
public bool PropertyParsing {
292
get { return handle_get_set; }
293
set { handle_get_set = value; }
296
public bool EventParsing {
297
get { return handle_remove_add; }
298
set { handle_remove_add = value; }
301
public bool ConstraintsParsing {
302
get { return handle_where; }
303
set { handle_where = value; }
306
public bool TypeOfParsing {
307
get { return handle_typeof; }
308
set { handle_typeof = value; }
311
public XmlCommentState doc_state {
312
get { return xml_doc_state; }
314
if (value == XmlCommentState.Allowed) {
315
check_incorrect_doc_comment ();
316
reset_doc_comment ();
318
xml_doc_state = value;
323
// This is used to trigger completion generation on the parser
324
public bool CompleteOnEOF;
326
void AddEscapedIdentifier (Location loc)
328
if (escaped_identifiers == null)
329
escaped_identifiers = new List<Location> ();
331
escaped_identifiers.Add (loc);
334
public bool IsEscapedIdentifier (ATypeNameExpression name)
336
return escaped_identifiers != null && escaped_identifiers.Contains (name.Location);
340
// Values for the associated token returned
342
internal int putback_char; // Used by repl only
348
const int TAKING = 1;
349
const int ELSE_SEEN = 4;
350
const int PARENT_TAKING = 8;
351
const int REGION = 16;
354
// pre-processor if stack state:
358
const int max_id_size = 512;
359
const int max_number_size = 512;
362
readonly char [] id_builder = new char [max_id_size];
364
Dictionary<char[], string>[] identifiers = new Dictionary<char[], string>[max_id_size + 1];
366
char [] number_builder = new char [max_number_size];
369
char[] value_builder = new char[256];
371
static readonly char [] id_builder = new char [max_id_size];
373
static Dictionary<char[], string>[] identifiers = new Dictionary<char[], string>[max_id_size + 1];
375
static char [] number_builder = new char [max_number_size];
376
static int number_pos;
377
static char[] value_builder = new char[256];
390
// This is used when the tokenizer needs to save
391
// the current position as it needs to do some parsing
392
// on its own to deamiguate a token in behalf of the
395
Stack<Position> position_stack = new Stack<Position> (2);
403
public Location hidden;
404
public int putback_char;
405
public int previous_col;
406
public Stack<int> ifstack;
407
public int parsing_generic_less_than;
408
public int current_token;
411
public Position (Tokenizer t)
413
position = t.reader.Position;
415
ref_line = t.ref_line;
417
hidden = t.hidden_block_start;
418
putback_char = t.putback_char;
419
previous_col = t.previous_col;
420
if (t.ifstack != null && t.ifstack.Count != 0) {
421
// There is no simple way to clone Stack<T> all
422
// methods reverse the order
423
var clone = t.ifstack.ToArray ();
424
Array.Reverse (clone);
425
ifstack = new Stack<int> (clone);
427
parsing_generic_less_than = t.parsing_generic_less_than;
428
current_token = t.current_token;
433
public Tokenizer (SeekableStreamReader input, CompilationSourceFile file)
435
this.source_file = file;
436
this.context = file.Compiler;
437
this.current_source = file.SourceFile;
443
xml_comment_buffer = new StringBuilder ();
444
doc_processing = context.Settings.DocumentationFile != null;
446
tab_size = context.Settings.TabSize;
448
Mono.CSharp.Location.Push (current_source);
451
public void PushPosition ()
453
position_stack.Push (new Position (this));
456
public void PopPosition ()
458
Position p = position_stack.Pop ();
460
reader.Position = p.position;
461
ref_line = p.ref_line;
464
hidden_block_start = p.hidden;
465
putback_char = p.putback_char;
466
previous_col = p.previous_col;
468
parsing_generic_less_than = p.parsing_generic_less_than;
469
current_token = p.current_token;
473
// Do not reset the position, ignore it.
474
public void DiscardPosition ()
476
position_stack.Pop ();
479
static void AddKeyword (string kw, int token)
481
keyword_strings.Add (kw);
483
AddKeyword (keywords, kw, token);
486
static void AddPreprocessorKeyword (string kw, PreprocessorDirective directive)
488
AddKeyword (keywords_preprocessor, kw, directive);
491
static void AddKeyword<T> (KeywordEntry<T>[][] keywords, string kw, T token)
493
int length = kw.Length;
494
if (keywords[length] == null) {
495
keywords[length] = new KeywordEntry<T>['z' - '_' + 1];
498
int char_index = kw[0] - '_';
499
var kwe = keywords[length][char_index];
501
keywords[length][char_index] = new KeywordEntry<T> (kw, token);
505
while (kwe.Next != null) {
509
kwe.Next = new KeywordEntry<T> (kw, token);
517
keyword_strings = new HashSet<string> ();
519
// 11 is the length of the longest keyword for now
520
keywords = new KeywordEntry<int>[11][];
522
AddKeyword ("__arglist", Token.ARGLIST);
523
AddKeyword ("__makeref", Token.MAKEREF);
524
AddKeyword ("__reftype", Token.REFTYPE);
525
AddKeyword ("__refvalue", Token.REFVALUE);
526
AddKeyword ("abstract", Token.ABSTRACT);
527
AddKeyword ("as", Token.AS);
528
AddKeyword ("add", Token.ADD);
529
AddKeyword ("base", Token.BASE);
530
AddKeyword ("bool", Token.BOOL);
531
AddKeyword ("break", Token.BREAK);
532
AddKeyword ("byte", Token.BYTE);
533
AddKeyword ("case", Token.CASE);
534
AddKeyword ("catch", Token.CATCH);
535
AddKeyword ("char", Token.CHAR);
536
AddKeyword ("checked", Token.CHECKED);
537
AddKeyword ("class", Token.CLASS);
538
AddKeyword ("const", Token.CONST);
539
AddKeyword ("continue", Token.CONTINUE);
540
AddKeyword ("decimal", Token.DECIMAL);
541
AddKeyword ("default", Token.DEFAULT);
542
AddKeyword ("delegate", Token.DELEGATE);
543
AddKeyword ("do", Token.DO);
544
AddKeyword ("double", Token.DOUBLE);
545
AddKeyword ("else", Token.ELSE);
546
AddKeyword ("enum", Token.ENUM);
547
AddKeyword ("event", Token.EVENT);
548
AddKeyword ("explicit", Token.EXPLICIT);
549
AddKeyword ("extern", Token.EXTERN);
550
AddKeyword ("false", Token.FALSE);
551
AddKeyword ("finally", Token.FINALLY);
552
AddKeyword ("fixed", Token.FIXED);
553
AddKeyword ("float", Token.FLOAT);
554
AddKeyword ("for", Token.FOR);
555
AddKeyword ("foreach", Token.FOREACH);
556
AddKeyword ("goto", Token.GOTO);
557
AddKeyword ("get", Token.GET);
558
AddKeyword ("if", Token.IF);
559
AddKeyword ("implicit", Token.IMPLICIT);
560
AddKeyword ("in", Token.IN);
561
AddKeyword ("int", Token.INT);
562
AddKeyword ("interface", Token.INTERFACE);
563
AddKeyword ("internal", Token.INTERNAL);
564
AddKeyword ("is", Token.IS);
565
AddKeyword ("lock", Token.LOCK);
566
AddKeyword ("long", Token.LONG);
567
AddKeyword ("namespace", Token.NAMESPACE);
568
AddKeyword ("new", Token.NEW);
569
AddKeyword ("null", Token.NULL);
570
AddKeyword ("object", Token.OBJECT);
571
AddKeyword ("operator", Token.OPERATOR);
572
AddKeyword ("out", Token.OUT);
573
AddKeyword ("override", Token.OVERRIDE);
574
AddKeyword ("params", Token.PARAMS);
575
AddKeyword ("private", Token.PRIVATE);
576
AddKeyword ("protected", Token.PROTECTED);
577
AddKeyword ("public", Token.PUBLIC);
578
AddKeyword ("readonly", Token.READONLY);
579
AddKeyword ("ref", Token.REF);
580
AddKeyword ("remove", Token.REMOVE);
581
AddKeyword ("return", Token.RETURN);
582
AddKeyword ("sbyte", Token.SBYTE);
583
AddKeyword ("sealed", Token.SEALED);
584
AddKeyword ("set", Token.SET);
585
AddKeyword ("short", Token.SHORT);
586
AddKeyword ("sizeof", Token.SIZEOF);
587
AddKeyword ("stackalloc", Token.STACKALLOC);
588
AddKeyword ("static", Token.STATIC);
589
AddKeyword ("string", Token.STRING);
590
AddKeyword ("struct", Token.STRUCT);
591
AddKeyword ("switch", Token.SWITCH);
592
AddKeyword ("this", Token.THIS);
593
AddKeyword ("throw", Token.THROW);
594
AddKeyword ("true", Token.TRUE);
595
AddKeyword ("try", Token.TRY);
596
AddKeyword ("typeof", Token.TYPEOF);
597
AddKeyword ("uint", Token.UINT);
598
AddKeyword ("ulong", Token.ULONG);
599
AddKeyword ("unchecked", Token.UNCHECKED);
600
AddKeyword ("unsafe", Token.UNSAFE);
601
AddKeyword ("ushort", Token.USHORT);
602
AddKeyword ("using", Token.USING);
603
AddKeyword ("virtual", Token.VIRTUAL);
604
AddKeyword ("void", Token.VOID);
605
AddKeyword ("volatile", Token.VOLATILE);
606
AddKeyword ("while", Token.WHILE);
607
AddKeyword ("partial", Token.PARTIAL);
608
AddKeyword ("where", Token.WHERE);
611
AddKeyword ("from", Token.FROM);
612
AddKeyword ("join", Token.JOIN);
613
AddKeyword ("on", Token.ON);
614
AddKeyword ("equals", Token.EQUALS);
615
AddKeyword ("select", Token.SELECT);
616
AddKeyword ("group", Token.GROUP);
617
AddKeyword ("by", Token.BY);
618
AddKeyword ("let", Token.LET);
619
AddKeyword ("orderby", Token.ORDERBY);
620
AddKeyword ("ascending", Token.ASCENDING);
621
AddKeyword ("descending", Token.DESCENDING);
622
AddKeyword ("into", Token.INTO);
624
// Contextual async keywords
625
AddKeyword ("async", Token.ASYNC);
626
AddKeyword ("await", Token.AWAIT);
628
keywords_preprocessor = new KeywordEntry<PreprocessorDirective>[10][];
630
AddPreprocessorKeyword ("region", PreprocessorDirective.Region);
631
AddPreprocessorKeyword ("endregion", PreprocessorDirective.Endregion);
632
AddPreprocessorKeyword ("if", PreprocessorDirective.If);
633
AddPreprocessorKeyword ("endif", PreprocessorDirective.Endif);
634
AddPreprocessorKeyword ("elif", PreprocessorDirective.Elif);
635
AddPreprocessorKeyword ("else", PreprocessorDirective.Else);
636
AddPreprocessorKeyword ("define", PreprocessorDirective.Define);
637
AddPreprocessorKeyword ("undef", PreprocessorDirective.Undef);
638
AddPreprocessorKeyword ("error", PreprocessorDirective.Error);
639
AddPreprocessorKeyword ("warning", PreprocessorDirective.Warning);
640
AddPreprocessorKeyword ("pragma", PreprocessorDirective.Pragma);
641
AddPreprocessorKeyword ("line", PreprocessorDirective.Line);
643
csharp_format_info = NumberFormatInfo.InvariantInfo;
644
styles = NumberStyles.Float;
647
int GetKeyword (char[] id, int id_len)
650
// Keywords are stored in an array of arrays grouped by their
651
// length and then by the first character
653
if (id_len >= keywords.Length || keywords [id_len] == null)
656
int first_index = id [0] - '_';
657
if (first_index > 'z' - '_')
660
var kwe = keywords [id_len] [first_index];
667
for (int i = 1; i < id_len; ++i) {
668
if (id [i] != kwe.Value [i]) {
674
} while (res == 0 && kwe != null);
688
if (!handle_remove_add)
692
if (parsing_declaration == 0)
693
res = Token.EXTERN_ALIAS;
696
if (peek_token () == Token.COLON) {
698
res = Token.DEFAULT_COLON;
702
if (!handle_where && !query_parsing)
707
// A query expression is any expression that starts with `from identifier'
708
// followed by any token except ; , =
710
if (!query_parsing) {
711
if (lambda_arguments_parsing) {
717
// HACK: to disable generics micro-parser, because PushPosition does not
718
// store identifiers array
719
parsing_generic_less_than = 1;
721
case Token.IDENTIFIER:
733
next_token = xtoken ();
734
if (next_token == Token.SEMICOLON || next_token == Token.COMMA || next_token == Token.EQUALS)
737
res = Token.FROM_FIRST;
738
query_parsing = true;
739
if (context.Settings.Version <= LanguageVersion.ISO_2)
740
Report.FeatureIsNotAvailable (context, Location, "query expressions");
743
Expression.Error_VoidInvalidInTheContext (Location, Report);
747
// HACK: A token is not a keyword so we need to restore identifiers buffer
748
// which has been overwritten before we grabbed the identifier
749
id_builder [0] = 'f'; id_builder [1] = 'r'; id_builder [2] = 'o'; id_builder [3] = 'm';
763
case Token.ASCENDING:
764
case Token.DESCENDING:
771
case Token.NAMESPACE:
772
// TODO: some explanation needed
773
check_incorrect_doc_comment ();
777
if (parsing_block > 0) {
782
// Save current position and parse next token.
785
next_token = token ();
786
bool ok = (next_token == Token.CLASS) ||
787
(next_token == Token.STRUCT) ||
788
(next_token == Token.INTERFACE) ||
789
(next_token == Token.VOID);
794
if (next_token == Token.VOID) {
795
if (context.Settings.Version <= LanguageVersion.ISO_2)
796
Report.FeatureIsNotAvailable (context, Location, "partial methods");
797
} else if (context.Settings.Version == LanguageVersion.ISO_1)
798
Report.FeatureIsNotAvailable (context, Location, "partial types");
803
if (next_token < Token.LAST_KEYWORD) {
804
Report.Error (267, Location,
805
"The `partial' modifier can be used only immediately before `class', `struct', `interface', or `void' keyword");
813
if (parsing_modifiers) {
815
// Skip attributes section or constructor called async
817
if (parsing_attribute_section || peek_token () == Token.OPEN_PARENS) {
822
} else if (parsing_block > 0) {
823
switch (peek_token ()) {
825
case Token.OPEN_PARENS_LAMBDA:
828
case Token.IDENTIFIER:
831
if (xtoken () != Token.ARROW)
844
if (res == Token.ASYNC && context.Settings.Version <= LanguageVersion.V_4) {
845
Report.FeatureIsNotAvailable (context, Location, "asynchronous functions");
851
if (parsing_block == 0)
860
static PreprocessorDirective GetPreprocessorDirective (char[] id, int id_len)
863
// Keywords are stored in an array of arrays grouped by their
864
// length and then by the first character
866
if (id_len >= keywords_preprocessor.Length || keywords_preprocessor[id_len] == null)
867
return PreprocessorDirective.Invalid;
869
int first_index = id[0] - '_';
870
if (first_index > 'z' - '_')
871
return PreprocessorDirective.Invalid;
873
var kwe = keywords_preprocessor[id_len][first_index];
875
return PreprocessorDirective.Invalid;
877
PreprocessorDirective res = PreprocessorDirective.Invalid;
880
for (int i = 1; i < id_len; ++i) {
881
if (id[i] != kwe.Value[i]) {
887
} while (res == PreprocessorDirective.Invalid && kwe != null);
892
public Location Location {
894
return new Location (ref_line, col);
898
static bool is_identifier_start_character (int c)
900
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || Char.IsLetter ((char)c);
903
static bool is_identifier_part_character (char c)
905
if (c >= 'a' && c <= 'z')
908
if (c >= 'A' && c <= 'Z')
911
if (c == '_' || (c >= '0' && c <= '9'))
917
return Char.IsLetter (c) || Char.GetUnicodeCategory (c) == UnicodeCategory.ConnectorPunctuation;
920
public static bool IsKeyword (string s)
922
return keyword_strings.Contains (s);
926
// Open parens micro parser. Detects both lambda and cast ambiguity.
928
int TokenizeOpenParens ()
933
int bracket_level = 0;
934
bool is_type = false;
935
bool can_be_type = false;
938
ptoken = current_token;
941
switch (current_token) {
942
case Token.CLOSE_PARENS:
946
// Expression inside parens is lambda, (int i) =>
948
if (current_token == Token.ARROW)
949
return Token.OPEN_PARENS_LAMBDA;
952
// Expression inside parens is single type, (int[])
955
return Token.OPEN_PARENS_CAST;
958
// Expression is possible cast, look at next token, (T)null
961
switch (current_token) {
962
case Token.OPEN_PARENS:
965
case Token.IDENTIFIER:
979
case Token.UNCHECKED:
985
// These can be part of a member access
999
return Token.OPEN_PARENS_CAST;
1002
return Token.OPEN_PARENS;
1005
case Token.DOUBLE_COLON:
1006
if (ptoken != Token.IDENTIFIER && ptoken != Token.OP_GENERICS_GT)
1011
case Token.IDENTIFIER:
1014
if (bracket_level == 0) {
1020
case Token.OP_GENERICS_LT:
1022
case Token.DOUBLE_COLON:
1024
if (bracket_level == 0)
1028
can_be_type = is_type = false;
1048
if (bracket_level == 0)
1053
if (bracket_level == 0) {
1054
bracket_level = 100;
1055
can_be_type = is_type = false;
1059
case Token.OP_GENERICS_LT:
1060
case Token.OPEN_BRACKET:
1061
if (bracket_level++ == 0)
1065
case Token.OP_GENERICS_GT:
1066
case Token.CLOSE_BRACKET:
1070
case Token.INTERR_NULLABLE:
1072
if (bracket_level == 0)
1078
can_be_type = is_type = false;
1082
return Token.OPEN_PARENS;
1087
public static bool IsValidIdentifier (string s)
1089
if (s == null || s.Length == 0)
1092
if (!is_identifier_start_character (s [0]))
1095
for (int i = 1; i < s.Length; i ++)
1096
if (! is_identifier_part_character (s [i]))
1102
bool parse_less_than ()
1105
int the_token = token ();
1106
if (the_token == Token.OPEN_BRACKET) {
1108
the_token = token ();
1109
} while (the_token != Token.CLOSE_BRACKET);
1110
the_token = token ();
1111
} else if (the_token == Token.IN || the_token == Token.OUT) {
1112
the_token = token ();
1114
switch (the_token) {
1115
case Token.IDENTIFIER:
1133
case Token.OP_GENERICS_GT:
1142
the_token = token ();
1144
if (the_token == Token.OP_GENERICS_GT)
1146
else if (the_token == Token.COMMA || the_token == Token.DOT || the_token == Token.DOUBLE_COLON)
1148
else if (the_token == Token.INTERR_NULLABLE || the_token == Token.STAR)
1150
else if (the_token == Token.OP_GENERICS_LT) {
1151
if (!parse_less_than ())
1154
} else if (the_token == Token.OPEN_BRACKET) {
1156
the_token = token ();
1157
if (the_token == Token.CLOSE_BRACKET)
1159
else if (the_token == Token.COMMA)
1160
goto rank_specifiers;
1167
bool parse_generic_dimension (out int dimension)
1172
int the_token = token ();
1173
if (the_token == Token.OP_GENERICS_GT)
1175
else if (the_token == Token.COMMA) {
1183
public int peek_token ()
1188
the_token = token ();
1195
// Tonizes `?' using custom disambiguous rules to return one
1196
// of following tokens: INTERR_NULLABLE, OP_COALESCING, INTERR
1198
// Tricky expression look like:
1200
// Foo ? a = x ? b : c;
1202
int TokenizePossibleNullableType ()
1204
if (parsing_block == 0 || parsing_type > 0)
1205
return Token.INTERR_NULLABLE;
1207
int d = peek_char ();
1210
return Token.OP_COALESCING;
1213
switch (current_token) {
1214
case Token.CLOSE_PARENS:
1219
return Token.INTERR;
1223
if (d == ',' || d == ';' || d == '>')
1224
return Token.INTERR_NULLABLE;
1225
if (d == '*' || (d >= '0' && d <= '9'))
1226
return Token.INTERR;
1230
current_token = Token.NONE;
1232
switch (xtoken ()) {
1239
next_token = Token.INTERR;
1242
case Token.SEMICOLON:
1244
case Token.CLOSE_PARENS:
1245
case Token.OPEN_BRACKET:
1246
case Token.OP_GENERICS_GT:
1248
next_token = Token.INTERR_NULLABLE;
1256
if (next_token == -1) {
1257
switch (xtoken ()) {
1259
case Token.SEMICOLON:
1260
case Token.OPEN_BRACE:
1261
case Token.CLOSE_PARENS:
1263
next_token = Token.INTERR_NULLABLE;
1267
next_token = Token.INTERR;
1276
// All shorcuts failed, do it hard way
1278
while ((ntoken = xtoken ()) != Token.EOF) {
1279
if (ntoken == Token.OPEN_BRACE) {
1284
if (ntoken == Token.CLOSE_BRACE) {
1292
if (ntoken == Token.SEMICOLON)
1295
if (ntoken == Token.COLON) {
1296
if (++colons == interrs)
1301
if (ntoken == Token.INTERR) {
1307
next_token = colons != interrs && braces == 0 ? Token.INTERR_NULLABLE : Token.INTERR;
1316
bool decimal_digits (int c)
1319
bool seen_digits = false;
1322
if (number_pos == max_number_size)
1323
Error_NumericConstantTooLong ();
1324
number_builder [number_pos++] = (char) c;
1328
// We use peek_char2, because decimal_digits needs to do a
1329
// 2-character look-ahead (5.ToString for example).
1331
while ((d = peek_char2 ()) != -1){
1332
if (d >= '0' && d <= '9'){
1333
if (number_pos == max_number_size)
1334
Error_NumericConstantTooLong ();
1335
number_builder [number_pos++] = (char) d;
1345
static bool is_hex (int e)
1347
return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
1350
static TypeCode real_type_suffix (int c)
1354
return TypeCode.Single;
1356
return TypeCode.Double;
1358
return TypeCode.Decimal;
1360
return TypeCode.Empty;
1364
ILiteralConstant integer_type_suffix (ulong ul, int c, Location loc)
1366
bool is_unsigned = false;
1367
bool is_long = false;
1370
bool scanning = true;
1383
// if we have not seen anything in between
1384
// report this error
1386
Report.Warning (78, 4, Location, "The 'l' suffix is easily confused with the digit '1' (use 'L' for clarity)");
1406
if (is_long && is_unsigned){
1407
return new ULongLiteral (context.BuiltinTypes, ul, loc);
1411
// uint if possible, or ulong else.
1413
if ((ul & 0xffffffff00000000) == 0)
1414
return new UIntLiteral (context.BuiltinTypes, (uint) ul, loc);
1416
return new ULongLiteral (context.BuiltinTypes, ul, loc);
1417
} else if (is_long){
1418
// long if possible, ulong otherwise
1419
if ((ul & 0x8000000000000000) != 0)
1420
return new ULongLiteral (context.BuiltinTypes, ul, loc);
1422
return new LongLiteral (context.BuiltinTypes, (long) ul, loc);
1424
// int, uint, long or ulong in that order
1425
if ((ul & 0xffffffff00000000) == 0){
1426
uint ui = (uint) ul;
1428
if ((ui & 0x80000000) != 0)
1429
return new UIntLiteral (context.BuiltinTypes, ui, loc);
1431
return new IntLiteral (context.BuiltinTypes, (int) ui, loc);
1433
if ((ul & 0x8000000000000000) != 0)
1434
return new ULongLiteral (context.BuiltinTypes, ul, loc);
1436
return new LongLiteral (context.BuiltinTypes, (long) ul, loc);
1442
// given `c' as the next char in the input decide whether
1443
// we need to convert to a special type, and then choose
1444
// the best representation for the integer
1446
ILiteralConstant adjust_int (int c, Location loc)
1449
if (number_pos > 9){
1450
ulong ul = (uint) (number_builder [0] - '0');
1452
for (int i = 1; i < number_pos; i++){
1453
ul = checked ((ul * 10) + ((uint)(number_builder [i] - '0')));
1456
return integer_type_suffix (ul, c, loc);
1458
uint ui = (uint) (number_builder [0] - '0');
1460
for (int i = 1; i < number_pos; i++){
1461
ui = checked ((ui * 10) + ((uint)(number_builder [i] - '0')));
1464
return integer_type_suffix (ui, c, loc);
1466
} catch (OverflowException) {
1467
Error_NumericConstantTooLong ();
1468
return new IntLiteral (context.BuiltinTypes, 0, loc);
1470
catch (FormatException) {
1471
Report.Error (1013, Location, "Invalid number");
1472
return new IntLiteral (context.BuiltinTypes, 0, loc);
1476
ILiteralConstant adjust_real (TypeCode t, Location loc)
1478
string s = new string (number_builder, 0, number_pos);
1479
const string error_details = "Floating-point constant is outside the range of type `{0}'";
1482
case TypeCode.Decimal:
1484
return new DecimalLiteral (context.BuiltinTypes, decimal.Parse (s, styles, csharp_format_info), loc);
1485
} catch (OverflowException) {
1486
Report.Error (594, Location, error_details, "decimal");
1487
return new DecimalLiteral (context.BuiltinTypes, 0, loc);
1489
case TypeCode.Single:
1491
return new FloatLiteral (context.BuiltinTypes, float.Parse (s, styles, csharp_format_info), loc);
1492
} catch (OverflowException) {
1493
Report.Error (594, Location, error_details, "float");
1494
return new FloatLiteral (context.BuiltinTypes, 0, loc);
1498
return new DoubleLiteral (context.BuiltinTypes, double.Parse (s, styles, csharp_format_info), loc);
1499
} catch (OverflowException) {
1500
Report.Error (594, loc, error_details, "double");
1501
return new DoubleLiteral (context.BuiltinTypes, 0, loc);
1506
ILiteralConstant handle_hex (Location loc)
1512
while ((d = peek_char ()) != -1){
1514
number_builder [number_pos++] = (char) d;
1520
string s = new String (number_builder, 0, number_pos);
1523
if (number_pos <= 8)
1524
ul = System.UInt32.Parse (s, NumberStyles.HexNumber);
1526
ul = System.UInt64.Parse (s, NumberStyles.HexNumber);
1528
return integer_type_suffix (ul, peek_char (), loc);
1529
} catch (OverflowException){
1530
Error_NumericConstantTooLong ();
1531
return new IntLiteral (context.BuiltinTypes, 0, loc);
1533
catch (FormatException) {
1534
Report.Error (1013, Location, "Invalid number");
1535
return new IntLiteral (context.BuiltinTypes, 0, loc);
1540
// Invoked if we know we have .digits or digits
1542
int is_number (int c)
1544
ILiteralConstant res;
1547
int read_start = reader.Position - 1;
1550
// Caller did peek_char
1557
bool hasLeadingDot = c == '.';
1559
if (c >= '0' && c <= '9'){
1561
int peek = peek_char ();
1563
if (peek == 'x' || peek == 'X') {
1564
val = res = handle_hex (loc);
1566
res.ParsedValue = reader.ReadChars (read_start, reader.Position - 1);
1569
return Token.LITERAL;
1577
// We need to handle the case of
1578
// "1.1" vs "1.string" (LITERAL_FLOAT vs NUMBER DOT IDENTIFIER)
1580
bool is_real = false;
1582
if (decimal_digits ('.')){
1588
val = res = adjust_int (-1, loc);
1590
res.ParsedValue = reader.ReadChars (read_start, reader.Position - 1);
1592
return Token.LITERAL;
1596
if (c == 'e' || c == 'E'){
1598
if (number_pos == max_number_size)
1599
Error_NumericConstantTooLong ();
1600
number_builder [number_pos++] = (char) c;
1604
if (number_pos == max_number_size)
1605
Error_NumericConstantTooLong ();
1606
number_builder [number_pos++] = '+';
1608
} else if (c == '-') {
1609
if (number_pos == max_number_size)
1610
Error_NumericConstantTooLong ();
1611
number_builder [number_pos++] = '-';
1614
if (number_pos == max_number_size)
1615
Error_NumericConstantTooLong ();
1616
number_builder [number_pos++] = '+';
1623
var type = real_type_suffix (c);
1624
if (type == TypeCode.Empty && !is_real) {
1626
res = adjust_int (c, loc);
1630
if (type == TypeCode.Empty) {
1634
res = adjust_real (type, loc);
1639
var chars = reader.ReadChars (read_start, reader.Position - (type == TypeCode.Empty && c > 0 ? 1 : 0));
1640
if (chars[chars.Length - 1] == '\r')
1641
Array.Resize (ref chars, chars.Length - 1);
1642
res.ParsedValue = chars;
1645
return Token.LITERAL;
1649
// Accepts exactly count (4 or 8) hex, no more no less
1651
int getHex (int count, out int surrogate, out bool error)
1656
int top = count != -1 ? count : 4;
1661
for (i = 0; i < top; i++){
1664
if (c >= '0' && c <= '9')
1665
c = (int) c - (int) '0';
1666
else if (c >= 'A' && c <= 'F')
1667
c = (int) c - (int) 'A' + 10;
1668
else if (c >= 'a' && c <= 'f')
1669
c = (int) c - (int) 'a' + 10;
1675
total = (total * 16) + c;
1677
int p = peek_char ();
1680
if (!is_hex ((char)p))
1686
if (total > 0x0010FFFF) {
1691
if (total >= 0x00010000) {
1692
surrogate = ((total - 0x00010000) % 0x0400 + 0xDC00);
1693
total = ((total - 0x00010000) / 0x0400 + 0xD800);
1700
int escape (int c, out int surrogate)
1736
v = getHex (-1, out surrogate, out error);
1742
return EscapeUnicode (d, out surrogate);
1745
Report.Error (1009, Location, "Unrecognized escape sequence `\\{0}'", ((char)d).ToString ());
1754
int EscapeUnicode (int ch, out int surrogate)
1758
ch = getHex (8, out surrogate, out error);
1760
ch = getHex (4, out surrogate, out error);
1764
Report.Error (1009, Location, "Unrecognized escape sequence");
1772
if (putback_char != -1) {
1780
if (peek_char () == '\n') {
1786
} else if (x == '\n') {
1794
void advance_line ()
1805
if (putback_char == -1)
1806
putback_char = reader.Read ();
1807
return putback_char;
1812
if (putback_char != -1)
1813
return putback_char;
1814
return reader.Peek ();
1817
public void putback (int c)
1819
if (putback_char != -1) {
1820
throw new InternalErrorException (string.Format ("Secondary putback [{0}] putting back [{1}] is not allowed", (char)putback_char, (char) c), Location);
1823
if (c == '\n' || col == 0) {
1824
// It won't happen though.
1834
public bool advance ()
1836
return peek_char () != -1 || CompleteOnEOF;
1839
public Object Value {
1845
public Object value ()
1852
current_token = xtoken ();
1853
return current_token;
1856
int TokenizePreprocessorIdentifier (out int c)
1858
int endLine, endCol;
1859
return TokenizePreprocessorIdentifier (out c, out endLine, out endCol);
1862
int TokenizePreprocessorIdentifier (out int c, out int endLine, out int endCol)
1864
// skip over white space
1869
} while (c == ' ' || c == '\t');
1872
while (c != -1 && c >= 'a' && c <= 'z') {
1873
id_builder[pos++] = (char) c;
1877
int peek = peek_char ();
1878
if (peek == 'U' || peek == 'u') {
1880
c = EscapeUnicode (c, out surrogate);
1881
if (surrogate != 0) {
1882
if (is_identifier_part_character ((char) c)) {
1883
id_builder[pos++] = (char) c;
1894
PreprocessorDirective get_cmd_arg (out string arg)
1897
int startLine = line, startCol = col;
1899
tokens_seen = false;
1902
int endLine, endCol;
1903
var cmd = GetPreprocessorDirective (id_builder, TokenizePreprocessorIdentifier (out c, out endLine, out endCol));
1905
if ((cmd & PreprocessorDirective.CustomArgumentsParsing) != 0) {
1906
if (position_stack.Count == 0)
1907
sbag.AddPreProcessorDirective (startLine, startCol, line, col, cmd, null);
1911
// skip over white space
1912
while (c == ' ' || c == '\t') {
1915
int has_identifier_argument = (int)(cmd & PreprocessorDirective.RequiresArgument);
1918
while (c != -1 && c != '\n' && c != '\r') {
1919
if (c == '\\' && has_identifier_argument >= 0) {
1920
if (has_identifier_argument != 0) {
1921
has_identifier_argument = 1;
1923
int peek = peek_char ();
1924
if (peek == 'U' || peek == 'u') {
1926
c = EscapeUnicode (c, out surrogate);
1927
if (surrogate != 0) {
1928
if (is_identifier_part_character ((char)c)) {
1929
if (pos == value_builder.Length)
1930
Array.Resize (ref value_builder, pos * 2);
1932
value_builder [pos++] = (char)c;
1938
has_identifier_argument = -1;
1940
} else if (c == '/' && peek_char () == '/') {
1942
// Eat single-line comments
1947
} while (c != -1 && c != '\n');
1955
if (pos == value_builder.Length)
1956
Array.Resize (ref value_builder, pos * 2);
1958
value_builder[pos++] = (char) c;
1963
if (pos > max_id_size)
1964
arg = new string (value_builder, 0, pos);
1966
arg = InternIdentifier (value_builder, pos);
1968
// Eat any trailing whitespaces
1969
arg = arg.Trim (simple_whitespaces);
1971
if (position_stack.Count == 0)
1972
sbag.AddPreProcessorDirective (startLine, startCol, endLine, endCol, cmd, arg);
1978
// Handles the #line directive
1980
bool PreProcessLine ()
1982
Location loc = Location;
1986
int length = TokenizePreprocessorIdentifier (out c);
1987
if (length == line_default.Length) {
1988
if (!IsTokenIdentifierEqual (line_default))
1991
current_source = source_file.SourceFile;
1992
if (!hidden_block_start.IsNull) {
1993
current_source.RegisterHiddenScope (hidden_block_start, loc);
1994
hidden_block_start = Location.Null;
1998
Location.Push (current_source);
2002
if (length == line_hidden.Length) {
2003
if (!IsTokenIdentifierEqual (line_hidden))
2006
if (hidden_block_start.IsNull)
2007
hidden_block_start = loc;
2012
if (length != 0 || c < '0' || c > '9') {
2014
// Eat any remaining characters to continue parsing on next line
2016
while (c != -1 && c != '\n') {
2023
int new_line = TokenizeNumber (c);
2026
// Eat any remaining characters to continue parsing on next line
2028
while (c != -1 && c != '\n') {
2032
return new_line != 0;
2037
// skip over white space
2040
} while (c == ' ' || c == '\t');
2041
} else if (c == '"') {
2045
if (c != '\n' && c != '/' && c != '"') {
2047
// Eat any remaining characters to continue parsing on next line
2049
while (c != -1 && c != '\n') {
2053
Report.Error (1578, loc, "Filename, single-line comment or end-of-line expected");
2057
string new_file_name = null;
2059
new_file_name = TokenizeFileName (ref c);
2061
// skip over white space
2062
while (c == ' ' || c == '\t') {
2068
} else if (c == '/') {
2069
ReadSingleLineComment ();
2072
// Eat any remaining characters to continue parsing on next line
2074
while (c != -1 && c != '\n') {
2078
Error_EndLineExpected ();
2082
if (new_file_name != null) {
2083
current_source = context.LookupFile (source_file, new_file_name);
2084
source_file.AddIncludeFile (current_source);
2085
Location.Push (current_source);
2088
if (!hidden_block_start.IsNull) {
2089
current_source.RegisterHiddenScope (hidden_block_start, loc);
2090
hidden_block_start = Location.Null;
2093
//ref_line = new_line;
2098
// Handles #define and #undef
2100
void PreProcessDefinition (bool is_define, string ident, bool caller_is_taking)
2102
if (ident.Length == 0 || ident == "true" || ident == "false"){
2103
Report.Error (1001, Location, "Missing identifier to pre-processor directive");
2107
if (ident.IndexOfAny (simple_whitespaces) != -1){
2108
Error_EndLineExpected ();
2112
if (!is_identifier_start_character (ident [0]))
2113
Report.Error (1001, Location, "Identifier expected: {0}", ident);
2115
foreach (char c in ident.Substring (1)){
2116
if (!is_identifier_part_character (c)){
2117
Report.Error (1001, Location, "Identifier expected: {0}", ident);
2122
if (!caller_is_taking)
2129
if (context.Settings.IsConditionalSymbolDefined (ident))
2132
source_file.AddDefine (ident);
2137
source_file.AddUndefine (ident);
2141
byte read_hex (out bool error)
2144
int c = get_char ();
2146
if ((c >= '0') && (c <= '9'))
2147
total = (int) c - (int) '0';
2148
else if ((c >= 'A') && (c <= 'F'))
2149
total = (int) c - (int) 'A' + 10;
2150
else if ((c >= 'a') && (c <= 'f'))
2151
total = (int) c - (int) 'a' + 10;
2160
if ((c >= '0') && (c <= '9'))
2161
total += (int) c - (int) '0';
2162
else if ((c >= 'A') && (c <= 'F'))
2163
total += (int) c - (int) 'A' + 10;
2164
else if ((c >= 'a') && (c <= 'f'))
2165
total += (int) c - (int) 'a' + 10;
2172
return (byte) total;
2176
// Parses #pragma checksum
2178
bool ParsePragmaChecksum ()
2181
// The syntax is ` "foo.txt" "{guid}" "hash"'
2183
int c = get_char ();
2188
string file_name = TokenizeFileName (ref c);
2190
// TODO: Any white-spaces count
2194
SourceFile file = context.LookupFile (source_file, file_name);
2196
if (get_char () != '"' || get_char () != '{')
2200
byte[] guid_bytes = new byte [16];
2203
for (; i < 4; i++) {
2204
guid_bytes [i] = read_hex (out error);
2209
if (get_char () != '-')
2212
for (; i < 10; i++) {
2213
guid_bytes [i] = read_hex (out error);
2217
guid_bytes [i++] = read_hex (out error);
2221
if (get_char () != '-')
2225
for (; i < 16; i++) {
2226
guid_bytes [i] = read_hex (out error);
2231
if (get_char () != '}' || get_char () != '"')
2234
// TODO: Any white-spaces count
2239
if (get_char () != '"')
2242
// Any length of checksum
2243
List<byte> checksum_bytes = new List<byte> (16);
2246
while (c != '"' && c != -1) {
2247
checksum_bytes.Add (read_hex (out error));
2255
ReadSingleLineComment ();
2256
} else if (get_char () != '"') {
2260
file.SetChecksum (guid_bytes, checksum_bytes.ToArray ());
2261
current_source.AutoGenerated = true;
2268
bool IsTokenIdentifierEqual (char[] identifier)
2270
for (int i = 0; i < identifier.Length; ++i) {
2271
if (identifier[i] != id_builder[i])
2278
int TokenizeNumber (int value)
2282
decimal_digits (value);
2283
uint ui = (uint) (number_builder[0] - '0');
2286
for (int i = 1; i < number_pos; i++) {
2287
ui = checked ((ui * 10) + ((uint) (number_builder[i] - '0')));
2291
} catch (OverflowException) {
2292
Error_NumericConstantTooLong ();
2297
string TokenizeFileName (ref int c)
2299
var string_builder = new StringBuilder ();
2300
while (c != -1 && c != '\n') {
2307
string_builder.Append ((char) c);
2310
if (string_builder.Length == 0) {
2311
Report.Warning (1709, 1, Location, "Filename specified for preprocessor directive is empty");
2315
return string_builder.ToString ();
2318
int TokenizePragmaNumber (ref int c)
2324
if (c >= '0' && c <= '9') {
2325
number = TokenizeNumber (c);
2329
// skip over white space
2330
while (c == ' ' || c == '\t')
2337
// skip over white space
2338
while (c == ' ' || c == '\t')
2343
ReadSingleLineComment ();
2345
Report.Warning (1692, 1, Location, "Invalid number");
2347
// Read everything till the end of the line or file
2350
} while (c != -1 && c != '\n');
2358
void ReadSingleLineComment ()
2360
if (peek_char () != '/')
2361
Report.Warning (1696, 1, Location, "Single-line comment or end-of-line expected");
2362
if (position_stack.Count == 0)
2363
sbag.StartComment (SpecialsBag.CommentType.Single, startsLine, line, col - 1);
2364
// Read everything till the end of the line or file
2368
if (position_stack.Count == 0)
2369
sbag.PushCommentChar (c);
2370
var pc = peek_char ();
2371
if ((pc == '\n' || pc == -1) && position_stack.Count == 0)
2372
sbag.EndComment (line, col + 1);
2373
} while (c != -1 && c != '\n');
2377
/// Handles #pragma directive
2379
void ParsePragmaDirective (string arg)
2382
int length = TokenizePreprocessorIdentifier (out c);
2383
if (length == pragma_warning.Length && IsTokenIdentifierEqual (pragma_warning)) {
2384
length = TokenizePreprocessorIdentifier (out c);
2387
// #pragma warning disable
2388
// #pragma warning restore
2390
if (length == pragma_warning_disable.Length) {
2391
bool disable = IsTokenIdentifierEqual (pragma_warning_disable);
2392
if (disable || IsTokenIdentifierEqual (pragma_warning_restore)) {
2393
// skip over white space
2394
while (c == ' ' || c == '\t')
2399
if (c == '\n' || c == '/') {
2401
ReadSingleLineComment ();
2404
// Disable/Restore all warnings
2407
Report.RegisterWarningRegion (loc).WarningDisable (loc.Row);
2409
Report.RegisterWarningRegion (loc).WarningEnable (loc.Row);
2413
// Disable/Restore a warning or group of warnings
2417
code = TokenizePragmaNumber (ref c);
2420
Report.RegisterWarningRegion (loc).WarningDisable (loc, code, context.Report);
2422
Report.RegisterWarningRegion (loc).WarningEnable (loc, code, context);
2425
} while (code >= 0 && c != '\n' && c != -1);
2432
Report.Warning (1634, 1, Location, "Expected disable or restore");
2439
if (length == pragma_checksum.Length && IsTokenIdentifierEqual (pragma_checksum)) {
2440
if (c != ' ' || !ParsePragmaChecksum ()) {
2441
Report.Warning (1695, 1, Location,
2442
"Invalid #pragma checksum syntax. Expected \"filename\" \"{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\" \"XXXX...\"");
2448
Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
2451
bool eval_val (string s)
2458
return source_file.IsConditionalDefined (s);
2461
bool pp_primary (ref string s)
2470
s = s.Substring (1);
2471
bool val = pp_expr (ref s, false);
2472
if (s.Length > 0 && s [0] == ')'){
2473
s = s.Substring (1);
2476
Error_InvalidDirective ();
2480
if (is_identifier_start_character (c)){
2486
if (is_identifier_part_character (c)){
2490
bool v = eval_val (s.Substring (0, j));
2491
s = s.Substring (j);
2494
bool vv = eval_val (s);
2499
Error_InvalidDirective ();
2503
bool pp_unary (ref string s)
2510
if (len > 1 && s [1] == '='){
2511
Error_InvalidDirective ();
2514
s = s.Substring (1);
2515
return ! pp_primary (ref s);
2517
return pp_primary (ref s);
2519
Error_InvalidDirective ();
2524
bool pp_eq (ref string s)
2526
bool va = pp_unary (ref s);
2532
if (len > 2 && s [1] == '='){
2533
s = s.Substring (2);
2534
return va == pp_unary (ref s);
2536
Error_InvalidDirective ();
2539
} else if (s [0] == '!' && len > 1 && s [1] == '='){
2540
s = s.Substring (2);
2542
return va != pp_unary (ref s);
2551
bool pp_and (ref string s)
2553
bool va = pp_eq (ref s);
2559
if (len > 2 && s [1] == '&'){
2560
s = s.Substring (2);
2561
return (va & pp_and (ref s));
2563
Error_InvalidDirective ();
2572
// Evaluates an expression for `#if' or `#elif'
2574
bool pp_expr (ref string s, bool isTerm)
2576
bool va = pp_and (ref s);
2583
if (len > 2 && s [1] == '|'){
2584
s = s.Substring (2);
2585
return va | pp_expr (ref s, isTerm);
2587
Error_InvalidDirective ();
2592
Error_EndLineExpected ();
2600
bool eval (string s)
2602
bool v = pp_expr (ref s, true);
2611
void Error_NumericConstantTooLong ()
2613
Report.Error (1021, Location, "Integral constant is too large");
2616
void Error_InvalidDirective ()
2618
Report.Error (1517, Location, "Invalid preprocessor directive");
2621
void Error_UnexpectedDirective (string extra)
2625
"Unexpected processor directive ({0})", extra);
2628
void Error_TokensSeen ()
2630
Report.Error (1032, Location,
2631
"Cannot define or undefine preprocessor symbols after first token in file");
2634
void Eror_WrongPreprocessorLocation ()
2636
Report.Error (1040, Location,
2637
"Preprocessor directives must appear as the first non-whitespace character on a line");
2640
void Error_EndLineExpected ()
2642
Report.Error (1025, Location, "Single-line comment or end-of-line expected");
2646
// Raises a warning when tokenizer found documentation comment
2647
// on unexpected place
2649
void WarningMisplacedComment (Location loc)
2651
if (doc_state != XmlCommentState.Error) {
2652
doc_state = XmlCommentState.Error;
2653
Report.Warning (1587, 2, loc, "XML comment is not placed on a valid language element");
2658
// if true, then the code continues processing the code
2659
// if false, the code stays in a loop until another directive is
2661
// When caller_is_taking is false we ignore all directives except the ones
2662
// which can help us to identify where the #if block ends
2663
bool ParsePreprocessingDirective (bool caller_is_taking)
2666
bool region_directive = false;
2668
var directive = get_cmd_arg (out arg);
2671
// The first group of pre-processing instructions is always processed
2673
switch (directive) {
2674
case PreprocessorDirective.Region:
2675
region_directive = true;
2677
goto case PreprocessorDirective.If;
2679
case PreprocessorDirective.Endregion:
2680
if (ifstack == null || ifstack.Count == 0){
2681
Error_UnexpectedDirective ("no #region for this #endregion");
2684
int pop = ifstack.Pop ();
2686
if ((pop & REGION) == 0)
2687
Report.Error (1027, Location, "Expected `#endif' directive");
2689
return caller_is_taking;
2691
case PreprocessorDirective.If:
2692
if (ifstack == null)
2693
ifstack = new Stack<int> (2);
2695
int flags = region_directive ? REGION : 0;
2696
if (ifstack.Count == 0){
2697
flags |= PARENT_TAKING;
2699
int state = ifstack.Peek ();
2700
if ((state & TAKING) != 0) {
2701
flags |= PARENT_TAKING;
2705
if (eval (arg) && caller_is_taking) {
2706
ifstack.Push (flags | TAKING);
2710
ifstack.Push (flags);
2713
case PreprocessorDirective.Endif:
2714
if (ifstack == null || ifstack.Count == 0){
2715
Error_UnexpectedDirective ("no #if for this #endif");
2718
pop = ifstack.Pop ();
2720
if ((pop & REGION) != 0)
2721
Report.Error (1038, Location, "#endregion directive expected");
2723
if (arg.Length != 0) {
2724
Error_EndLineExpected ();
2727
if (ifstack.Count == 0)
2730
int state = ifstack.Peek ();
2731
return (state & TAKING) != 0;
2734
case PreprocessorDirective.Elif:
2735
if (ifstack == null || ifstack.Count == 0){
2736
Error_UnexpectedDirective ("no #if for this #elif");
2739
int state = ifstack.Pop ();
2741
if ((state & REGION) != 0) {
2742
Report.Error (1038, Location, "#endregion directive expected");
2746
if ((state & ELSE_SEEN) != 0){
2747
Error_UnexpectedDirective ("#elif not valid after #else");
2751
if ((state & TAKING) != 0) {
2756
if (eval (arg) && ((state & PARENT_TAKING) != 0)){
2757
ifstack.Push (state | TAKING);
2761
ifstack.Push (state);
2765
case PreprocessorDirective.Else:
2766
if (ifstack == null || ifstack.Count == 0){
2767
Error_UnexpectedDirective ("no #if for this #else");
2770
int state = ifstack.Peek ();
2772
if ((state & REGION) != 0) {
2773
Report.Error (1038, Location, "#endregion directive expected");
2777
if ((state & ELSE_SEEN) != 0){
2778
Error_UnexpectedDirective ("#else within #else");
2784
if (arg.Length != 0) {
2785
Error_EndLineExpected ();
2790
if ((state & PARENT_TAKING) != 0) {
2791
ret = (state & TAKING) == 0;
2799
ifstack.Push (state | ELSE_SEEN);
2803
case PreprocessorDirective.Define:
2804
if (any_token_seen){
2805
Error_TokensSeen ();
2806
return caller_is_taking;
2808
PreProcessDefinition (true, arg, caller_is_taking);
2809
return caller_is_taking;
2811
case PreprocessorDirective.Undef:
2812
if (any_token_seen){
2813
Error_TokensSeen ();
2814
return caller_is_taking;
2816
PreProcessDefinition (false, arg, caller_is_taking);
2817
return caller_is_taking;
2819
case PreprocessorDirective.Invalid:
2820
Report.Error (1024, Location, "Wrong preprocessor directive");
2825
// These are only processed if we are in a `taking' block
2827
if (!caller_is_taking)
2831
case PreprocessorDirective.Error:
2832
Report.Error (1029, Location, "#error: '{0}'", arg);
2835
case PreprocessorDirective.Warning:
2836
Report.Warning (1030, 1, Location, "#warning: `{0}'", arg);
2839
case PreprocessorDirective.Pragma:
2840
if (context.Settings.Version == LanguageVersion.ISO_1) {
2841
Report.FeatureIsNotAvailable (context, Location, "#pragma");
2844
ParsePragmaDirective (arg);
2847
case PreprocessorDirective.Line:
2848
Location loc = Location;
2849
if (!PreProcessLine ())
2850
Report.Error (1576, loc, "The line number specified for #line directive is missing or invalid");
2852
return caller_is_taking;
2855
throw new NotImplementedException (directive.ToString ());
2858
private int consume_string (bool quoted)
2862
Location start_location = Location;
2864
start_location = start_location - 1;
2867
int reader_pos = reader.Position;
2873
if (quoted && peek_char () == '"') {
2874
if (pos == value_builder.Length)
2875
Array.Resize (ref value_builder, pos * 2);
2877
value_builder[pos++] = (char) c;
2886
s = InternIdentifier (value_builder, pos);
2888
s = new string (value_builder, 0, pos);
2890
ILiteralConstant res = new StringLiteral (context.BuiltinTypes, s, start_location);
2893
res.ParsedValue = quoted ?
2894
reader.ReadChars (reader_pos - 2, reader.Position - 1) :
2895
reader.ReadChars (reader_pos - 1, reader.Position);
2898
return Token.LITERAL;
2903
Report.Error (1010, Location, "Newline in constant");
2904
val = new StringLiteral (context.BuiltinTypes, new string (value_builder, 0, pos), start_location);
2905
return Token.LITERAL;
2907
} else if (c == '\\' && !quoted) {
2909
c = escape (c, out surrogate);
2912
if (surrogate != 0) {
2913
if (pos == value_builder.Length)
2914
Array.Resize (ref value_builder, pos * 2);
2916
value_builder[pos++] = (char) c;
2919
} else if (c == -1) {
2920
Report.Error (1039, Location, "Unterminated string literal");
2924
if (pos == value_builder.Length)
2925
Array.Resize (ref value_builder, pos * 2);
2927
value_builder[pos++] = (char) c;
2931
private int consume_identifier (int s)
2933
int res = consume_identifier (s, false);
2935
if (doc_state == XmlCommentState.Allowed)
2936
doc_state = XmlCommentState.NotAllowed;
2941
int consume_identifier (int c, bool quoted)
2944
// This method is very performance sensitive. It accounts
2945
// for approximately 25% of all parser time
2955
c = escape (c, out surrogate);
2956
if (surrogate != 0) {
2957
id_builder [pos++] = (char) c;
2962
id_builder [pos++] = (char) c;
2968
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9')) {
2969
id_builder [pos++] = (char) c;
2976
c = escape (c, out surrogate);
2977
if (is_identifier_part_character ((char) c))
2978
id_builder[pos++] = (char) c;
2980
if (surrogate != 0) {
2986
} else if (Char.IsLetter ((char) c) || Char.GetUnicodeCategory ((char) c) == UnicodeCategory.ConnectorPunctuation) {
2987
id_builder [pos++] = (char) c;
2994
} catch (IndexOutOfRangeException) {
2995
Report.Error (645, Location, "Identifier too long (limit is 512 chars)");
3003
// Optimization: avoids doing the keyword lookup
3004
// on uppercase letters
3006
if (id_builder [0] >= '_' && !quoted) {
3007
int keyword = GetKeyword (id_builder, pos);
3008
if (keyword != -1) {
3009
val = LocatedToken.Create (keyword == Token.AWAIT ? "await" : null, ref_line, column);
3014
string s = InternIdentifier (id_builder, pos);
3017
val = LocatedToken.Create ("@" + s, ref_line, column - 1);
3019
val = LocatedToken.Create (s, ref_line, column);
3022
val = LocatedToken.Create (s, ref_line, column);
3024
if (quoted && parsing_attribute_section)
3025
AddEscapedIdentifier (((LocatedToken) val).Location);
3027
return Token.IDENTIFIER;
3033
string InternIdentifier (char[] charBuffer, int length)
3036
// Keep identifiers in an array of hashtables to avoid needless
3039
var identifiers_group = identifiers [length];
3041
if (identifiers_group != null) {
3042
if (identifiers_group.TryGetValue (charBuffer, out s)) {
3046
// TODO: this should be number of files dependant
3047
// corlib compilation peaks at 1000 and System.Core at 150
3048
int capacity = length > 20 ? 10 : 100;
3049
identifiers_group = new Dictionary<char[], string> (capacity, new IdentifiersComparer (length));
3050
identifiers [length] = identifiers_group;
3053
char[] chars = new char[length];
3054
Array.Copy (charBuffer, chars, length);
3056
s = new string (charBuffer, 0, length);
3057
identifiers_group.Add (chars, s);
3062
public int xtoken ()
3066
// Whether we have seen comments on the current line
3067
bool comments_seen = false;
3068
while ((c = get_char ()) != -1) {
3071
col = ((col - 1 + tab_size) / tab_size) * tab_size;
3079
case 0xFEFF: // Ignore BOM anywhere in the file
3082
/* This is required for compatibility with .NET
3084
if (peek_char () == 0xBB) {
3087
if (get_char () == 0xBF)
3095
return consume_identifier (c);
3098
val = LocatedToken.Create (ref_line, col);
3099
return Token.OPEN_BRACE;
3101
val = LocatedToken.Create (ref_line, col);
3102
return Token.CLOSE_BRACE;
3104
// To block doccomment inside attribute declaration.
3105
if (doc_state == XmlCommentState.Allowed)
3106
doc_state = XmlCommentState.NotAllowed;
3108
val = LocatedToken.Create (ref_line, col);
3110
if (parsing_block == 0 || lambda_arguments_parsing)
3111
return Token.OPEN_BRACKET;
3113
int next = peek_char ();
3117
return Token.OPEN_BRACKET;
3125
next = peek_token ();
3126
if (next == Token.COMMA || next == Token.CLOSE_BRACKET)
3127
return Token.OPEN_BRACKET;
3129
return Token.OPEN_BRACKET_EXPR;
3131
return Token.OPEN_BRACKET_EXPR;
3134
LocatedToken.CreateOptional (ref_line, col, ref val);
3135
return Token.CLOSE_BRACKET;
3137
val = LocatedToken.Create (ref_line, col);
3139
// An expression versions of parens can appear in block context only
3141
if (parsing_block != 0 && !lambda_arguments_parsing) {
3144
// Optmize most common case where we know that parens
3147
switch (current_token) {
3148
case Token.IDENTIFIER:
3156
case Token.DELEGATE:
3157
case Token.OP_GENERICS_GT:
3158
return Token.OPEN_PARENS;
3161
// Optimize using peek
3162
int xx = peek_char ();
3169
return Token.OPEN_PARENS;
3172
lambda_arguments_parsing = true;
3174
d = TokenizeOpenParens ();
3176
lambda_arguments_parsing = false;
3180
return Token.OPEN_PARENS;
3182
LocatedToken.CreateOptional (ref_line, col, ref val);
3183
return Token.CLOSE_PARENS;
3185
LocatedToken.CreateOptional (ref_line, col, ref val);
3188
LocatedToken.CreateOptional (ref_line, col, ref val);
3189
return Token.SEMICOLON;
3191
val = LocatedToken.Create (ref_line, col);
3194
val = LocatedToken.Create (ref_line, col);
3195
return TokenizePossibleNullableType ();
3197
val = LocatedToken.Create (ref_line, col);
3198
if (parsing_generic_less_than++ > 0)
3199
return Token.OP_GENERICS_LT;
3201
return TokenizeLessThan ();
3204
val = LocatedToken.Create (ref_line, col);
3212
if (parsing_generic_less_than > 1 || (parsing_generic_less_than == 1 && d != '>')) {
3213
parsing_generic_less_than--;
3214
return Token.OP_GENERICS_GT;
3223
return Token.OP_SHIFT_RIGHT_ASSIGN;
3225
return Token.OP_SHIFT_RIGHT;
3231
val = LocatedToken.Create (ref_line, col);
3235
} else if (d == '=') {
3236
d = Token.OP_ADD_ASSIGN;
3244
val = LocatedToken.Create (ref_line, col);
3248
} else if (d == '=')
3249
d = Token.OP_SUB_ASSIGN;
3259
val = LocatedToken.Create (ref_line, col);
3260
if (peek_char () == '=') {
3267
val = LocatedToken.Create (ref_line, col);
3278
return Token.ASSIGN;
3281
val = LocatedToken.Create (ref_line, col);
3285
return Token.OP_AND;
3289
return Token.OP_AND_ASSIGN;
3291
return Token.BITWISE_AND;
3294
val = LocatedToken.Create (ref_line, col);
3302
return Token.OP_OR_ASSIGN;
3304
return Token.BITWISE_OR;
3307
val = LocatedToken.Create (ref_line, col);
3308
if (peek_char () == '=') {
3310
return Token.OP_MULT_ASSIGN;
3317
val = LocatedToken.Create (ref_line, col);
3319
return Token.OP_DIV_ASSIGN;
3321
// Handle double-slash comments.
3324
if (doc_processing) {
3325
if (peek_char () == '/') {
3327
// Don't allow ////.
3328
if ((d = peek_char ()) != '/') {
3329
if (position_stack.Count == 0)
3330
sbag.PushCommentChar (d);
3331
if (doc_state == XmlCommentState.Allowed)
3332
handle_one_line_xml_comment ();
3333
else if (doc_state == XmlCommentState.NotAllowed)
3334
WarningMisplacedComment (Location - 3);
3337
if (xml_comment_buffer.Length > 0)
3338
doc_state = XmlCommentState.NotAllowed;
3341
bool isDoc = peek_char () == '/';
3342
if (position_stack.Count == 0)
3343
sbag.StartComment (isDoc ? SpecialsBag.CommentType.Documentation : SpecialsBag.CommentType.Single, startsLine, line, col - 1);
3349
int endLine = line, endCol = col;
3350
while ((d = get_char ()) != -1 && (d != '\n') && d != '\r') {
3351
if (position_stack.Count == 0)
3352
sbag.PushCommentChar (d);
3356
if (position_stack.Count == 0)
3357
sbag.EndComment (endLine, endCol + 1);
3359
any_token_seen |= tokens_seen;
3360
tokens_seen = false;
3361
comments_seen = false;
3363
} else if (d == '*'){
3364
if (position_stack.Count == 0)
3365
sbag.StartComment (SpecialsBag.CommentType.Multi, startsLine, line, col);
3367
bool docAppend = false;
3368
if (doc_processing && peek_char () == '*') {
3369
int ch = get_char ();
3370
// But when it is /**/, just do nothing.
3371
if (peek_char () == '/') {
3373
if (position_stack.Count == 0) {
3374
sbag.EndComment (line, col + 1);
3378
if (position_stack.Count == 0)
3379
sbag.PushCommentChar (ch);
3381
if (doc_state == XmlCommentState.Allowed)
3383
else if (doc_state == XmlCommentState.NotAllowed) {
3384
WarningMisplacedComment (Location - 2);
3388
int current_comment_start = 0;
3390
current_comment_start = xml_comment_buffer.Length;
3391
xml_comment_buffer.Append (Environment.NewLine);
3394
while ((d = get_char ()) != -1){
3395
if (d == '*' && peek_char () == '/'){
3397
if (position_stack.Count == 0)
3398
sbag.EndComment (line, col + 1);
3399
comments_seen = true;
3402
if (position_stack.Count == 0)
3403
sbag.PushCommentChar (d);
3406
xml_comment_buffer.Append ((char) d);
3409
any_token_seen |= tokens_seen;
3410
tokens_seen = false;
3412
// Reset 'comments_seen' just to be consistent.
3413
// It doesn't matter either way, here.
3415
comments_seen = false;
3420
Report.Error (1035, Location, "End-of-file found, '*/' expected");
3423
update_formatted_doc_comment (current_comment_start);
3426
val = LocatedToken.Create (ref_line, col);
3430
val = LocatedToken.Create (ref_line, col);
3431
if (peek_char () == '='){
3433
return Token.OP_MOD_ASSIGN;
3435
return Token.PERCENT;
3438
val = LocatedToken.Create (ref_line, col);
3439
if (peek_char () == '='){
3441
return Token.OP_XOR_ASSIGN;
3443
return Token.CARRET;
3446
val = LocatedToken.Create (ref_line, col);
3447
if (peek_char () == ':') {
3449
return Token.DOUBLE_COLON;
3453
case '0': case '1': case '2': case '3': case '4':
3454
case '5': case '6': case '7': case '8': case '9':
3456
return is_number (c);
3458
case '\n': // white space
3459
any_token_seen |= tokens_seen;
3460
tokens_seen = false;
3461
comments_seen = false;
3467
if (d >= '0' && d <= '9')
3468
return is_number (c);
3470
LocatedToken.CreateOptional (ref_line, col, ref val);
3474
if (tokens_seen || comments_seen) {
3475
Eror_WrongPreprocessorLocation ();
3479
if (ParsePreprocessingDirective (true))
3481
sbag.StartComment (SpecialsBag.CommentType.InactiveCode, false, line, 1);
3482
bool directive_expected = false;
3483
while ((c = get_char ()) != -1) {
3485
directive_expected = true;
3486
} else if (!directive_expected) {
3487
// TODO: Implement comment support for disabled code and uncomment this code
3489
// Eror_WrongPreprocessorLocation ();
3490
// return Token.ERROR;
3492
sbag.PushCommentChar (c);
3496
if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\v' ) {
3497
sbag.PushCommentChar (c);
3502
if (ParsePreprocessingDirective (false))
3505
sbag.PushCommentChar (c);
3506
directive_expected = false;
3508
sbag.EndComment (line, col);
3510
tokens_seen = false;
3517
return consume_string (false);
3520
return TokenizeBackslash ();
3526
return consume_string (true);
3529
if (is_identifier_start_character (c)){
3530
return consume_identifier (c, true);
3533
Report.Error (1646, Location, "Keyword, identifier, or string expected after verbatim specifier: @");
3536
case EvalStatementParserCharacter:
3537
return Token.EVAL_STATEMENT_PARSER;
3538
case EvalCompilationUnitParserCharacter:
3539
return Token.EVAL_COMPILATION_UNIT_PARSER;
3540
case EvalUsingDeclarationsParserCharacter:
3541
return Token.EVAL_USING_DECLARATIONS_UNIT_PARSER;
3542
case DocumentationXref:
3543
return Token.DOC_SEE;
3546
if (is_identifier_start_character (c)) {
3548
return consume_identifier (c);
3551
if (char.IsWhiteSpace ((char) c))
3554
Report.Error (1056, Location, "Unexpected character `{0}'", ((char) c).ToString ());
3559
return Token.COMPLETE_COMPLETION;
3562
return Token.GENERATE_COMPLETION;
3569
int TokenizeBackslash ()
3572
int read_start = reader.Position;
3574
Location start_location = Location;
3575
int c = get_char ();
3578
val = new CharLiteral (context.BuiltinTypes, (char) c, start_location);
3579
Report.Error (1011, start_location, "Empty character literal");
3580
return Token.LITERAL;
3584
Report.Error (1010, start_location, "Newline in constant");
3589
c = escape (c, out d);
3593
throw new NotImplementedException ();
3595
ILiteralConstant res = new CharLiteral (context.BuiltinTypes, (char) c, start_location);
3600
Report.Error (1012, start_location, "Too many characters in character literal");
3602
// Try to recover, read until newline or next "'"
3603
while ((c = get_char ()) != -1) {
3604
if (c == '\n' || c == '\'')
3610
res.ParsedValue = reader.ReadChars (read_start - 1, reader.Position);
3613
return Token.LITERAL;
3616
int TokenizeLessThan ()
3619
if (handle_typeof) {
3621
if (parse_generic_dimension (out d)) {
3624
return Token.GENERIC_DIMENSION;
3629
// Save current position and parse next token.
3631
if (parse_less_than ()) {
3632
if (parsing_generic_declaration && (parsing_generic_declaration_doc || token () != Token.DOT)) {
3633
d = Token.OP_GENERICS_LT_DECL;
3635
d = Token.OP_GENERICS_LT;
3642
parsing_generic_less_than = 0;
3651
return Token.OP_SHIFT_LEFT_ASSIGN;
3653
return Token.OP_SHIFT_LEFT;
3664
// Handles one line xml comment
3666
private void handle_one_line_xml_comment ()
3669
while ((c = peek_char ()) == ' ') {
3670
if (position_stack.Count == 0)
3671
sbag.PushCommentChar (c);
3672
get_char (); // skip heading whitespaces.
3674
while ((c = peek_char ()) != -1 && c != '\n' && c != '\r') {
3675
if (position_stack.Count == 0)
3676
sbag.PushCommentChar (c);
3677
xml_comment_buffer.Append ((char) get_char ());
3679
if (c == '\r' || c == '\n')
3680
xml_comment_buffer.Append (Environment.NewLine);
3684
// Remove heading "*" in Javadoc-like xml documentation.
3686
private void update_formatted_doc_comment (int current_comment_start)
3688
int length = xml_comment_buffer.Length - current_comment_start;
3689
string [] lines = xml_comment_buffer.ToString (
3690
current_comment_start,
3691
length).Replace ("\r", "").Split ('\n');
3693
// The first line starts with /**, thus it is not target
3694
// for the format check.
3695
for (int i = 1; i < lines.Length; i++) {
3696
string s = lines [i];
3697
int idx = s.IndexOf ('*');
3700
if (i < lines.Length - 1)
3704
head = s.Substring (0, idx);
3705
foreach (char c in head)
3708
lines [i] = s.Substring (idx + 1);
3710
xml_comment_buffer.Remove (current_comment_start, length);
3711
xml_comment_buffer.Insert (current_comment_start, String.Join (Environment.NewLine, lines));
3715
// Checks if there was incorrect doc comments and raise
3718
public void check_incorrect_doc_comment ()
3720
if (xml_comment_buffer.Length > 0)
3721
WarningMisplacedComment (Location);
3725
// Consumes the saved xml comment lines (if any)
3726
// as for current target member or type.
3728
public string consume_doc_comment ()
3730
if (xml_comment_buffer.Length > 0) {
3731
string ret = xml_comment_buffer.ToString ();
3732
reset_doc_comment ();
3739
get { return context.Report; }
3742
void reset_doc_comment ()
3744
xml_comment_buffer.Length = 0;
3747
public void cleanup ()
3749
if (ifstack != null && ifstack.Count >= 1) {
3750
int state = ifstack.Pop ();
3751
if ((state & REGION) != 0)
3752
Report.Error (1038, Location, "#endregion directive expected");
3754
Report.Error (1027, Location, "Expected `#endif' directive");
3760
// Indicates whether it accepts XML documentation or not.
3762
public enum XmlCommentState {
3763
// comment is allowed in this state.
3765
// comment is not allowed in this state.
3767
// once comments appeared when it is NotAllowed, then the
3768
// state is changed to it, until the state is changed to