Start enumerate conversion functions.
--- a/absyntax_utils/Makefile.in Thu Nov 15 14:14:00 2012 +0000
+++ b/absyntax_utils/Makefile.in Thu Nov 15 17:30:35 2012 +0100
@@ -93,9 +93,7 @@
search_varfb_instance_type.$(OBJEXT) \
search_var_instance_decl.$(OBJEXT) \
spec_init_separator.$(OBJEXT) type_initial_value.$(OBJEXT) \
- debug_ast.$(OBJEXT) \
- get_datatype_info.$(OBJEXT)
-
+ debug_ast.$(OBJEXT) get_datatype_info.$(OBJEXT)
libabsyntax_utils_a_OBJECTS = $(am_libabsyntax_utils_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/config
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -236,7 +234,6 @@
debug_ast.cc \
get_datatype_info.cc
-
all: all-am
.SUFFIXES:
--- a/stage1_2/Makefile.am Thu Nov 15 14:14:00 2012 +0000
+++ b/stage1_2/Makefile.am Thu Nov 15 17:30:35 2012 +0100
@@ -16,6 +16,7 @@
libstage1_2_a_SOURCES = \
iec_flex.ll \
iec_bison.yy \
+ derived_conversion_functions.cc \
stage1_2.cc
libstage1_2_a_CPPFLAGS = -DDEFAULT_LIBDIR='"lib"' -I../../absyntax
--- a/stage1_2/Makefile.in Thu Nov 15 14:14:00 2012 +0000
+++ b/stage1_2/Makefile.in Thu Nov 15 17:30:35 2012 +0100
@@ -78,6 +78,7 @@
libstage1_2_a_LIBADD =
am_libstage1_2_a_OBJECTS = libstage1_2_a-iec_flex.$(OBJEXT) \
libstage1_2_a-iec_bison.$(OBJEXT) \
+ libstage1_2_a-derived_conversion_functions.$(OBJEXT) \
libstage1_2_a-stage1_2.$(OBJEXT)
libstage1_2_a_OBJECTS = $(am_libstage1_2_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/config
@@ -214,6 +215,7 @@
libstage1_2_a_SOURCES = \
iec_flex.ll \
iec_bison.yy \
+ derived_conversion_functions.cc \
stage1_2.cc
libstage1_2_a_CPPFLAGS = -DDEFAULT_LIBDIR='"lib"' -I../../absyntax
@@ -297,6 +299,7 @@
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstage1_2_a-derived_conversion_functions.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstage1_2_a-iec_bison.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstage1_2_a-iec_flex.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstage1_2_a-stage1_2.Po@am__quote@
@@ -343,6 +346,20 @@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstage1_2_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libstage1_2_a-iec_bison.obj `if test -f 'iec_bison.cc'; then $(CYGPATH_W) 'iec_bison.cc'; else $(CYGPATH_W) '$(srcdir)/iec_bison.cc'; fi`
+libstage1_2_a-derived_conversion_functions.o: derived_conversion_functions.cc
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstage1_2_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libstage1_2_a-derived_conversion_functions.o -MD -MP -MF $(DEPDIR)/libstage1_2_a-derived_conversion_functions.Tpo -c -o libstage1_2_a-derived_conversion_functions.o `test -f 'derived_conversion_functions.cc' || echo '$(srcdir)/'`derived_conversion_functions.cc
+@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libstage1_2_a-derived_conversion_functions.Tpo $(DEPDIR)/libstage1_2_a-derived_conversion_functions.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='derived_conversion_functions.cc' object='libstage1_2_a-derived_conversion_functions.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstage1_2_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libstage1_2_a-derived_conversion_functions.o `test -f 'derived_conversion_functions.cc' || echo '$(srcdir)/'`derived_conversion_functions.cc
+
+libstage1_2_a-derived_conversion_functions.obj: derived_conversion_functions.cc
+@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstage1_2_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libstage1_2_a-derived_conversion_functions.obj -MD -MP -MF $(DEPDIR)/libstage1_2_a-derived_conversion_functions.Tpo -c -o libstage1_2_a-derived_conversion_functions.obj `if test -f 'derived_conversion_functions.cc'; then $(CYGPATH_W) 'derived_conversion_functions.cc'; else $(CYGPATH_W) '$(srcdir)/derived_conversion_functions.cc'; fi`
+@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libstage1_2_a-derived_conversion_functions.Tpo $(DEPDIR)/libstage1_2_a-derived_conversion_functions.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='derived_conversion_functions.cc' object='libstage1_2_a-derived_conversion_functions.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstage1_2_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libstage1_2_a-derived_conversion_functions.obj `if test -f 'derived_conversion_functions.cc'; then $(CYGPATH_W) 'derived_conversion_functions.cc'; else $(CYGPATH_W) '$(srcdir)/derived_conversion_functions.cc'; fi`
+
libstage1_2_a-stage1_2.o: stage1_2.cc
@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstage1_2_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libstage1_2_a-stage1_2.o -MD -MP -MF $(DEPDIR)/libstage1_2_a-stage1_2.Tpo -c -o libstage1_2_a-stage1_2.o `test -f 'stage1_2.cc' || echo '$(srcdir)/'`stage1_2.cc
@am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/libstage1_2_a-stage1_2.Tpo $(DEPDIR)/libstage1_2_a-stage1_2.Po
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stage1_2/derived_conversion_functions.cc Thu Nov 15 17:30:35 2012 +0100
@@ -0,0 +1,200 @@
+/*
+ * matiec - a compiler for the programming languages defined in IEC 61131-3
+ *
+ * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt)
+ * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * This code is made available on the understanding that it will not be
+ * used in safety-critical situations without a full and competent review.
+ */
+
+/*
+ * An IEC 61131-3 compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ */
+
+
+#include "derived_conversion_functions.hh"
+#include <sstream>
+
+static const int debug = 0;
+
+derived_conversion_functions_c::derived_conversion_functions_c(symbol_c *ignore) {
+
+}
+
+derived_conversion_functions_c::~derived_conversion_functions_c(void) {
+
+}
+
+std::string &derived_conversion_functions_c::get_declaration(symbol_c *root) {
+ text = "";
+ if (NULL != root) {
+ root->accept(*this);
+ }
+
+ return text;
+}
+
+void *derived_conversion_functions_c::visit(identifier_c *symbol) {
+ currentToken = symbol->value;
+
+ return NULL;
+}
+
+void *derived_conversion_functions_c::visit(enumerated_type_declaration_c *symbol) {
+ std::string enumerateName;
+ std::string functionName;
+ std::list <std::string> enumerateValues;
+
+ symbol->enumerated_type_name->accept(*this);
+ enumerateName = currentToken;
+
+ symbol->enumerated_spec_init->accept(*this);
+ enumerateValues = currentTokenList;
+
+ printStringToEnum (enumerateName, enumerateValues);
+ printEnumToString (enumerateName, enumerateValues);
+ for (size_t s = 8; s <= 64; s*= 2) {
+ printIntegerToEnum (enumerateName, enumerateValues, true , s);
+ printEnumToInteger (enumerateName, enumerateValues, true , s);
+ printIntegerToEnum (enumerateName, enumerateValues, false, s);
+ printEnumToInteger (enumerateName, enumerateValues, false, s);
+ }
+ if (debug) std::cout << text << std::endl;
+
+ return NULL;
+}
+
+void *derived_conversion_functions_c::visit(enumerated_value_list_c *symbol) {
+ list_c *list;
+
+ currentTokenList.clear();
+ list = (list_c *)symbol;
+ for (int i = 0; i < list->n; i++) {
+ list->elements[i]->accept(*this);
+ currentTokenList.push_back(currentToken);
+ }
+
+ return NULL;
+}
+
+std::string derived_conversion_functions_c::getIntegerName(bool isSigned, size_t size) {
+ std::string integerType = "";
+ if (! isSigned) {
+ integerType = "U";
+ }
+ switch(size) {
+ case 8 : integerType += "S"; break;
+ case 16: break;
+ case 32: integerType += "D"; break;
+ case 64: integerType += "L"; break;
+ default: break;
+ }
+ integerType +="INT";
+
+ return integerType;
+}
+
+void derived_conversion_functions_c::printStringToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues) {
+ std::list <std::string>::const_iterator itr;
+ std::string functionName;
+
+ functionName = "STRING_TO_" + enumerateName;
+ text += "FUNCTION " + functionName + " : " + enumerateName;
+ text += "\nVAR_INPUT\nIN : STRING;\nEND_VAR\n";
+ for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
+ std::string value = *itr;
+ text += "IF IN = '" + value + "' THEN\n";
+ text += " " + functionName + " := " + value + ";\n";
+ text += " RETURN;\n";
+ text += "END_IF;\n";
+ }
+ text += "END_FUNCTION\n\n";
+}
+
+void derived_conversion_functions_c::printEnumToString (std::string &enumerateName, std::list<std::string> &enumerateValues) {
+ std::list <std::string>::const_iterator itr;
+ std::string functionName;
+
+ functionName = enumerateName + "_TO_STRING";
+ text += "FUNCTION " + functionName + " : STRING";
+ text += "\nVAR_INPUT\nIN : " + enumerateName + ";\nEND_VAR\n";
+ for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
+ std::string value = *itr;
+ text += "IF IN = " + value + " THEN\n";
+ text += " " + functionName + " := '" + value + "';\n";
+ text += " RETURN;\n";
+ text += "END_IF;\n";
+ }
+ text += "END_FUNCTION\n\n";
+}
+
+void derived_conversion_functions_c::printIntegerToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
+ std::list <std::string>::const_iterator itr;
+ std::string functionName;
+ std::string integerType;
+ int count;
+
+ integerType = getIntegerName(isSigned, size);
+ functionName = integerType + "_TO_" + enumerateName;
+ text += "FUNCTION " + functionName + " : " + enumerateName;
+ text += "\nVAR_INPUT\nIN : " + integerType + ";\nEND_VAR\n";
+ count = 0;
+ for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
+ std::string value = *itr;
+ std::stringstream out;
+ out << count;
+ text += "IF IN = " + out.str() + " THEN\n";
+ text += " " + functionName + " := " + value + ";\n";
+ text += " RETURN;\n";
+ text += "END_IF;\n";
+ count++;
+ }
+ text += "END_FUNCTION\n\n";
+}
+
+void derived_conversion_functions_c::printEnumToInteger (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size) {
+ std::list <std::string>::const_iterator itr;
+ std::string functionName;
+ std::string integerType;
+ int count;
+
+ integerType = getIntegerName(isSigned, size);
+ functionName = enumerateName + "_TO_" + integerType;
+ text += "FUNCTION " + functionName + " : " + integerType;
+ text += "\nVAR_INPUT\nIN : " + enumerateName + ";\nEND_VAR\n";
+ count = 0;
+ for (itr = enumerateValues.begin(); itr != enumerateValues.end(); ++itr) {
+ std::string value = *itr;
+ std::stringstream out;
+ out << count;
+ text += "IF IN = " + value + " THEN\n";
+ text += " " + functionName + " := " + out.str() + ";\n";
+ text += " RETURN;\n";
+ text += "END_IF;\n";
+ count++;
+ }
+ text += "END_FUNCTION\n\n";
+}
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stage1_2/derived_conversion_functions.hh Thu Nov 15 17:30:35 2012 +0100
@@ -0,0 +1,68 @@
+/*
+ * matiec - a compiler for the programming languages defined in IEC 61131-3
+ *
+ * Copyright (C) 2009-2012 Mario de Sousa (msousa@fe.up.pt)
+ * Copyright (C) 2012 Manuele Conti (conti.ma@alice.it)
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * This code is made available on the understanding that it will not be
+ * used in safety-critical situations without a full and competent review.
+ */
+
+/*
+ * An IEC 61131-3 compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ */
+
+#ifndef _DERIVED_CONVERSION_FUNCTIONS_H
+#define _DERIVED_CONVERSION_FUNCTIONS_H
+
+#include "../absyntax_utils/absyntax_utils.hh"
+#include <string>
+#include <list>
+
+class derived_conversion_functions_c: public iterator_visitor_c {
+ public:
+ explicit derived_conversion_functions_c(symbol_c *ignore);
+ virtual ~derived_conversion_functions_c(void);
+ std::string &get_declaration(symbol_c *root);
+
+ void *visit(identifier_c *symbol);
+ /**********************/
+ /* B 1.3 - Data types */
+ /**********************/
+ /********************************/
+ /* B 1.3.3 - Derived data types */
+ /********************************/
+ void *visit(enumerated_type_declaration_c *symbol);
+ void *visit(enumerated_value_list_c *symbol);
+
+ private:
+ std::string text;
+ std::string currentToken;
+ std::list< std::string> currentTokenList;
+ std::string getIntegerName(bool isSigned, size_t size);
+ void printStringToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues);
+ void printEnumToString (std::string &enumerateName, std::list<std::string> &enumerateValues);
+ void printIntegerToEnum (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size);
+ void printEnumToInteger (std::string &enumerateName, std::list<std::string> &enumerateValues, bool isSigned, size_t size);
+};
+
+#endif /* _DERIVED_CONVERSION_FUNCTIONS_H */
--- a/stage1_2/iec_bison.yy Thu Nov 15 14:14:00 2012 +0000
+++ b/stage1_2/iec_bison.yy Thu Nov 15 17:30:35 2012 +0100
@@ -233,6 +233,9 @@
const char *last_filename,
long int last_order,
const char *additional_error_msg);
+
+/* Create entry in symbol table for function conversion data type*/
+void make_derived_conversion_functions(const char * dname);
%}
@@ -2704,7 +2707,11 @@
* and include the library_element_symtable.insert(...) code in the rule actions!
*/
identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);}
- {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$));}
+ {
+ $$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$));
+ const char *name = ((identifier_c *)$1)->value;
+ make_derived_conversion_functions(name);
+ }
| identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value
{$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));}
/* ERROR_CHECK_BEGIN */
@@ -8340,5 +8347,105 @@
return 0;
}
-
-
+FILE *ftmpopen (void *buf, size_t size, const char *opentype)
+{
+ FILE *f;
+ f = tmpfile();
+ fwrite(buf, 1, size, f);
+ rewind(f);
+ return f;
+}
+
+
+int sstage2__(const char *text,
+ symbol_c **tree_root_ref,
+ bool full_token_loc_ /* error messages specify full token location */
+ ) {
+
+ FILE *in_file = NULL;
+
+ if((in_file = ftmpopen((void *)text, strlen(text), "r")) == NULL) {
+ perror("Error temp file.");
+ return -1;
+ }
+
+ /* now parse the input file... */
+ #if YYDEBUG
+ yydebug = 1;
+ #endif
+ yyin = in_file;
+ allow_function_overloading = true;
+ allow_extensible_function_parameters = false;
+ full_token_loc = full_token_loc_;
+ current_filename = "built-in";
+ current_tracking = GetNewTracking(yyin);
+ {int res;
+ if ((res = yyparse()) != 0) {
+ fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (yynerrs > 0) {
+ fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */);
+ exit(EXIT_FAILURE);
+ }
+
+ if (tree_root_ref != NULL)
+ *tree_root_ref = tree_root;
+
+ fclose(in_file);
+ return 0;
+}
+
+
+
+/* Create entry in symbol table for function conversion data type*/
+void make_derived_conversion_functions(const char * dname) {
+ std::string strname;
+ std::string tmp;
+
+ strname = dname;
+ tmp = strname + "_TO_STRING";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_SINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_INT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_DINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_LINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_USINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_UINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_UDINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = strname + "_TO_ULINT";
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ /* ... */
+ tmp = "STRING_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "SINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "INT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "DINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "LINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "USINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "UINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "UDINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ tmp = "ULINT_TO_" + strname;
+ library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token);
+ /* ... */
+}
+
+
+
+
--- a/stage1_2/stage1_2.cc Thu Nov 15 14:14:00 2012 +0000
+++ b/stage1_2/stage1_2.cc Thu Nov 15 17:30:35 2012 +0100
@@ -46,7 +46,7 @@
#include "stage1_2.hh"
#include "iec_bison.h"
#include "stage1_2_priv.hh"
-
+#include "derived_conversion_functions.hh"
@@ -285,6 +285,11 @@
bool full_token_loc /* error messages specify full token location */
);
+int sstage2__(const char *text,
+ symbol_c **tree_root_ref,
+ bool full_token_loc /* error messages specify full token location */
+ );
+
int stage1_2(const char *filename, symbol_c **tree_root_ref, stage1_2_options_t options) {
/* NOTE: we only call stage2 (bison - syntax analysis) directly, as stage 2 will itself call stage1 (flex - lexical analysis)
@@ -297,8 +302,12 @@
* These callback functions will get their data from local (to this file) global variables...
* We now set those variables...
*/
+
safe_extensions_ = options.safe_extensions;
-
- return stage2__(filename, options.includedir, tree_root_ref, options.full_token_loc);
-}
-
+ int ret = stage2__(filename, options.includedir, tree_root_ref, options.full_token_loc);
+ derived_conversion_functions_c derived_conversion_functions(*tree_root_ref);
+ std::string source_code = derived_conversion_functions.get_declaration(*tree_root_ref);
+ ret = sstage2__(source_code.c_str(), tree_root_ref, false);
+ return ret;
+}
+