author | Edouard Tisserant |
Mon, 04 Apr 2011 17:13:03 +0200 | |
changeset 271 | 4f281513277f |
parent 265 | 4d222f46f8cc |
child 279 | c0453b7f99df |
permissions | -rwxr-xr-x |
181 | 1 |
/* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
2 |
* matiec - a compiler for the programming languages defined in IEC 61131-3 |
181 | 3 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
4 |
* Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
181 | 5 |
* |
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
6 |
* This program is free software: you can redistribute it and/or modify |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
7 |
* it under the terms of the GNU General Public License as published by |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
8 |
* the Free Software Foundation, either version 3 of the License, or |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
9 |
* (at your option) any later version. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
10 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
11 |
* This program is distributed in the hope that it will be useful, |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
14 |
* GNU General Public License for more details. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
15 |
* |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
18 |
* |
181 | 19 |
* |
20 |
* This code is made available on the understanding that it will not be |
|
21 |
* used in safety-critical situations without a full and competent review. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
265
4d222f46f8cc
Updating license info (with Edouard's permission for relevant files).
Mario de Sousa <msousa@fe.up.pt>
parents:
202
diff
changeset
|
25 |
* An IEC 61131-3 compiler. |
181 | 26 |
* |
27 |
* Based on the |
|
28 |
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
29 |
* |
|
30 |
*/ |
|
31 |
||
32 |
/* Determine the data type of an ST expression. |
|
33 |
* A reference to the relevant type definition is returned. |
|
34 |
* |
|
35 |
* For example: |
|
36 |
* 2 + 3 -> returns reference to a int_type_name_c object. |
|
37 |
* 22.2 - 5 -> returns reference to a real_type_name_c object. |
|
38 |
* etc... |
|
39 |
*/ |
|
40 |
||
41 |
class search_expression_type_c: public search_constant_type_c { |
|
42 |
||
43 |
private: |
|
44 |
search_varfb_instance_type_c *search_varfb_instance_type; |
|
45 |
search_base_type_c search_base_type; |
|
46 |
||
47 |
||
48 |
public: |
|
49 |
search_expression_type_c(symbol_c *search_scope); |
|
50 |
virtual ~search_expression_type_c(void); |
|
51 |
||
52 |
/* A helper function... */ |
|
53 |
bool is_bool_type(symbol_c *type_symbol); |
|
54 |
bool is_time_type(symbol_c *type_symbol); |
|
55 |
bool is_string_type(symbol_c *type_symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
56 |
bool is_literal_integer_type(symbol_c *type_symbol); |
181 | 57 |
bool is_integer_type(symbol_c *type_symbol); |
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
58 |
bool is_literal_real_type(symbol_c *type_symbol); |
181 | 59 |
bool is_real_type(symbol_c *type_symbol); |
60 |
bool is_num_type(symbol_c *type_symbol); |
|
61 |
bool is_nbinary_type(symbol_c *type_symbol); |
|
62 |
bool is_binary_type(symbol_c *type_symbol); |
|
63 |
||
64 |
bool is_same_type(symbol_c *first_type, symbol_c *second_type); |
|
65 |
symbol_c* common_type(symbol_c *first_type, symbol_c *second_type); |
|
66 |
||
67 |
/* |
|
68 |
#include "search_type_code.c" |
|
69 |
*/ |
|
70 |
void *compute_standard_function_default(function_invocation_c *st_symbol, il_formal_funct_call_c *il_symbol); |
|
71 |
void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type); |
|
72 |
||
73 |
||
74 |
||
75 |
/*static bool_type_name_c bool_type_name;*/ |
|
76 |
||
77 |
/* A helper function... */ |
|
78 |
void *compute_boolean_expression(symbol_c *left_type, symbol_c *right_type); |
|
79 |
||
80 |
/* A helper function... */ |
|
81 |
void *compute_numeric_expression(symbol_c *left_type, symbol_c *right_type); |
|
82 |
||
83 |
/* a helper function... */ |
|
84 |
symbol_c *base_type(symbol_c *symbol); |
|
85 |
||
86 |
/*********************/ |
|
87 |
/* B 1.4 - Variables */ |
|
88 |
/*********************/ |
|
89 |
||
90 |
void *visit(symbolic_variable_c *symbol); |
|
91 |
||
92 |
/********************************************/ |
|
93 |
/* B 1.4.1 - Directly Represented Variables */ |
|
94 |
/********************************************/ |
|
95 |
void *visit(direct_variable_c *symbol); |
|
96 |
||
97 |
/*************************************/ |
|
98 |
/* B 1.4.2 - Multi-element variables */ |
|
99 |
/*************************************/ |
|
100 |
||
101 |
void *visit(array_variable_c *symbol); |
|
102 |
void *visit(structured_variable_c *symbol); |
|
103 |
||
104 |
/***************************************/ |
|
105 |
/* B.3 - Language ST (Structured Text) */ |
|
106 |
/***************************************/ |
|
107 |
/***********************/ |
|
108 |
/* B 3.1 - Expressions */ |
|
109 |
/***********************/ |
|
110 |
void *visit(or_expression_c *symbol); |
|
111 |
void *visit(xor_expression_c *symbol); |
|
112 |
void *visit(and_expression_c *symbol); |
|
113 |
void *visit(equ_expression_c *symbol); |
|
114 |
void *visit(notequ_expression_c *symbol); |
|
115 |
void *visit(lt_expression_c *symbol); |
|
116 |
void *visit(gt_expression_c *symbol); |
|
117 |
void *visit(le_expression_c *symbol); |
|
118 |
void *visit(ge_expression_c *symbol); |
|
119 |
||
120 |
void *visit(add_expression_c *symbol); |
|
121 |
void *visit(sub_expression_c *symbol); |
|
122 |
void *visit(mul_expression_c *symbol); |
|
123 |
void *visit(div_expression_c *symbol); |
|
124 |
void *visit(mod_expression_c *symbol); |
|
125 |
void *visit(power_expression_c *symbol); |
|
126 |
void *visit(neg_expression_c *symbol); |
|
127 |
void *visit(not_expression_c *symbol); |
|
128 |
void *visit(function_invocation_c *symbol); |
|
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
129 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
130 |
|
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
131 |
static integer_c integer; |
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
132 |
|
181 | 133 |
}; // search_expression_type_c |
134 |
||
135 |
||
202
da1a8186f86f
Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents:
181
diff
changeset
|
136 |