1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 /* Main program for the merged compiler */
18 #if defined SOLARIS || defined SOLARIS8
19 # include <sys/utsname.h>
23 #include "../common/usage_stats.hh"
27 #include "../common/dbgnew.hh"
28 #include "../common/path.h"
29 #include "../common/version_internal.h"
30 #include "../common/userinfo.h"
31 #include "datatypes.h"
34 #include "asn1/asn1_preparser.h"
35 #include "asn1/asn1.hh"
36 #include "ttcn3/ttcn3_preparser.h"
37 #include "ttcn3/compiler.h"
40 #include "asn1/AST_asn1.hh"
41 #include "ttcn3/AST_ttcn3.hh"
43 #include "CodeGenHelper.hh"
44 #include "Stopwatch.hh"
46 #include "ttcn3/Ttcn2Json.hh"
49 #include "../common/license.h"
52 using namespace Common
;
54 const char *output_dir
= NULL
;
55 const char *tcov_file_name
= NULL
;
56 tcov_file_list
*tcov_files
= NULL
;
57 expstring_t effective_module_lines
= NULL
;
58 expstring_t effective_module_functions
= NULL
;
60 size_t nof_top_level_pdus
= 0;
61 const char **top_level_pdu
= NULL
;
63 boolean generate_skeleton
= FALSE
, force_overwrite
= FALSE
,
64 include_line_info
= FALSE
, include_location_info
= FALSE
,
65 duplicate_underscores
= FALSE
, parse_only
= FALSE
,
66 semantic_check_only
= FALSE
, output_only_linenum
= FALSE
,
67 default_as_optional
= FALSE
, enable_set_bound_out_param
= FALSE
,
68 use_runtime_2
= FALSE
, gcc_compat
= FALSE
, asn1_xer
= FALSE
,
69 check_subtype
= TRUE
, suppress_context
= FALSE
, display_up_to_date
= FALSE
;
71 // Default code splitting mode is set to 'no splitting'.
72 CodeGenHelper::split_type code_splitting_mode
= CodeGenHelper::SPLIT_NONE
;
74 #if defined SOLARIS || defined SOLARIS8
75 /** Automatic detection of Solaris version based on uname() system call.
76 * Distinguishing is needed because some socket functions use socklen_t
77 * (which is an alias for unsigned int) as length arguments on Solaris 8.
78 * On Solaris 2.6 the argument type is simply int and no socklen_t or other
80 * Note: It was discovered later that Solaris 7 (which is used rarely within
81 * Ericsson) already uses socklen_t thus the SOLARIS8 platform identifier is a
83 static const char *get_platform_string(void)
87 if (uname(&name
) < 0) {
88 WARNING("System call uname() failed: %s", strerror(errno
));
92 if (sscanf(name
.release
, "%d.%d", &major
, &minor
) == 2 && major
== 5) {
93 if (minor
<= 6) return "SOLARIS";
94 else return "SOLARIS8";
96 ERROR("Invalid OS release: %s", name
.release
);
101 #define get_platform_string() "LINUX"
102 #elif defined FREEBSD
103 #define get_platform_string() "FREEBSD"
105 #define get_platform_string() "WIN32"
106 #elif defined INTERIX
107 #define get_platform_string() "INTERIX"
109 #error Platform was not set.
113 const char *expected_platform
= get_platform_string();
116 Modules
*modules
= NULL
;
118 // Features can be disabled in the license or by commandline switches
119 static bool raw_disabled
= false, ber_disabled
= false, per_disabled
= false,
120 text_disabled
= false, xer_disabled
= false, json_disabled
= false;
121 static bool attribute_validation_disabled
= FALSE
;
123 static bool has_raw_feature
= false, has_ber_feature
= false,
124 has_per_feature
= false, has_text_feature
= false, has_xer_feature
= false;
129 if (raw_disabled
) return FALSE
;
131 if (!has_raw_feature
) {
132 WARNING("The license key does not allow the generation of "
133 "RAW encoder/decoder functions.");
143 if (ber_disabled
) return FALSE
;
145 if (!has_ber_feature
) {
146 WARNING("The license key does not allow the generation of "
147 "BER encoder/decoder functions.");
157 if (per_disabled
) return FALSE
;
159 if (!has_per_feature
) {
160 WARNING("The license key does not allow the generation of "
161 "PER encoder/decoder functions.");
169 boolean
enable_text()
171 if (text_disabled
) return FALSE
;
173 if (!has_text_feature
) {
174 WARNING("The license key does not allow the generation of "
175 "TEXT encoder/decoder functions.");
176 text_disabled
= true;
185 if (xer_disabled
) return FALSE
;
187 if (!has_xer_feature
) {
188 WARNING("The license key does not allow the generation of "
189 "XER encoder/decoder functions.");
197 boolean
enable_json()
199 return !json_disabled
;
202 boolean
disable_attribute_validation()
204 if (attribute_validation_disabled
) return TRUE
;
209 char *canonize_input_file(const char *path_name
)
211 switch (get_path_status(path_name
)) {
213 ERROR("Input file `%s' does not exist.", path_name
);
216 ERROR("Argument `%s' is a directory.", path_name
);
221 char *dir_name
= get_dir_from_path(path_name
);
222 char *abs_dir
= get_absolute_dir(dir_name
, NULL
);
224 char *file_name
= get_file_from_path(path_name
);
225 char *ret_val
= compose_path_name(abs_dir
, file_name
);
231 struct module_struct
{
232 const char *file_name
;
234 Module::moduletype_t module_type
;
235 bool need_codegen
; /**< Code is generated for a module if
236 - the module appears on the command line after the dash, or
237 - there is no dash (code is generated for all modules) */
240 static void add_module(size_t& n_modules
, module_struct
*& module_list
,
241 const char *file_name
, Module::moduletype_t module_type
)
243 char *absolute_path
= canonize_input_file(file_name
);
244 if (absolute_path
== NULL
) return;
245 for (size_t i
= 0; i
< n_modules
; i
++) {
246 const module_struct
*module
= module_list
+ i
;
247 if (module
->module_type
== module_type
&&
248 !strcmp(module
->absolute_path
, absolute_path
)) {
249 ERROR("Input file `%s' was given more than once.", file_name
);
254 module_list
= (module_struct
*)
255 Realloc(module_list
, (n_modules
+ 1) * sizeof(module_struct
));
256 module_struct
*module
= module_list
+ n_modules
;
257 module
->file_name
= file_name
;
258 module
->absolute_path
= absolute_path
;
259 module
->module_type
= module_type
;
260 module
->need_codegen
= false;
264 const char *get_tcov_file_name(const char *file_name
)
266 tcov_file_list
*tcov_file
= tcov_files
;
267 expstring_t file_name_pp
= mputprintf(NULL
, "%spp", file_name
);
268 while (tcov_file
!= NULL
) {
269 // This name can be a `.ttcnpp' too.
270 const char *real_file_name
= static_cast<const char *>(tcov_file
->file_name
);
271 if (!strcmp(file_name
, real_file_name
) ||
272 !strcmp(static_cast<const char *>(file_name_pp
), real_file_name
)) {
274 return real_file_name
;
276 tcov_file
= tcov_file
->next
;
282 boolean
in_tcov_files(const char *file_name
)
284 return get_tcov_file_name(file_name
) ? TRUE
: FALSE
;
287 static bool check_file_list(const char *file_name
, module_struct
*module_list
, size_t n_modules
)
289 FILE *fp
= fopen(file_name
, "r");
291 ERROR("File `%s' does not exist.", file_name
);
295 #define PATH_MAX 1024
298 bool unlisted_files
= false;
299 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
300 // Remove trailing '\n'.
301 size_t line_len
= strlen(line
) - 1;
302 if (line
[line_len
] == '\n')
304 // Handle `.ttcnpp' files in input file.
306 char last
= line
[line_len
- 1];
307 char before_last
= line
[line_len
- 2];
308 if (last
== 'p' && before_last
== 'p')
314 for (; i
< n_modules
; ++i
) {
315 const module_struct
*module
= module_list
+ i
;
316 if (!strncmp(module
->file_name
, line
, line_len
)) {
317 tcov_file_list
*next_file
= new tcov_file_list
;
318 next_file
->next
= tcov_files
;
319 // We'll need the `.ttcnpp' file name.
320 next_file
->file_name
= mcopystr(line
);
321 tcov_files
= next_file
;
325 if (i
== n_modules
) {
326 ERROR("File `%s' was listed in `%s', but not in the command line.",
328 unlisted_files
= true;
332 if (unlisted_files
) {
333 while (tcov_files
!= NULL
) {
334 tcov_file_list
*next_file
= tcov_files
->next
;
335 Free(tcov_files
->file_name
);
337 tcov_files
= next_file
;
341 return !unlisted_files
;
344 static boolean
is_valid_asn1_filename(const char* file_name
)
346 if (0 == strchr(file_name
, '-' )) {
355 "usage: %s [-abcdfgilLOpqrRsStuwxXjy] [-K file] [-V verb_level] [-o dir]\n"
356 " [-U none|type] [-P modulename.top_level_pdu_name] [-Q number] ...\n"
357 " [-T] module.ttcn [-A] module.asn ...\n"
359 " or %s --ttcn2json [-T] module.ttcn [-A] module.asn ... - schema.json\n"
362 " -a: force XER in ASN.1 files\n"
363 " -b: disable BER encoder/decoder functions\n"
364 " -c: write out checksums in case of error\n"
365 " -d: treat default fields as omit\n"
366 " -f: force overwriting of output files\n"
367 " -g: emulate GCC error/warning message format\n"
368 " -i: use only line numbers in error/warning messages\n"
369 " -l: include source line info in C++ code\n"
370 " -L: add source line info for logging\n"
371 " -K file: enable selective code coverage\n"
372 " -p: parse only (no semantic check or code generation)\n"
373 " -q: suppress all messages (quiet mode)\n"
374 " -Qn: quit after n errors\n"
375 " -r: disable RAW encoder/decoder functions\n"
376 " -R: use function test runtime (TITAN_RUNTIME_2)\n"
377 " -s: parse and semantic check only (no code generation)\n"
378 " -S: suppress context information\n"
379 " -t: generate Test Port skeleton\n"
380 " -u: duplicate underscores in file names\n"
381 " -U none|type: select code splitting mode for the generated C++ code\n"
382 " -w: suppress warnings\n"
383 " -x: disable TEXT encoder/decoder functions\n"
384 " -X: disable XER encoder/decoder functions\n"
385 " -j: disable JSON encoder/decoder functions\n"
386 " -y: disable subtype checking\n"
387 " -V verb_level: set verbosity level bitmask (decimal)\n"
388 " -o dir: output files will be placed into dir\n"
389 " -Y: Enforces legacy behaviour of the \"out\" function parameters (see refguide)\n"
390 " -P pduname: define top-level pdu\n"
391 " -T file: force interpretation of file as TTCN-3 module\n"
392 " -A file: force interpretation of file as ASN.1 module\n"
393 " -v: show version\n"
394 " --ttcn2json: generate JSON schema from input modules\n", argv0
, argv0
, argv0
);
397 #define SET_FLAG(x) if (x##flag) {\
398 ERROR("Flag -" #x " was specified more than once.");\
400 } else x##flag = true
403 extern int ttcn3_debug
;
404 extern int asn1_yydebug
;
405 extern int pattern_yydebug
;
406 extern int pattern_unidebug
;
407 extern int rawAST_debug
;
408 extern int coding_attrib_debug
;
410 int main(int argc
, char *argv
[])
414 asn1_yydebug
= !! getenv("DEBUG_ASN1");
415 ttcn3_debug
= !! getenv("DEBUG_TTCN");
416 pattern_unidebug
= pattern_yydebug
= !! getenv("DEBUG_PATTERN");
417 rawAST_debug
= !! getenv("DEBUG_RAW");
418 coding_attrib_debug
= !!getenv("DEBUG_ATRIB") || getenv("DEBUG_ATTRIB");
422 #if defined(__CYGWIN__) || defined(INTERIX)
425 debug_new_counter
.set_program_name(argv0
);
430 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version "
431 PRODUCT_NUMBER
"\n", stderr
);
437 Aflag
= false, Lflag
= false, Yflag
= false,
438 Pflag
= false, Tflag
= false, Vflag
= false, bflag
= false,
439 cflag
= false, fflag
= false, iflag
= false, lflag
= false,
440 oflag
= false, pflag
= false, qflag
= false, rflag
= false, sflag
= false,
441 tflag
= false, uflag
= false, vflag
= false, wflag
= false, xflag
= false,
442 dflag
= false, Xflag
= false, Rflag
= false, gflag
= false, aflag
= false,
443 s0flag
= false, Cflag
= false, yflag
= false, Uflag
= false, Qflag
= false,
444 Sflag
= false, Kflag
= false, jflag
= false,
445 errflag
= false, print_usage
= false, ttcn2json
= false;
449 bool asn1_modules_present
= false;
451 bool ttcn3_modules_present
= false;
453 size_t n_modules
= 0;
454 module_struct
*module_list
= NULL
;
455 char* json_schema_name
= NULL
;
457 if (0 == strcmp(argv
[1], "--ttcn2json")) {
459 display_up_to_date
= TRUE
;
460 for (int i
= 2; i
< argc
; ++i
) {
461 // A dash (-) is used to separate the schema file name from the input files
462 if (0 == strcmp(argv
[i
], "-")) {
464 json_schema_name
= mcopystr(argv
[i
+ 1]);
466 ERROR("Expected JSON schema name (1 argument) after option `--ttcn2json' and `-'");
471 else if (0 == strcmp(argv
[i
], "-A")) {
474 ERROR("Option `-A' must be followed by an ASN.1 file name");
478 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_ASN
);
479 asn1_modules_present
= true;
481 else if (0 == strcmp(argv
[i
], "-T")) {
484 ERROR("Option `-T' must be followed by a TTCN-3 file name");
488 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_TTCN
);
490 else if (argv
[i
][0] == '-') {
491 ERROR("Invalid option `%s' after option `--ttcn2json'", argv
[i
]);
497 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
501 if (!errflag
&& 0 == n_modules
) {
502 ERROR("No TTCN-3 or ASN.1 modules specified after option `--ttcn2json'");
507 if (!errflag
&& NULL
== json_schema_name
) {
508 // Create the schema name using the first TTCN-3 or ASN.1 file's name
509 const module_struct
& first
= module_list
[0];
510 if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 4, ".asn", 4)) {
511 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 4);
512 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
514 else if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 5, ".ttcn", 5)) {
515 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 5);
516 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
519 json_schema_name
= mprintf("%s.json", first
.file_name
);
526 int c
= getopt(argc
, argv
, "aA:C:K:LP:T:V:bcdfgilo:YpqQ:rRs0StuU:vwxXjy-");
535 add_module(n_modules
, module_list
, optarg
, Module::MOD_ASN
);
536 asn1_modules_present
= true;
540 expected_platform
= optarg
;
544 include_location_info
= TRUE
;
548 nof_top_level_pdus
++;
549 top_level_pdu
=(const char**)
550 Realloc(top_level_pdu
, nof_top_level_pdus
*sizeof(*top_level_pdu
));
551 top_level_pdu
[nof_top_level_pdus
-1] = optarg
;
555 add_module(n_modules
, module_list
, optarg
, Module::MOD_TTCN
);
557 ttcn3_modules_present
= true;
562 /* set verbosity level bitmask */
563 if (isdigit(optarg
[0])) {
564 verb_level
= atoi(optarg
);
565 // don't bother with overflow
568 ERROR("Option `-V' requires a decimal number as argument instead of "
582 default_as_optional
= TRUE
;
586 force_overwrite
= TRUE
;
594 output_only_linenum
= TRUE
;
598 tcov_file_name
= optarg
;
602 include_line_info
= TRUE
;
610 enable_set_bound_out_param
= TRUE
;
618 /* quiet; suppress all message */
627 use_runtime_2
= TRUE
;
631 semantic_check_only
= TRUE
;
635 suppress_context
= TRUE
;
639 attribute_validation_disabled
= TRUE
;
643 generate_skeleton
= TRUE
;
647 duplicate_underscores
= TRUE
;
651 if (!cgh
.set_split_mode(optarg
)) {
652 ERROR("Wrong code splitting option: '%s'. Valid values are: 'none', "
662 /* suppress warnings and "not supported" messages */
663 verb_level
&= ~(1|2);
667 text_disabled
= TRUE
;
675 json_disabled
= TRUE
;
679 check_subtype
= FALSE
;
685 printf("Q: %s\n", optarg
);
688 max_errs
= strtol(optarg
, (char**)NULL
, 10);
690 || (long)(int)max_errs
!= max_errs
) { // does not fit into int
691 ERROR("Invalid value %s: %s", optarg
, strerror(errno
));
694 else if (max_errs
< 0) {
695 ERROR("Negative value %s not allowed", optarg
);
699 if (max_errs
== 0) max_errs
= 1;
702 Error_Context::set_max_errors(max_errs
);
706 if (!strcmp(argv
[optind
], "--ttcn2json")) {
707 ERROR("Option `--ttcn2json' does not allow the use of other options");
709 ERROR("Invalid option: `%s'", argv
[optind
]);
720 /* Checking incompatible options */
722 if (Aflag
|| Lflag
|| Pflag
|| Tflag
|| Vflag
|| Yflag
||
723 bflag
|| fflag
|| iflag
|| lflag
|| oflag
|| pflag
|| qflag
||
724 rflag
|| sflag
|| tflag
|| uflag
|| wflag
|| xflag
|| Xflag
|| Rflag
||
725 Uflag
|| yflag
|| Kflag
|| jflag
) {
732 ERROR("Options `-p' and `-s' are incompatible with each other.");
733 // totally confusing: exit immediately
737 if (Kflag
&& !Lflag
) {
738 ERROR("Source line information `-L' is necessary for code coverage `-K'.");
741 if (iflag
&& gflag
) {
742 WARNING("Option `-g' overrides `-i'.");
743 iflag
= false; // -g gives more information
745 if (oflag
&& get_path_status(output_dir
) != PS_DIRECTORY
) {
746 ERROR("The argument of -o switch (`%s') must be a directory.",
750 if (optind
== argc
&& n_modules
== 0) {
751 ERROR("No input TTCN-3 or ASN.1 module was given.");
758 if (print_usage
) usage();
759 Free(json_schema_name
);
764 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor\n"
765 "Product number: " PRODUCT_NUMBER
"\n"
766 "Build date: " __DATE__
" " __TIME__
"\n"
767 "Compiled with: " C_COMPILER_VERSION
"\n\n"
768 COPYRIGHT_STRING
"\n\n", stderr
);
770 print_license_info();
771 fputs("\nUsing ", stderr
);
772 fputs(openssl_version_str(), stderr
);
773 fputs("\n\n", stderr
);
782 int license_valid
= verify_license(&lstr
);
784 if (!license_valid
) {
791 /* the position of '-' switch in argv list */
792 int dash_position
= -1;
794 /* Add the remaining files until switch '-' to the module_list */
795 for(int i
= optind
; i
< argc
; i
++) {
796 if (strcmp(argv
[i
], "-"))
797 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
804 if (dash_position
== -1) {
805 /** if '-' was not present in the command line code should be generated for
807 for (size_t i
= 0; i
< n_modules
; i
++) module_list
[i
].need_codegen
= true;
809 for (int i
= dash_position
+ 1; i
< argc
; i
++) {
810 char *absolute_path
= canonize_input_file(argv
[i
]);
811 if (absolute_path
== NULL
) continue;
813 for (size_t j
= 0; j
< n_modules
; j
++) {
814 module_struct
*module
= module_list
+ j
;
815 if (!strcmp(module
->absolute_path
, absolute_path
)) {
816 module
->need_codegen
= true;
818 // do not stop: the same file may be present on the list twice
819 // (as both ASN.1 and TTCN-3 module)
824 ERROR("File `%s' was not given before the `-' switch for selective "
825 "code generation.", argv
[i
]);
826 // go further (i.e. check all files after the `-')
833 STOPWATCH("Determining module types");
834 // check the readability of all files and
835 // determine the type of unknown modules
836 for (size_t i
= 0; i
< n_modules
; i
++) {
837 module_struct
*module
= module_list
+ i
;
838 FILE *fp
= fopen(module
->file_name
, "r");
840 if (module
->module_type
== Module::MOD_UNKNOWN
) {
841 // try the ASN.1 and TTCN-3 preparsers
842 boolean asn1_module
= is_asn1_module(module
->file_name
, fp
, NULL
);
843 boolean ttcn3_module
= is_ttcn3_module(module
->file_name
, fp
, NULL
);
845 if (!is_valid_asn1_filename (module
->file_name
)) {
846 ERROR("The file name (without suffix) shall be identical to the module name.\n"
847 "If the name of the ASN.1 module contains a hyphen, the corresponding "
848 "file name shall contain an underscore character instead.");
851 ERROR("File `%s' looks so strange that it can contain both an "
852 "ASN.1 and a TTCN-3 module. Use the command-line switch `-A' or "
853 "`-T' to set its type.", module
->file_name
);
856 for (size_t j
= 0; j
< n_modules
; j
++) {
857 module_struct
*module2
= module_list
+ j
;
858 if (module2
->module_type
== Module::MOD_ASN
&&
859 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
865 ERROR("Input file `%s' was given more than once.",
868 module
->module_type
= Module::MOD_ASN
;
869 asn1_modules_present
= true;
872 } else if (ttcn3_module
) {
874 for (size_t j
= 0; j
< n_modules
; j
++) {
875 module_struct
*module2
= module_list
+ j
;
876 if (module2
->module_type
== Module::MOD_TTCN
&&
877 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
883 ERROR("Input file `%s' was given more than once.",
886 module
->module_type
= Module::MOD_TTCN
;
888 ttcn3_modules_present
= true;
892 ERROR("Cannot recognize file `%s' as an ASN.1 or TTCN-3 module. "
893 "Use the command-line switch `-A' or `-T' to set its type.",
899 ERROR("Cannot open input file `%s' for reading: %s", module
->file_name
,
902 // do not invoke the real parsers on that file
903 module
->module_type
= Module::MOD_UNKNOWN
;
909 if (!semantic_check_only
) {
910 NOTIFY("On native win32 builds code generation is disabled.");
911 semantic_check_only
= TRUE
;
915 /* Checking of required license features */
916 if (asn1_modules_present
&& !check_feature(&lstr
, FEATURE_ASN1
)) {
917 ERROR("The license key does not allow the parsing of "
921 if (ttcn3_modules_present
&& !check_feature(&lstr
, FEATURE_TTCN3
)) {
922 ERROR("The license key does not allow the parsing of "
926 if (!parse_only
&& !semantic_check_only
&&
927 !check_feature(&lstr
, FEATURE_CODEGEN
)) {
928 WARNING("The license key does not allow the generation of "
930 semantic_check_only
= TRUE
;
932 if (generate_skeleton
&& !check_feature(&lstr
, FEATURE_TPGEN
)) {
933 WARNING("The license key does not allow the generation of "
934 "Test Port skeletons.");
935 generate_skeleton
= FALSE
;
937 has_raw_feature
= check_feature(&lstr
, FEATURE_RAW
);
938 has_ber_feature
= check_feature(&lstr
, FEATURE_BER
);
939 has_per_feature
= check_feature(&lstr
, FEATURE_PER
);
940 has_text_feature
= check_feature(&lstr
, FEATURE_TEXT
);
941 has_xer_feature
= check_feature(&lstr
, FEATURE_XER
);
944 if (Kflag
&& !check_file_list(tcov_file_name
, module_list
, n_modules
)) {
945 ERROR("Error while processing `%s' provided for code coverage data "
946 "generation.", tcov_file_name
);
950 STOPWATCH("Parsing modules");
953 if (asn1_modules_present
) asn1_init();
954 modules
= new Common::Modules();
956 for (size_t i
= 0; i
< n_modules
; i
++) {
957 const module_struct
*module
= module_list
+ i
;
958 switch (module
->module_type
) {
959 case Module::MOD_ASN
:
960 asn1_parse_file(module
->file_name
, module
->need_codegen
);
962 case Module::MOD_TTCN
:
963 ttcn3_parse_file(module
->file_name
, module
->need_codegen
);
965 default: // MOD_UNKNOWN ?
970 for (size_t i
= 0; i
< n_modules
; i
++) Free(module_list
[i
].absolute_path
);
974 if (!parse_only
&& 0 == Error_Context::get_error_count()) {
975 NOTIFY("Checking modules...");
977 STOPWATCH("Semantic check");
982 if (verb_level
> 7) modules
->dump();
984 int ret_val
= EXIT_SUCCESS
;
985 unsigned int error_count
= Error_Context::get_error_count();
986 if (error_count
> 0) ret_val
= EXIT_FAILURE
;
988 if (parse_only
|| semantic_check_only
) {
989 // print detailed statistics
990 Error_Context::print_error_statistics();
992 if (error_count
== 0) {
995 // Ignore SIGPIPE signals
996 struct sigaction sig_act
;
997 if (sigaction(SIGPIPE
, NULL
, &sig_act
))
998 ERROR("System call sigaction() failed when getting signal "
999 "handling information for %s.", "SIGINT");
1000 sig_act
.sa_handler
= SIG_IGN
;
1001 sig_act
.sa_flags
= 0;
1002 if (sigaction(SIGPIPE
, &sig_act
, NULL
))
1003 ERROR("System call sigaction() failed when disabling signal "
1007 std::stringstream stream
;
1008 stream
<< "compiler";
1009 std::set
<ModuleVersion
> versions
= modules
->getVersionsWithProductNumber();
1010 if (!versions
.empty()) {
1011 stream
<< "&products=";
1012 for (std::set
<ModuleVersion
>::iterator it
= versions
.begin(); it
!= versions
.end(); ++it
) {
1013 if (it
!= versions
.begin()) {
1016 stream
<< it
->toString();
1020 HttpSender
*sender
= new HttpSender
;
1021 UsageData::getInstance().sendDataThreaded(stream
.str(), sender
);
1024 NOTIFY("Generating JSON schema...");
1025 STOPWATCH("Generating JSON schema");
1026 // the Ttcn2Json constructor starts the process
1027 Ttcn::Ttcn2Json
t2j(modules
, json_schema_name
);
1029 NOTIFY("Generating code...");
1030 STOPWATCH("Generating code");
1031 modules
->generate_code(cgh
);
1032 report_nof_updated_files();
1035 NOTIFY("Error%s found in the input module%s. Code will not be generated.",
1036 error_count
> 1 ? "s" : "", n_modules
> 1 ? "s" : "");
1038 modules
->write_checksums();
1044 while (tcov_files
!= NULL
) {
1045 tcov_file_list
*next_file
= tcov_files
->next
;
1046 Free(tcov_files
->file_name
);
1048 tcov_files
= next_file
;
1053 Free(top_level_pdu
);
1054 if (asn1_modules_present
) asn1_free();
1056 Common::Node::chk_counter();
1057 Location::delete_source_file_names();
1058 Free(json_schema_name
);
1060 // dbgnew.hh already does it: check_mem_leak(argv[0]);