source: liacs/coco/assignment4/IOperand.h@ 318

Last change on this file since 318 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 2.8 KB
RevLine 
[2]1/*
2 * IOperand.h - Declaration of the IOperand abstract data structure
3 *
4 * Part of the assignment of the Compiler Construction course
5 * LIACS, Leiden University
6 *
7 * This file provides three different objects:
8 * - IOperand_Int
9 * - IOperand_Real
10 * - IOperand_Symbol
11 * You can instantiate these objects using a constructor, for example:
12 * IOperand * myOperand = new IOperand_Int(42);
13 * This creates an IOperand_Int object containing the value 42.
14 *
15 * Note that deleting an IOperand_Symbol does not lead to a deletion of its
16 * Symbol object.
17 */
18
19#ifndef _IOPERAND_H_
20#define _IOPERAND_H_
21
22#include "Symbol.h"
23
24// The type of an operand
25typedef enum __ioperandtype {
26 OT_UNKNOWN, // Unknown (yet)
27 OT_INT, // Integer immediate
28 OT_REAL, // Real immediate
29 OT_SYMBOL // Symbol object
30} IOperandType;
31
32
33
34// Operand of an IStatement
35class IOperand {
36 public:
37 // Constructor/destructor
38 IOperand();
39 virtual ~IOperand();
40 virtual IOperand * Clone() =0;
41
42 // Get operand type
43 IOperandType GetOperandType();
44
45 // Set operand type
46 void SetOperandType(IOperandType type);
47
48 // Empty virtuals
49 virtual int GetIntValue();
50 virtual void SetIntValue(int newvalue);
51 virtual float GetRealValue();
52 virtual void SetRealValue(float newvalue);
53 virtual Symbol *GetSymbol();
54 virtual void SetSymbol(Symbol *sym);
55
56 // Dump
57 virtual void Dump(FILE *file) =0;
58
59 private:
60 IOperandType optype;
61};
62
63
64// Integer operand
65class IOperand_Int: public IOperand {
66 public:
67 // Constructor/destructor
68 IOperand_Int();
69 IOperand_Int(int newvalue);
70 ~IOperand_Int();
71
72 // Clone
73 virtual IOperand_Int * Clone();
74
75 // Get the integer value
76 int GetIntValue();
77
78 // Set the integer value
79 void SetIntValue(int newvalue);
80
81 // Dump
82 void Dump(FILE *file);
83
84 private:
85 int value;
86};
87
88
89// Real operand
90class IOperand_Real: public IOperand {
91 public:
92 // Constructor/destructor
93 IOperand_Real();
94 IOperand_Real(float newvalue);
95 ~IOperand_Real();
96
97 // Clone
98 virtual IOperand_Real * Clone();
99
100 // Get the float value
101 float GetRealValue();
102
103 // Set the float value
104 void SetRealValue(float newvalue);
105
106 // Dump
107 void Dump(FILE *file);
108
109 private:
110 float value;
111};
112
113
114// Symbol operand
115class IOperand_Symbol: public IOperand {
116 public:
117 // Constructor/destructor
118 IOperand_Symbol();
119 IOperand_Symbol(Symbol * newsym);
120 ~IOperand_Symbol();
121
122 // Clone
123 virtual IOperand_Symbol * Clone();
124
125 // Get the Symbol object
126 Symbol *GetSymbol();
127
128 // Set the Symbol object
129 void SetSymbol(Symbol *sym);
130
131 // Dump
132 void Dump(FILE *file);
133
134 private:
135 Symbol *symbol;
136};
137
138
139#endif
Note: See TracBrowser for help on using the repository browser.