The StaDyn Programming Language
Source code documentation of StaDyn, a hybrid static and dynamic typing language.
CGBitwiseOperation.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 CGBitwiseOperation<T> : NewOperations.CGBinaryOperation<T> where T : ILCodeGenerator
9  {
10 
11  public CGBitwiseOperation(VisitorILCodeGeneration<T> visitor, object obj, int indent, BitwiseExpression node) : base(visitor, obj, indent, node) { }
12 
13 
14  protected override UnionType GenerateAllUnionTypes()
15  {
16  UnionType unions = new UnionType();
17  unions.AddType(IntType.Instance);
18  return unions;
19  }
20 
21  protected override TypeExpression MajorType(TypeExpression typeExpression1, TypeExpression typeExpression2)
22  {
23  return typeExpression1;
24  }
25 
26  protected override void GenerateOperator(BinaryExpression node, TypeExpression result)
27  {
28  BitwiseOperator bitwiseOperator = ((BitwiseExpression)node).Operator;
29  switch (bitwiseOperator)
30  {
31  case BitwiseOperator.BitwiseOr:
32  this.codeGenerator.or(this.indent);
33  break;
34  case BitwiseOperator.BitwiseAnd:
35  this.codeGenerator.and(this.indent);
36  break;
37  case BitwiseOperator.BitwiseXOr:
38  this.codeGenerator.xor(this.indent);
39  break;
40  case BitwiseOperator.ShiftLeft:
41  this.codeGenerator.shl(this.indent);
42  break;
43  case BitwiseOperator.ShiftRight:
44  this.codeGenerator.shr(this.indent);
45  break;
46  default:
47  break;
48  }
49 
50  if (!IsValueType(node.ExpressionType))
51  this.codeGenerator.Box(indent, IntType.Instance);
52  }
53  }
54 }
Encapsulates a binary expression of our programming language.
Representa a union type.
Definition: UnionType.cs:36
TypeExpression ExpressionType
Gets or sets the type of the expression.
Definition: Expression.cs:71
Abstract class that represents all different types.
Represent a integer type.
Definition: IntType.cs:37
Encapsulates a bitwise binary expression.
static IntType Instance
Gets the unique instance of IntType
Definition: IntType.cs:57
BitwiseOperator
Bitwise binary operators