stage3/stage3.cc
author Mario de Sousa <msousa@fe.up.pt>
Mon, 04 Apr 2011 15:59:35 +0100
changeset 277 f88718b71b6c
parent 267 0a1204bcc9af
child 279 c0453b7f99df
permissions -rwxr-xr-x
Changing to LGPL for library functions.
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     1
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     3
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     4
 *  Copyright (C) 2009-2011  Mario de Sousa (msousa@fe.up.pt)
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     5
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     9
 *  (at your option) any later version.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    10
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    14
 *  GNU General Public License for more details.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    15
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    18
 *
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    19
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    22
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    23
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    24
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    25
 * An IEC 61131-3 compiler.
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    26
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    27
 * Based on the
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    29
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    30
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    31
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    32
#include "stage3.hh"
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    33
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    34
int type_safety(symbol_c *tree_root){
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    35
	visit_expression_type_c visit_expression_type(tree_root);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    36
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    37
	(*tree_root).accept(visit_expression_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    38
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    39
	if (visit_expression_type.get_error_found())
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    40
	  return -1;
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    41
	
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    42
	return 0;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    43
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    44
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    45
int stage3(symbol_c *tree_root){
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    46
	return type_safety(tree_root);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    47
}