The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGRelationalOperation.cs
Go to the documentation of this file.
1 using CodeGeneration.Operations;
2 using TypeSystem;
3 using AST;
4 
5 namespace CodeGeneration.NewOperations
6 {
7 
8  internal class CGRelationalOperation<T> : NewOperations.CGBinaryOperation<T> where T : ILCodeGenerator
9  {
10 
11  public CGRelationalOperation(VisitorILCodeGeneration<T> visitor, object obj, int indent, RelationalExpression node) : base(visitor, obj, indent, node) { }
12 
13 
14  protected override UnionType GenerateAllUnionTypes()
15  {
16 
17  UnionType unions = new UnionType();
18  if (!(node.FirstOperand.ExpressionType is NullType) && !(node.SecondOperand.ExpressionType is NullType))
19  {
20  unions.AddType(IntType.Instance);
21  unions.AddType(DoubleType.Instance);
22  unions.AddType(CharType.Instance);
23  }
24  return unions;
25  }
26 
27  protected override TypeExpression MajorType(TypeExpression typeExpression1, TypeExpression typeExpression2)
28  {
29  return null;
30  }
31 
32  protected override void GenerateOperator(BinaryExpression node, TypeExpression result)
33  {
34  RelationalOperator relationalOperator = ((RelationalExpression)node).Operator;
35  switch (relationalOperator)
36  {
37  case RelationalOperator.NotEqual:
38  this.codeGenerator.ceq(this.indent);
39  this.codeGenerator.ldc(this.indent, false);
40  this.codeGenerator.ceq(this.indent);
41  break;
42  case RelationalOperator.Equal:
43  this.codeGenerator.ceq(this.indent);
44  break;
45  case RelationalOperator.LessThan:
46  this.codeGenerator.clt(this.indent);
47  break;
48  case RelationalOperator.GreaterThan:
49  this.codeGenerator.cgt(this.indent);
50  break;
51  case RelationalOperator.LessThanOrEqual:
52  this.codeGenerator.cgt(this.indent);
53  this.codeGenerator.ldc(this.indent, false);
54  this.codeGenerator.ceq(this.indent);
55  break;
56  case RelationalOperator.GreaterThanOrEqual:
57  this.codeGenerator.clt(this.indent);
58  this.codeGenerator.ldc(this.indent, false);
59  this.codeGenerator.ceq(this.indent);
60  break;
61  default: // Error
62  this.codeGenerator.Comment("ERROR");
63  break;
64  }
65 
66  // if (!IsValueType(node.ExpressionType) && !(node.ExpressionType is StringType))
67  // this.codeGenerator.Box(indent, BoolType.Instance);
68  }
69  }
70 }
Encapsulates a binary expression of our programming language.
Representa a union type.
Definition: UnionType.cs:36
Abstract class that represents all different types.
RelationalOperator
Relational binary operators
Encapsulates a relational binary expression.
Represent a null type.
Definition: NullType.cs:36