stage3/stage3.cc
author Mario de Sousa <msousa@fe.up.pt>
Mon, 06 Feb 2012 18:32:11 +0000
changeset 430 d7a6221f64d7
parent 417 d48f53715f77
child 443 ff4d26b7e51d
permissions -rwxr-xr-x
More detailed error messages in function invocations in ST.
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
 *
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
     4
 *  Copyright (C) 2009-2012  Mario de Sousa (msousa@fe.up.pt)
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 267
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
     6
 *  Copyright (C) 2012       Manuele Conti (manuele.conti@sirius-es.it)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
     7
 *  Copyright (C) 2012       Matteo Facchinetti (matteo.facchinetti@sirius-es.it)
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     8
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
     9
 *  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
    10
 *  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
    11
 *  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
    12
 *  (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
    13
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    14
 *  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
    15
 *  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
    16
 *  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
    17
 *  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
    18
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
    19
 *  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
    20
 *  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
    21
 *
204
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
 * 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
    24
 * 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
    25
 */
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
/*
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
 * An IEC 61131-3 compiler.
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
 * 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
    31
 * 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
    32
 *
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
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    35
#include "stage3.hh"
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    36
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    37
#include "fill_candidate_datatypes.hh"
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    38
#include "narrow_candidate_datatypes.hh"
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    39
#include "print_datatypes_error.hh"
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    40
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    41
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    42
int type_safety(symbol_c *tree_root){
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    43
	fill_candidate_datatypes_c fill_candidate_datatypes(tree_root);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    44
	tree_root->accept(fill_candidate_datatypes);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    45
	narrow_candidate_datatypes_c narrow_candidate_datatypes(tree_root);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    46
	tree_root->accept(narrow_candidate_datatypes);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    47
	print_datatypes_error_c print_datatypes_error(tree_root);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    48
	tree_root->accept(print_datatypes_error);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    49
	if (print_datatypes_error.get_error_found())
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    50
		return -1;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    51
	return 0;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    52
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    53
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    54
int stage3(symbol_c *tree_root){
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    55
	return type_safety(tree_root);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    56
}