/// <include file='Doc/Nodes.xml' path='doc/method[@name="Statement.Analyze"]/*'/> internal override Statement/*!*/ Analyze(Analyzer/*!*/ analyzer) { if (analyzer.IsThisCodeUnreachable()) { analyzer.ReportUnreachableCode(position); return EmptyStmt.Unreachable; } Evaluation cond_eval = condExpr.Analyze(analyzer, ExInfoFromParent.DefaultExInfo); if (cond_eval.HasValue) { if (Convert.ObjectToBoolean(cond_eval.Value)) { // unbounded loop: condExpr = null; } else { // unreachable body: if (type == Type.While) { body.ReportUnreachable(analyzer); return EmptyStmt.Unreachable; } } } condExpr = cond_eval.Literalize(); analyzer.EnterLoopBody(); body = body.Analyze(analyzer); analyzer.LeaveLoopBody(); return this; }
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Statement.Analyze"]/*'/> internal override Statement/*!*/ Analyze(Analyzer/*!*/ analyzer) { if (analyzer.IsThisCodeUnreachable()) { analyzer.ReportUnreachableCode(position); return EmptyStmt.Unreachable; } ExInfoFromParent info = ExInfoFromParent.DefaultExInfo; Statement result = this; bool is_first = true; int remaining = conditions.Count; int last_non_null = -1; for (int i = 0; i < conditions.Count; i++) { // "else": if (conditions[i].Condition == null) { Debug.Assert(i > 0); if (!is_first) analyzer.EnterConditionalCode(); conditions[i].Statement = conditions[i].Statement.Analyze(analyzer); if (!is_first) analyzer.LeaveConditionalCode(); last_non_null = i; break; } // all but the condition before the first non-evaluable including are conditional: if (!is_first) analyzer.EnterConditionalCode(); Evaluation cond_eval = conditions[i].Condition.Analyze(analyzer, info); if (!is_first) analyzer.LeaveConditionalCode(); if (cond_eval.HasValue) { if (Convert.ObjectToBoolean(cond_eval.Value)) { // condition is evaluated to be true // // analyze the first statement unconditionally, the the others conditionally: if (!is_first) analyzer.EnterConditionalCode(); conditions[i].Statement = conditions[i].Statement.Analyze(analyzer); if (!is_first) analyzer.LeaveConditionalCode(); // the remaining conditions are unreachable: for (int j = i + 1; j < conditions.Count; j++) { conditions[j].Statement.ReportUnreachable(analyzer); conditions[j] = null; remaining--; } conditions[i].Condition = null; last_non_null = i; break; } else { // condition is evaluated to be false // // remove the condition, report unreachable code: conditions[i].Statement.ReportUnreachable(analyzer); conditions[i] = null; remaining--; } } else { // condition is not evaluable: conditions[i].Condition = cond_eval.Expression; // analyze statement conditinally: analyzer.EnterConditionalCode(); conditions[i].Statement = conditions[i].Statement.Analyze(analyzer); analyzer.LeaveConditionalCode(); is_first = false; last_non_null = i; } } if (remaining == 0) return EmptyStmt.Skipped; Debug.Assert(last_non_null != -1 && conditions[last_non_null] != null); // only "else" remained: if (remaining == 1 && conditions[last_non_null].Condition == null) return conditions[last_non_null].Statement; // compact the list (remove nulls): if (remaining < conditions.Count) { List<ConditionalStmt> compacted = new List<ConditionalStmt>(remaining); foreach (ConditionalStmt condition in conditions) { if (condition != null) compacted.Add(condition); } conditions = compacted; } return this; }
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Statement.Analyze"]/*'/> internal override Statement/*!*/ Analyze(Analyzer/*!*/ analyzer) { if (analyzer.IsThisCodeUnreachable()) { analyzer.ReportUnreachableCode(position); return EmptyStmt.Unreachable; } //next version: array.SetSeqPoint(); enumeree.Analyze(analyzer, ExInfoFromParent.DefaultExInfo); if (keyVariable != null) keyVariable.Analyze(analyzer); valueVariable.Analyze(analyzer); analyzer.EnterLoopBody(); body = body.Analyze(analyzer); analyzer.LeaveLoopBody(); return this; }
/// <include file='Doc/Nodes.xml' path='doc/method[@name="Statement.Analyze"]/*'/> internal override Statement Analyze(Analyzer analyzer) { if (analyzer.IsThisCodeUnreachable()) { analyzer.ReportUnreachableCode(position); return EmptyStmt.Unreachable; } ExInfoFromParent info = new ExInfoFromParent(this); info.Access = AccessType.None; for (int i = 0; i < initExList.Count; i++) { initExList[i] = initExList[i].Analyze(analyzer, info).Literalize(); } if (condExList.Count > 0) { // all but the last expression is evaluated and the result is ignored (AccessType.None), // the last is read: for (int i = 0; i < condExList.Count - 1; i++) { condExList[i] = condExList[i].Analyze(analyzer, info).Literalize(); } condExList[condExList.Count - 1] = condExList[condExList.Count - 1].Analyze(analyzer, ExInfoFromParent.DefaultExInfo).Literalize(); } for (int i = 0; i < actionExList.Count; i++) { actionExList[i] = actionExList[i].Analyze(analyzer, info).Literalize(); } analyzer.EnterLoopBody(); body = body.Analyze(analyzer); analyzer.LeaveLoopBody(); return this; }
internal void Analyze(Analyzer/*!*/ analyzer) { analyzer.LeaveUnreachableCode(); ExInfoFromParent info = new ExInfoFromParent(this); // analyze auto-prepended inclusion (no code reachability checks): if (prependedInclusion != null) { info.Access = AccessType.None; prependedInclusion.Analyze(analyzer, info); } for (int i = 0; i < statements.Count; i++) { if (analyzer.IsThisCodeUnreachable() && statements[i].IsDeclaration) { //unreachable declarations in global code are valid analyzer.LeaveUnreachableCode(); statements[i] = statements[i].Analyze(analyzer); analyzer.EnterUnreachableCode(); } else { statements[i] = statements[i].Analyze(analyzer); } } if (!sourceUnit.CompilationUnit.IsPure) Analyzer.ValidateLabels(analyzer.ErrorSink, sourceUnit, labels); // analyze auto-prepended inclusion (no code reachability checks): if (appendedInclusion != null) { info.Access = AccessType.Read; appendedInclusion.Analyze(analyzer, info); } analyzer.LeaveUnreachableCode(); }
internal override Statement/*!*/ Analyze(Analyzer/*!*/ analyzer) { attributes.AnalyzeMembers(analyzer, analyzer.CurrentScope); attributes.Analyze(analyzer, this); bool is_unreachable = analyzer.IsThisCodeUnreachable(); foreach (GlobalConstantDecl cd in constants) { cd.GlobalConstant.Declaration.IsUnreachable = is_unreachable; // cd.Constant.CustomAttributes = attributes; cd.Analyze(analyzer); } if (is_unreachable) { analyzer.ReportUnreachableCode(position); return EmptyStmt.Unreachable; } else { return this; } }