예제 #1
0
파일: codegen.cs 프로젝트: shugo/babel
 public override void VisitTypecase(TypecaseStatement typecase)
 {
     Label endLabel = ilGenerator.DefineLabel();
     foreach (TypecaseWhen when in typecase.WhenPartList) {
         Label nextLabel = ilGenerator.DefineLabel();
         typecase.Variable.Accept(this);
         ilGenerator.Emit(OpCodes.Isinst, when.TypeSpecifier.RawType);
         ilGenerator.Emit(OpCodes.Brfalse, nextLabel);
         when.LocalVariable.Declare(ilGenerator);
         when.LocalVariable.EmitStorePrefix(ilGenerator);
         typecase.Variable.Accept(this);
         TypeData varType = typecase.Variable.NodeType;
         TypeData whenType = when.TypeSpecifier.NodeType;
         if (!varType.IsSubtypeOf(whenType)) {
             UnboxIfNecessary(varType.RawType, whenType.RawType);
         }
         when.LocalVariable.EmitStore(ilGenerator);
         when.ThenPart.Accept(this);
         ilGenerator.Emit(OpCodes.Br, endLabel);
         ilGenerator.MarkLabel(nextLabel);
     }
     if (typecase.ElsePart != null)
         typecase.ElsePart.Accept(this);
     ilGenerator.MarkLabel(endLabel);
 }
예제 #2
0
파일: typecheck.cs 프로젝트: shugo/babel
 public override void VisitTypecase(TypecaseStatement typecase)
 {
     typecase.Variable.Accept(this);
     if (typecase.Variable.NodeType == null)
         return;
     if (typecase.Variable.Call != null) {
         report.Error(typecase.Variable.Location,
                      "typecase variable must be a local variable " +
                      "or an argument");
         return;
     }
     TypeData varType = typecase.Variable.NodeType;
     foreach (TypecaseWhen when in typecase.WhenPartList) {
         when.TypeSpecifier.Accept(this);
         if (when.TypeSpecifier.NodeType == null)
             continue;
         TypeData localType;
         if (varType.IsSubtypeOf(when.TypeSpecifier.NodeType)) {
             localType = typecase.Variable.NodeType;
         }
         else {
             localType = when.TypeSpecifier.NodeType;
         }
         when.LocalVariable =
             localVariableStack.CreateLocal(typecase.Variable.Name,
                                            localType,
                                            true);
         when.ThenPart.LocalVariables.Add(typecase.Variable.Name,
                                          when.LocalVariable);
         when.ThenPart.Accept(this);
     }
     if (typecase.ElsePart != null)
         typecase.ElsePart.Accept(this);
 }
예제 #3
0
파일: node.cs 프로젝트: shugo/babel
 public virtual void VisitTypecase(TypecaseStatement typecase)
 {
 }