Ejemplo n.º 1
0
 public override void OnCodeAnalysis(CodeAnalysisArgs args)
 {
     switch (args.Phase) {
     case CodeAnalysisPhase.Allocate:
       if (IsSet(AstNodeFlags.AllocateSlot) && !Scope.SlotDefined(Name))
     Slot = Scope.CreateSlot(Name);
       break;
     case CodeAnalysisPhase.Binding:
       Slot = Scope.FindSlot(Name);
       if (Slot == null && !IsSet(AstNodeFlags.SuppressNotDefined))
     args.Context.ReportError(this.Location, "Variable " + Name + " is not declared");
       if (Slot != null) {
     //unless suppressed, mark this ID use as RValue
     if (!IsSet(AstNodeFlags.NotRValue))
       Slot.Flags |= SlotFlags.UsedAsRValue;
     if (IsSet(AstNodeFlags.IsLValue))
       Slot.Flags |= SlotFlags.ExplicitlyAssigned;
       }
       SetupEvaluateMethod();
       break;
       }//switch
       base.OnCodeAnalysis(args);
 }
Ejemplo n.º 2
0
        private void RunAnalysisPhases(AstNode astRoot, CompilerContext context, params CodeAnalysisPhase[] phases)
        {
            CodeAnalysisArgs args = new CodeAnalysisArgs(context);
              foreach (CodeAnalysisPhase phase in phases) {
            switch (phase) {
              case CodeAnalysisPhase.AssignScopes:
            astRoot.Scope = new Scope(astRoot, null);
            break;

              case CodeAnalysisPhase.MarkTailCalls:
            if (!Grammar.FlagIsSet(LanguageFlags.TailRecursive)) continue;//foreach loop - don't run the phase
            astRoot.Flags |= AstNodeFlags.IsTail;
            break;
            }//switch
            args.Phase = phase;
            astRoot.OnCodeAnalysis(args);
              }//foreach phase
        }