35
35
using MonoDevelop.Projects;
36
36
using MonoDevelop.CSharp.Project;
37
37
using MonoDevelop.Core;
38
using MonoDevelop.Projects.Dom.Parser;
39
using MonoDevelop.Projects.Dom;
39
41
namespace MonoDevelop.CSharp.Highlighting
177
179
class ConditinalExpressionEvaluator : ICSharpCode.NRefactory.Visitors.AbstractAstVisitor
179
181
HashSet<string> symbols = new HashSet<string> ();
180
public ConditinalExpressionEvaluator ()
183
public ConditinalExpressionEvaluator (Document doc)
182
185
var project = MonoDevelop.Ide.Gui.IdeApp.ProjectOperations.CurrentSelectedProject;
183
186
if (project != null) {
184
CSharpCompilerParameters cparams = ((DotNetProjectConfiguration)project.GetConfiguration (project.ParentSolution.DefaultConfigurationSelector)).CompilationParameters as CSharpCompilerParameters;
185
if (cparams != null) {
186
string[] syms = cparams.DefineSymbols.Split (';', ',');
187
foreach (string s in syms) {
188
string ss = s.Trim ();
189
if (ss.Length > 0 && !symbols.Contains (ss))
187
DotNetProjectConfiguration configuration = project.GetConfiguration (project.ParentSolution.DefaultConfigurationSelector) as DotNetProjectConfiguration;
188
if (configuration != null) {
189
CSharpCompilerParameters cparams = configuration.CompilationParameters as CSharpCompilerParameters;
190
if (cparams != null) {
191
string[] syms = cparams.DefineSymbols.Split (';', ',');
192
foreach (string s in syms) {
193
string ss = s.Trim ();
194
if (ss.Length > 0 && !symbols.Contains (ss))
201
ProjectDom dom = ProjectDomService.GetProjectDom (project);
202
ParsedDocument parsedDocument = ProjectDomService.GetParsedDocument (dom, doc.FileName);
203
if (parsedDocument == null)
204
parsedDocument = ProjectDomService.ParseFile (dom, doc.FileName ?? "a.cs", delegate { return doc.Text; });
205
if (parsedDocument != null) {
206
foreach (PreProcessorDefine define in parsedDocument.Defines) {
207
symbols.Add (define.Define);
196
212
public override object VisitIdentifierExpression (ICSharpCode.NRefactory.Ast.IdentifierExpression identifierExpression, object data)
238
254
base.ScanSpan (ref i);
241
if (i + 5 < doc.Length && doc.GetTextAt (i, 5) == "#else" && spanStack.Any (span => span is IfBlockSpan)) {
257
if (i + 5 < doc.Length && doc.GetTextAt (i, 5) == "#else") {
258
LineSegment line = doc.GetLineByOffset (i);
242
260
bool previousResult = false;
243
262
foreach (Span span in spanStack.ToArray ().Reverse ()) {
244
263
if (span is IfBlockSpan) {
245
264
previousResult = ((IfBlockSpan)span).IsValid;
252
LineSegment line = doc.GetLineByOffset (i);
253
272
int length = line.Offset + line.EditableLength - i;
254
273
while (spanStack.Count > 0 && !(CurSpan is IfBlockSpan)) {
255
274
spanStack.Pop ();
257
276
// IfBlockSpan ifBlock = (IfBlockSpan)CurSpan;
259
277
ElseBlockSpan elseBlockSpan = new ElseBlockSpan (!previousResult);
260
278
OnFoundSpanBegin (elseBlockSpan, i, 0);
277
296
ICSharpCode.NRefactory.Ast.Expression expr = lexer.PPExpression ();
278
297
bool result = false;
279
298
if (expr != null && !expr.IsNull) {
280
object o = expr.AcceptVisitor (new ConditinalExpressionEvaluator (), null);
299
object o = expr.AcceptVisitor (new ConditinalExpressionEvaluator (doc), null);
282
301
result = (bool)o;
296
315
ICSharpCode.NRefactory.Parser.CSharp.Lexer lexer = new ICSharpCode.NRefactory.Parser.CSharp.Lexer (new System.IO.StringReader (parameter));
297
316
ICSharpCode.NRefactory.Ast.Expression expr = lexer.PPExpression ();
299
bool result = !expr.IsNull ? (bool)expr.AcceptVisitor (new ConditinalExpressionEvaluator (), null) : false;
318
bool result = !expr.IsNull ? (bool)expr.AcceptVisitor (new ConditinalExpressionEvaluator (doc), null) : false;
302
321
bool previousResult = false;