Browse Source

[Parser] Added conditional symbols to the compilation unit.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
8090455130
  1. 21
      ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs
  2. 7
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  3. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  4. 1
      ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  5. 6
      ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs

21
ICSharpCode.NRefactory.CSharp/Ast/CompilationUnit.cs

@ -61,13 +61,30 @@ namespace ICSharpCode.NRefactory.CSharp
public AstNodeCollection<AstNode> Members { public AstNodeCollection<AstNode> Members {
get { return GetChildrenByRole(MemberRole); } get { return GetChildrenByRole(MemberRole); }
} }
string[] conditionals = null;
List<Error> errors = new List<Error> (); List<Error> errors = new List<Error> ();
public List<Error> Errors { public List<Error> Errors {
get { return errors; } get { return errors; }
} }
/// <summary>
/// Gets the conditional symbols used to parse the source file. Note that this list contains
/// the conditional symbols at the start of the first token in the file - including the ones defined
/// in the source file.
/// </summary>
public string[] Conditionals {
get {
return conditionals ?? new string[0];
}
internal set {
conditionals = value;
}
}
/// <summary> /// <summary>
/// Gets the expression that was on top of the parse stack. /// Gets the expression that was on top of the parse stack.
/// This is the only way to get an expression that isn't part of a statment. /// This is the only way to get an expression that isn't part of a statment.

7
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -3669,7 +3669,9 @@ namespace ICSharpCode.NRefactory.CSharp
if (top.LastYYValue is Mono.CSharp.Expression) { if (top.LastYYValue is Mono.CSharp.Expression) {
conversionVisitor.Unit.TopExpression = ((Mono.CSharp.Expression)top.LastYYValue).Accept(conversionVisitor) as AstNode; conversionVisitor.Unit.TopExpression = ((Mono.CSharp.Expression)top.LastYYValue).Accept(conversionVisitor) as AstNode;
} }
conversionVisitor.Unit.FileName = fileName; conversionVisitor.Unit.FileName = fileName;
conversionVisitor.Unit.Conditionals = top.Conditionals.ToArray ();
return conversionVisitor.Unit; return conversionVisitor.Unit;
} }
@ -3710,11 +3712,12 @@ namespace ICSharpCode.NRefactory.CSharp
Location.Initialize (new List<SourceFile> (new [] { file })); Location.Initialize (new List<SourceFile> (new [] { file }));
var module = new ModuleContainer (ctx); var module = new ModuleContainer (ctx);
var parser = Driver.Parse (reader, file, module, lineModifier); var parser = Driver.Parse (reader, file, module, lineModifier);
var top = new CompilerCompilationUnit () { var top = new CompilerCompilationUnit () {
ModuleCompiled = module, ModuleCompiled = module,
LocationsBag = parser.LocationsBag, LocationsBag = parser.LocationsBag,
SpecialsBag = parser.Lexer.sbag SpecialsBag = parser.Lexer.sbag,
Conditionals = parser.Lexer.SourceFile.Conditionals
}; };
var unit = Parse (top, fileName, lineModifier); var unit = Parse (top, fileName, lineModifier);
unit.Errors.AddRange (errorReportPrinter.Errors); unit.Errors.AddRange (errorReportPrinter.Errors);

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs

@ -174,6 +174,13 @@ namespace Mono.CSharp
readonly SeekableStreamReader reader; readonly SeekableStreamReader reader;
readonly CompilationSourceFile source_file; readonly CompilationSourceFile source_file;
public CompilationSourceFile SourceFile {
get {
return source_file;
}
}
readonly CompilerContext context; readonly CompilerContext context;
SourceFile current_source; SourceFile current_source;

1
ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs

@ -369,6 +369,7 @@ namespace Mono.CSharp
public ModuleContainer ModuleCompiled { get; set; } public ModuleContainer ModuleCompiled { get; set; }
public LocationsBag LocationsBag { get; set; } public LocationsBag LocationsBag { get; set; }
public SpecialsBag SpecialsBag { get; set; } public SpecialsBag SpecialsBag { get; set; }
public IEnumerable<string> Conditionals { get; set; }
public object LastYYValue { get; set; } public object LastYYValue { get; set; }
} }

6
ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs

@ -591,6 +591,12 @@ namespace Mono.CSharp {
} }
} }
public IEnumerable<string> Conditionals {
get {
return conditionals.Where (kv => kv.Value).Select (kv => kv.Key);
}
}
public string FileName { public string FileName {
get { get {
return file.Name; return file.Name;

Loading…
Cancel
Save