The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CheckMakeAnUnboxOperation.cs
Go to the documentation of this file.
1 using AST;
2 using ErrorManagement;
3 using System;
4 
5 namespace AST.Operations {
13  internal class CheckMakeAnUnboxOperation : AstOperation {
14 
15  private TypeSystem.MethodType methodType;
16 
17  public CheckMakeAnUnboxOperation() {
18  this.methodType = null;
19  }
20 
21  public override object Exec(BaseCallExpression b, object arg) {
22  this.CheckActualMethodCalled(b);
23  return this.ReturnValue(b);
24  }
31  public override object Exec(Expression node, object arg) {
32  return this.ReturnValue(node);
33  }
34 
35  private bool ReturnValue(Expression expression) {
36  if (this.methodType != null)
37  return !(this.methodType.Return.IsValueType());
38 
39  TypeSystem.FieldType field = expression.ExpressionType as TypeSystem.FieldType;
40 
41  if (field != null)
42  return (field.FieldTypeExpression is TypeSystem.TypeVariable);
43 
44  return false;
45 
46  }
47 
48  protected void CheckActualMethodCalled(BaseCallExpression bc) {
49  this.methodType = bc.ActualMethodCalled as TypeSystem.MethodType;
50  if (this.methodType == null) { // ActualMethodCalled is a TypeVariable or UnionType
51  TypeSystem.TypeVariable typeVariable = bc.ActualMethodCalled as TypeSystem.TypeVariable;
52  if (typeVariable != null)
53  this.methodType = typeVariable.Substitution as TypeSystem.MethodType;
54  }
55  }
56 
57  }
58 }
Abstract class encapsulate a programming language expression.
Definition: Expression.cs:37
Represents a generic type expression
Definition: TypeVariable.cs:36
Representa a method type.
Definition: MethodType.cs:37
Representa a field type.
Definition: FieldType.cs:37
Encapsulates a invocation expression to base class.