// Author: Miguel de Icaza (miguel@gnu.org)
// Marek Safar (marek.safar@seznam.cz)
//
-// Licensed under the terms of the GNU GPL
+// Dual licensed under the terms of the MIT X11 or GNU GPL
//
-// (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
-// (C) 2004 Novell, Inc
+// Copyright 2001, 2002 Ximian, Inc (http://www.ximian.com)
+// Copyright 2004-2008 Novell, Inc
//
//
{
SeekableStreamReader reader;
SourceFile ref_name;
- SourceFile file_name;
+ CompilationUnit file_name;
+ bool hidden = false;
int ref_line = 1;
int line = 1;
int col = 0;
Stack position_stack = new Stack (2);
class Position {
public int position;
+ public int line;
public int ref_line;
public int col;
+ public bool hidden;
public int putback_char;
public int previous_col;
public Stack ifstack;
public Position (Tokenizer t)
{
position = t.reader.Position;
+ line = t.line;
ref_line = t.ref_line;
col = t.col;
+ hidden = t.hidden;
putback_char = t.putback_char;
previous_col = t.previous_col;
if (t.ifstack != null && t.ifstack.Count != 0)
reader.Position = p.position;
ref_line = p.ref_line;
+ line = p.line;
col = p.col;
+ hidden = p.hidden;
putback_char = p.putback_char;
previous_col = p.previous_col;
ifstack = p.ifstack;
defines [def] = true;
}
- public Tokenizer (SeekableStreamReader input, SourceFile file, ArrayList defs)
+ public Tokenizer (SeekableStreamReader input, CompilationUnit file, ArrayList defs)
{
this.ref_name = file;
this.file_name = file;
// FIXME: This could be `Location.Push' but we have to
// find out why the MS compiler allows this
//
- Mono.CSharp.Location.Push (file);
+ Mono.CSharp.Location.Push (file, file);
}
static bool is_identifier_start_character (char c)
case Token.STAR:
case Token.SEMICOLON:
+ case Token.OPEN_BRACE:
case Token.OPEN_PARENS:
case Token.LITERAL_STRING:
return false;
{
putback (')');
- // When any binary operation is used we are sure it is not a cast
- if (expression is Binary)
+ // When any binary operation, a conditional is used we are sure it is not a cast
+ // maybe more.
+
+ if (expression is Binary || expression is Conditional)
return;
deambiguate_close_parens++;
{
return (e >= '0' && e <= '9') || (e >= 'A' && e <= 'F') || (e >= 'a' && e <= 'f');
}
-
+
static int real_type_suffix (int c)
{
int t;
case Token.DOUBLE:
case Token.FLOAT:
case Token.CHAR:
+ case Token.BYTE:
+ case Token.DECIMAL:
return true;
default:
if (arg == "default"){
ref_line = line;
ref_name = file_name;
- Location.Push (ref_name);
+ hidden = false;
+ Location.Push (file_name, ref_name);
return true;
} else if (arg == "hidden"){
- //
- // We ignore #line hidden
- //
+ hidden = true;
return true;
}
string name = arg.Substring (pos). Trim (quotes);
ref_name = Location.LookupFile (name);
- file_name.HasLineDirective = true;
- ref_name.HasLineDirective = true;
- Location.Push (ref_name);
+ file_name.AddFile (ref_name);
+ hidden = false;
+ Location.Push (file_name, ref_name);
} else {
ref_line = System.Int32.Parse (arg);
+ hidden = false;
}
} catch {
return false;
}
}
+ byte read_hex (string arg, int pos, out bool error)
+ {
+ error = false;
+
+ int total;
+ char c = arg [pos];
+
+ if ((c >= '0') && (c <= '9'))
+ total = (int) c - (int) '0';
+ else if ((c >= 'A') && (c <= 'F'))
+ total = (int) c - (int) 'A' + 10;
+ else if ((c >= 'a') && (c <= 'f'))
+ total = (int) c - (int) 'a' + 10;
+ else {
+ error = true;
+ return 0;
+ }
+
+ total *= 16;
+ c = arg [pos+1];
+
+ if ((c >= '0') && (c <= '9'))
+ total += (int) c - (int) '0';
+ else if ((c >= 'A') && (c <= 'F'))
+ total += (int) c - (int) 'A' + 10;
+ else if ((c >= 'a') && (c <= 'f'))
+ total += (int) c - (int) 'a' + 10;
+ else {
+ error = true;
+ return 0;
+ }
+
+ return (byte) total;
+ }
+
+ /// <summary>
+ /// Handles #pragma checksum
+ /// </summary>
+ bool PreProcessPragmaChecksum (string arg)
+ {
+ if ((arg [0] != ' ') && (arg [0] != '\t'))
+ return false;
+
+ arg = arg.Trim (simple_whitespaces);
+ if ((arg.Length < 2) || (arg [0] != '"'))
+ return false;
+
+ StringBuilder file_sb = new StringBuilder ();
+
+ int pos = 1;
+ char ch;
+ while ((ch = arg [pos++]) != '"') {
+ if (pos >= arg.Length)
+ return false;
+
+ if (ch == '\\') {
+ if (pos+1 >= arg.Length)
+ return false;
+ ch = arg [pos++];
+ }
+
+ file_sb.Append (ch);
+ }
+
+ if ((pos+2 >= arg.Length) || ((arg [pos] != ' ') && (arg [pos] != '\t')))
+ return false;
+
+ arg = arg.Substring (pos).Trim (simple_whitespaces);
+ if ((arg.Length < 42) || (arg [0] != '"') || (arg [1] != '{') ||
+ (arg [10] != '-') || (arg [15] != '-') || (arg [20] != '-') ||
+ (arg [25] != '-') || (arg [38] != '}') || (arg [39] != '"'))
+ return false;
+
+ bool error;
+ byte[] guid_bytes = new byte [16];
+
+ for (int i = 0; i < 4; i++) {
+ guid_bytes [i] = read_hex (arg, 2+2*i, out error);
+ if (error)
+ return false;
+ }
+ for (int i = 0; i < 2; i++) {
+ guid_bytes [i+4] = read_hex (arg, 11+2*i, out error);
+ if (error)
+ return false;
+ guid_bytes [i+6] = read_hex (arg, 16+2*i, out error);
+ if (error)
+ return false;
+ guid_bytes [i+8] = read_hex (arg, 21+2*i, out error);
+ if (error)
+ return false;
+ }
+
+ for (int i = 0; i < 6; i++) {
+ guid_bytes [i+10] = read_hex (arg, 26+2*i, out error);
+ if (error)
+ return false;
+ }
+
+ arg = arg.Substring (40).Trim (simple_whitespaces);
+ if ((arg.Length < 34) || (arg [0] != '"') || (arg [33] != '"'))
+ return false;
+
+ byte[] checksum_bytes = new byte [16];
+ for (int i = 0; i < 16; i++) {
+ checksum_bytes [i] = read_hex (arg, 1+2*i, out error);
+ if (error)
+ return false;
+ }
+
+ arg = arg.Substring (34).Trim (simple_whitespaces);
+ if (arg.Length > 0)
+ return false;
+
+ SourceFile file = Location.LookupFile (file_sb.ToString ());
+ file.SetChecksum (guid_bytes, checksum_bytes);
+ ref_name.AutoGenerated = true;
+ return true;
+ }
+
/// <summary>
/// Handles #pragma directive
/// </summary>
const string warning = "warning";
const string w_disable = "warning disable";
const string w_restore = "warning restore";
+ const string checksum = "checksum";
if (arg == w_disable) {
Report.RegisterWarningRegion (Location).WarningDisable (Location.Row);
return;
}
+ if (arg.StartsWith (checksum)) {
+ if (!PreProcessPragmaChecksum (arg.Substring (checksum.Length)))
+ Warning_InvalidPragmaChecksum ();
+ return;
+ }
+
Report.Warning (1633, 1, Location, "Unrecognized #pragma directive");
}
Report.Error (1025, Location, "Single-line comment or end-of-line expected");
}
+ void Warning_InvalidPragmaChecksum ()
+ {
+ Report.Warning (1695, 1, Location,
+ "Invalid #pragma checksum syntax; should be " +
+ "#pragma checksum \"filename\" " +
+ "\"{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\" \"XXXX...\"");
+ }
//
// if true, then the code continues processing the code
// if false, the code stays in a loop until another directive is
{
int c;
string_builder.Length = 0;
-
+
+ //
+ // No need to parse full string when parsing lambda arguments
+ //
+ if (lambda_arguments_parsing)
+ return Token.LITERAL_STRING;
+
while ((c = get_char ()) != -1){
if (c == '"'){
if (quoted && peek_char () == '"'){
id_builder [0] = (char) s;
- current_location = new Location (ref_line, Col);
+ current_location = new Location (ref_line, hidden ? -1 : Col);
while ((c = get_char ()) != -1) {
loop:
}
is_punct_label:
- current_location = new Location (ref_line, Col);
+ current_location = new Location (ref_line, hidden ? -1 : Col);
if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){
tokens_seen = true;
if (doread){
if (current_comment_location.IsNull) {
// "-2" is for heading "//" or "/*"
current_comment_location =
- new Location (ref_line, col - 2);
+ new Location (ref_line, hidden ? -1 : col - 2);
}
}
public void cleanup ()
{
if (ifstack != null && ifstack.Count >= 1) {
- current_location = new Location (ref_line, Col);
+ current_location = new Location (ref_line, hidden ? -1 : Col);
int state = (int) ifstack.Pop ();
if ((state & REGION) != 0)
Report.Error (1038, Location, "#endregion directive expected");