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"
48 #include "ttcn3/profiler.h"
51 #include "../common/license.h"
54 using namespace Common
;
56 const char *output_dir
= NULL
;
57 const char *tcov_file_name
= NULL
;
58 const char *profiler_file_name
= NULL
;
59 tcov_file_list
*tcov_files
= NULL
;
60 expstring_t effective_module_lines
= NULL
;
61 expstring_t effective_module_functions
= NULL
;
63 size_t nof_top_level_pdus
= 0;
64 const char **top_level_pdu
= NULL
;
66 boolean generate_skeleton
= FALSE
, force_overwrite
= FALSE
,
67 include_line_info
= FALSE
, include_location_info
= FALSE
,
68 duplicate_underscores
= FALSE
, parse_only
= FALSE
,
69 semantic_check_only
= FALSE
, output_only_linenum
= FALSE
,
70 default_as_optional
= FALSE
, enable_set_bound_out_param
= FALSE
,
71 use_runtime_2
= FALSE
, gcc_compat
= FALSE
, asn1_xer
= FALSE
,
72 check_subtype
= TRUE
, suppress_context
= FALSE
, display_up_to_date
= FALSE
,
73 implicit_json_encoding
= FALSE
, json_refs_for_all_types
= TRUE
,
74 force_gen_seof
= FALSE
;
76 // Default code splitting mode is set to 'no splitting'.
77 CodeGenHelper::split_type code_splitting_mode
= CodeGenHelper::SPLIT_NONE
;
79 #if defined SOLARIS || defined SOLARIS8
80 /** Automatic detection of Solaris version based on uname() system call.
81 * Distinguishing is needed because some socket functions use socklen_t
82 * (which is an alias for unsigned int) as length arguments on Solaris 8.
83 * On Solaris 2.6 the argument type is simply int and no socklen_t or other
85 * Note: It was discovered later that Solaris 7 (which is used rarely within
86 * Ericsson) already uses socklen_t thus the SOLARIS8 platform identifier is a
88 static const char *get_platform_string(void)
92 if (uname(&name
) < 0) {
93 WARNING("System call uname() failed: %s", strerror(errno
));
97 if (sscanf(name
.release
, "%d.%d", &major
, &minor
) == 2 && major
== 5) {
98 if (minor
<= 6) return "SOLARIS";
99 else return "SOLARIS8";
101 ERROR("Invalid OS release: %s", name
.release
);
106 #define get_platform_string() "LINUX"
107 #elif defined FREEBSD
108 #define get_platform_string() "FREEBSD"
110 #define get_platform_string() "WIN32"
111 #elif defined INTERIX
112 #define get_platform_string() "INTERIX"
114 #error Platform was not set.
118 const char *expected_platform
= get_platform_string();
121 Modules
*modules
= NULL
;
123 // Features can be disabled in the license or by commandline switches
124 static bool raw_disabled
= false, ber_disabled
= false, per_disabled
= false,
125 text_disabled
= false, xer_disabled
= false, json_disabled
= false;
126 static bool attribute_validation_disabled
= FALSE
;
128 static bool has_raw_feature
= false, has_ber_feature
= false,
129 has_per_feature
= false, has_text_feature
= false, has_xer_feature
= false;
134 if (raw_disabled
) return FALSE
;
136 if (!has_raw_feature
) {
137 WARNING("The license key does not allow the generation of "
138 "RAW encoder/decoder functions.");
148 if (ber_disabled
) return FALSE
;
150 if (!has_ber_feature
) {
151 WARNING("The license key does not allow the generation of "
152 "BER encoder/decoder functions.");
162 if (per_disabled
) return FALSE
;
164 if (!has_per_feature
) {
165 WARNING("The license key does not allow the generation of "
166 "PER encoder/decoder functions.");
174 boolean
enable_text()
176 if (text_disabled
) return FALSE
;
178 if (!has_text_feature
) {
179 WARNING("The license key does not allow the generation of "
180 "TEXT encoder/decoder functions.");
181 text_disabled
= true;
190 if (xer_disabled
) return FALSE
;
192 if (!has_xer_feature
) {
193 WARNING("The license key does not allow the generation of "
194 "XER encoder/decoder functions.");
202 boolean
enable_json()
204 return !json_disabled
;
207 boolean
disable_attribute_validation()
209 if (attribute_validation_disabled
) return TRUE
;
214 char *canonize_input_file(const char *path_name
)
216 switch (get_path_status(path_name
)) {
218 ERROR("Input file `%s' does not exist.", path_name
);
221 ERROR("Argument `%s' is a directory.", path_name
);
226 char *dir_name
= get_dir_from_path(path_name
);
227 char *abs_dir
= get_absolute_dir(dir_name
, NULL
);
229 char *file_name
= get_file_from_path(path_name
);
230 char *ret_val
= compose_path_name(abs_dir
, file_name
);
236 struct module_struct
{
237 const char *file_name
;
239 Module::moduletype_t module_type
;
240 bool need_codegen
; /**< Code is generated for a module if
241 - the module appears on the command line after the dash, or
242 - there is no dash (code is generated for all modules) */
245 static void add_module(size_t& n_modules
, module_struct
*& module_list
,
246 const char *file_name
, Module::moduletype_t module_type
)
248 char *absolute_path
= canonize_input_file(file_name
);
249 if (absolute_path
== NULL
) return;
250 for (size_t i
= 0; i
< n_modules
; i
++) {
251 const module_struct
*module
= module_list
+ i
;
252 if (module
->module_type
== module_type
&&
253 !strcmp(module
->absolute_path
, absolute_path
)) {
254 ERROR("Input file `%s' was given more than once.", file_name
);
259 module_list
= (module_struct
*)
260 Realloc(module_list
, (n_modules
+ 1) * sizeof(module_struct
));
261 module_struct
*module
= module_list
+ n_modules
;
262 module
->file_name
= file_name
;
263 module
->absolute_path
= absolute_path
;
264 module
->module_type
= module_type
;
265 module
->need_codegen
= false;
269 const char *get_tcov_file_name(const char *file_name
)
271 tcov_file_list
*tcov_file
= tcov_files
;
272 expstring_t file_name_pp
= mputprintf(NULL
, "%spp", file_name
);
273 while (tcov_file
!= NULL
) {
274 // This name can be a `.ttcnpp' too.
275 const char *real_file_name
= static_cast<const char *>(tcov_file
->file_name
);
276 if (!strcmp(file_name
, real_file_name
) ||
277 !strcmp(static_cast<const char *>(file_name_pp
), real_file_name
)) {
279 return real_file_name
;
281 tcov_file
= tcov_file
->next
;
287 boolean
in_tcov_files(const char *file_name
)
289 return get_tcov_file_name(file_name
) ? TRUE
: FALSE
;
292 static bool check_file_list(const char *file_name
, module_struct
*module_list
,
293 size_t n_modules
, tcov_file_list
*&file_list_head
)
295 FILE *fp
= fopen(file_name
, "r");
297 ERROR("File `%s' does not exist.", file_name
);
301 #define PATH_MAX 1024
304 bool unlisted_files
= false;
305 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
306 // Remove trailing '\n'.
307 size_t line_len
= strlen(line
) - 1;
308 if (line
[line_len
] == '\n')
310 // Handle `.ttcnpp' files in input file.
312 char last
= line
[line_len
- 1];
313 char before_last
= line
[line_len
- 2];
314 if (last
== 'p' && before_last
== 'p')
320 for (; i
< n_modules
; ++i
) {
321 const module_struct
*module
= module_list
+ i
;
322 if (!strncmp(module
->file_name
, line
, line_len
)) {
323 tcov_file_list
*next_file
= (tcov_file_list
*)Malloc(sizeof(tcov_file_list
));
324 next_file
->next
= file_list_head
;
325 // We'll need the `.ttcnpp' file name.
326 next_file
->file_name
= mcopystr(line
);
327 file_list_head
= next_file
;
331 if (i
== n_modules
) {
332 ERROR("File `%s' was listed in `%s', but not in the command line.",
334 unlisted_files
= true;
338 if (unlisted_files
) {
339 while (file_list_head
!= NULL
) {
340 tcov_file_list
*next_file
= file_list_head
->next
;
341 Free(file_list_head
->file_name
);
342 Free(file_list_head
);
343 file_list_head
= next_file
;
345 file_list_head
= NULL
;
347 return !unlisted_files
;
350 static boolean
is_valid_asn1_filename(const char* file_name
)
352 if (0 == strchr(file_name
, '-' )) {
361 "usage: %s [-abcdfgijlLOpqrRsStuwxXyY] [-K file] [-z file] [-V verb_level]\n"
362 " [-o dir] [-U none|type] [-P modulename.top_level_pdu_name] [-Q number] ...\n"
363 " [-T] module.ttcn [-A] module.asn ...\n"
365 " or %s --ttcn2json [-jf] ... [-T] module.ttcn [-A] module.asn ... [- schema.json]\n"
368 " -a: force XER in ASN.1 files\n"
369 " -b: disable BER encoder/decoder functions\n"
370 " -c: write out checksums in case of error\n"
371 " -d: treat default fields as omit\n"
372 " -f: force overwriting of output files\n"
373 " -g: emulate GCC error/warning message format\n"
374 " -i: use only line numbers in error/warning messages\n"
375 " -j: disable JSON encoder/decoder functions\n"
376 " -l: include source line info in C++ code\n"
377 " -L: add source line info for logging\n"
378 " -K file: enable selective code coverage\n"
379 " -o dir: output files will be placed into dir\n"
380 " -p: parse only (no semantic check or code generation)\n"
381 " -P pduname: define top-level pdu\n"
382 " -q: suppress all messages (quiet mode)\n"
383 " -Qn: quit after n errors\n"
384 " -r: disable RAW encoder/decoder functions\n"
385 " -R: use function test runtime (TITAN_RUNTIME_2)\n"
386 " -s: parse and semantic check only (no code generation)\n"
387 " -S: suppress context information\n"
388 " -t: generate Test Port skeleton\n"
389 " -u: duplicate underscores in file names\n"
390 " -U none|type: select code splitting mode for the generated C++ code\n"
391 " -V verb_level: set verbosity level bitmask (decimal)\n"
392 " -w: suppress warnings\n"
393 " -x: disable TEXT encoder/decoder functions\n"
394 " -X: disable XER encoder/decoder functions\n"
395 " -y: disable subtype checking\n"
396 " -Y: Enforces legacy behaviour of the \"out\" function parameters (see refguide)\n"
397 " -z file: enable profiling and code coverage for the TTCN-3 files in the argument\n"
398 " -T file: force interpretation of file as TTCN-3 module\n"
399 " -A file: force interpretation of file as ASN.1 module\n"
400 " -v: show version\n"
401 " --ttcn2json: generate JSON schema from input modules\n"
402 "JSON schema generator options:\n"
403 " -j: only include types with JSON encoding\n"
404 " -f: only generate references to types with JSON encoding/decoding functions\n", argv0
, argv0
, argv0
);
407 #define SET_FLAG(x) if (x##flag) {\
408 ERROR("Flag -" #x " was specified more than once.");\
410 } else x##flag = true
413 extern int ttcn3_debug
;
414 extern int asn1_yydebug
;
415 extern int pattern_yydebug
;
416 extern int pattern_unidebug
;
417 extern int rawAST_debug
;
418 extern int coding_attrib_debug
;
420 int main(int argc
, char *argv
[])
424 asn1_yydebug
= !! getenv("DEBUG_ASN1");
425 ttcn3_debug
= !! getenv("DEBUG_TTCN");
426 pattern_unidebug
= pattern_yydebug
= !! getenv("DEBUG_PATTERN");
427 rawAST_debug
= !! getenv("DEBUG_RAW");
428 coding_attrib_debug
= !!getenv("DEBUG_ATRIB") || getenv("DEBUG_ATTRIB");
432 #if defined(__CYGWIN__) || defined(INTERIX)
435 debug_new_counter
.set_program_name(argv0
);
440 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version "
441 PRODUCT_NUMBER
"\n", stderr
);
447 Aflag
= false, Lflag
= false, Yflag
= false,
448 Pflag
= false, Tflag
= false, Vflag
= false, bflag
= false,
449 cflag
= false, fflag
= false, iflag
= false, lflag
= false,
450 oflag
= false, pflag
= false, qflag
= false, rflag
= false, sflag
= false,
451 tflag
= false, uflag
= false, vflag
= false, wflag
= false, xflag
= false,
452 dflag
= false, Xflag
= false, Rflag
= false, gflag
= false, aflag
= false,
453 s0flag
= false, Cflag
= false, yflag
= false, Uflag
= false, Qflag
= false,
454 Sflag
= false, Kflag
= false, jflag
= false, zflag
= false, Fflag
= false,
455 errflag
= false, print_usage
= false, ttcn2json
= false;
459 bool asn1_modules_present
= false;
461 bool ttcn3_modules_present
= false;
463 size_t n_modules
= 0;
464 module_struct
*module_list
= NULL
;
465 char* json_schema_name
= NULL
;
467 if (0 == strcmp(argv
[1], "--ttcn2json")) {
469 display_up_to_date
= TRUE
;
470 implicit_json_encoding
= TRUE
;
471 for (int i
= 2; i
< argc
; ++i
) {
472 // A dash (-) is used to separate the schema file name from the input files
473 if (0 == strcmp(argv
[i
], "-")) {
475 json_schema_name
= mcopystr(argv
[i
+ 1]);
477 ERROR("Expected JSON schema name (1 argument) after option `--ttcn2json' and `-'");
482 else if (0 == strcmp(argv
[i
], "-A")) {
485 ERROR("Option `-A' must be followed by an ASN.1 file name");
489 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_ASN
);
490 asn1_modules_present
= true;
492 else if (0 == strcmp(argv
[i
], "-T")) {
495 ERROR("Option `-T' must be followed by a TTCN-3 file name");
499 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_TTCN
);
501 else if (0 == strcmp(argv
[i
], "-j")) {
502 implicit_json_encoding
= FALSE
;
504 else if (0 == strcmp(argv
[i
], "-f")) {
505 json_refs_for_all_types
= FALSE
;
507 else if (0 == strcmp(argv
[i
], "-fj") || 0 == strcmp(argv
[i
], "-jf")) {
508 implicit_json_encoding
= FALSE
;
509 json_refs_for_all_types
= FALSE
;
511 else if (argv
[i
][0] == '-') {
512 ERROR("Invalid option `%s' after option `--ttcn2json'", argv
[i
]);
518 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
522 if (!errflag
&& 0 == n_modules
) {
523 ERROR("No TTCN-3 or ASN.1 modules specified after option `--ttcn2json'");
528 if (!errflag
&& NULL
== json_schema_name
) {
529 // Create the schema name using the first TTCN-3 or ASN.1 file's name
530 const module_struct
& first
= module_list
[0];
531 if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 4, ".asn", 4)) {
532 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 4);
533 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
535 else if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 5, ".ttcn", 5)) {
536 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 5);
537 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
540 json_schema_name
= mprintf("%s.json", first
.file_name
);
547 int c
= getopt(argc
, argv
, "aA:C:K:LP:T:V:bcdfFgilo:YpqQ:rRs0StuU:vwxXjyz:-");
556 add_module(n_modules
, module_list
, optarg
, Module::MOD_ASN
);
557 asn1_modules_present
= true;
561 expected_platform
= optarg
;
565 include_location_info
= TRUE
;
569 nof_top_level_pdus
++;
570 top_level_pdu
=(const char**)
571 Realloc(top_level_pdu
, nof_top_level_pdus
*sizeof(*top_level_pdu
));
572 top_level_pdu
[nof_top_level_pdus
-1] = optarg
;
576 add_module(n_modules
, module_list
, optarg
, Module::MOD_TTCN
);
578 ttcn3_modules_present
= true;
583 /* set verbosity level bitmask */
584 if (isdigit(optarg
[0])) {
585 verb_level
= atoi(optarg
);
586 // don't bother with overflow
589 ERROR("Option `-V' requires a decimal number as argument instead of "
603 default_as_optional
= TRUE
;
607 force_overwrite
= TRUE
;
615 output_only_linenum
= TRUE
;
619 tcov_file_name
= optarg
;
623 include_line_info
= TRUE
;
631 enable_set_bound_out_param
= TRUE
;
639 /* quiet; suppress all message */
648 use_runtime_2
= TRUE
;
652 semantic_check_only
= TRUE
;
656 suppress_context
= TRUE
;
660 attribute_validation_disabled
= TRUE
;
664 generate_skeleton
= TRUE
;
668 duplicate_underscores
= TRUE
;
672 if (!cgh
.set_split_mode(optarg
)) {
673 ERROR("Wrong code splitting option: '%s'. Valid values are: 'none', "
683 /* suppress warnings and "not supported" messages */
684 verb_level
&= ~(1|2);
688 text_disabled
= TRUE
;
696 json_disabled
= TRUE
;
700 check_subtype
= FALSE
;
704 profiler_file_name
= optarg
;
708 force_gen_seof
= TRUE
;
714 printf("Q: %s\n", optarg
);
717 max_errs
= strtol(optarg
, (char**)NULL
, 10);
719 || (long)(int)max_errs
!= max_errs
) { // does not fit into int
720 ERROR("Invalid value %s: %s", optarg
, strerror(errno
));
723 else if (max_errs
< 0) {
724 ERROR("Negative value %s not allowed", optarg
);
728 if (max_errs
== 0) max_errs
= 1;
731 Error_Context::set_max_errors(max_errs
);
735 if (!strcmp(argv
[optind
], "--ttcn2json")) {
736 ERROR("Option `--ttcn2json' is only allowed as the first option");
738 ERROR("Invalid option: `%s'", argv
[optind
]);
749 /* Checking incompatible options */
751 if (Aflag
|| Lflag
|| Pflag
|| Tflag
|| Vflag
|| Yflag
||
752 bflag
|| fflag
|| iflag
|| lflag
|| oflag
|| pflag
|| qflag
||
753 rflag
|| sflag
|| tflag
|| uflag
|| wflag
|| xflag
|| Xflag
|| Rflag
||
754 Uflag
|| yflag
|| Kflag
|| jflag
|| zflag
|| Fflag
) {
761 ERROR("Options `-p' and `-s' are incompatible with each other.");
762 // totally confusing: exit immediately
766 if (Kflag
&& !Lflag
) {
767 ERROR("Source line information `-L' is necessary for code coverage `-K'.");
770 if (zflag
&& !Lflag
) {
771 ERROR("Source line information `-L' is necessary for profiling `-z'.");
774 if (iflag
&& gflag
) {
775 WARNING("Option `-g' overrides `-i'.");
776 iflag
= false; // -g gives more information
778 if (oflag
&& get_path_status(output_dir
) != PS_DIRECTORY
) {
779 ERROR("The argument of -o switch (`%s') must be a directory.",
783 if (optind
== argc
&& n_modules
== 0) {
784 ERROR("No input TTCN-3 or ASN.1 module was given.");
791 if (print_usage
) usage();
792 Free(json_schema_name
);
797 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor\n"
798 "Product number: " PRODUCT_NUMBER
"\n"
799 "Build date: " __DATE__
" " __TIME__
"\n"
800 "Compiled with: " C_COMPILER_VERSION
"\n\n"
801 COPYRIGHT_STRING
"\n\n", stderr
);
803 print_license_info();
804 fputs("\nUsing ", stderr
);
805 fputs(openssl_version_str(), stderr
);
806 fputs("\n\n", stderr
);
815 int license_valid
= verify_license(&lstr
);
817 if (!license_valid
) {
824 /* the position of '-' switch in argv list */
825 int dash_position
= -1;
827 /* Add the remaining files until switch '-' to the module_list */
828 for(int i
= optind
; i
< argc
; i
++) {
829 if (strcmp(argv
[i
], "-"))
830 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
837 if (dash_position
== -1) {
838 /** if '-' was not present in the command line code should be generated for
840 for (size_t i
= 0; i
< n_modules
; i
++) module_list
[i
].need_codegen
= true;
842 for (int i
= dash_position
+ 1; i
< argc
; i
++) {
843 char *absolute_path
= canonize_input_file(argv
[i
]);
844 if (absolute_path
== NULL
) continue;
846 for (size_t j
= 0; j
< n_modules
; j
++) {
847 module_struct
*module
= module_list
+ j
;
848 if (!strcmp(module
->absolute_path
, absolute_path
)) {
849 module
->need_codegen
= true;
851 // do not stop: the same file may be present on the list twice
852 // (as both ASN.1 and TTCN-3 module)
857 ERROR("File `%s' was not given before the `-' switch for selective "
858 "code generation.", argv
[i
]);
859 // go further (i.e. check all files after the `-')
866 STOPWATCH("Determining module types");
867 // check the readability of all files and
868 // determine the type of unknown modules
869 for (size_t i
= 0; i
< n_modules
; i
++) {
870 module_struct
*module
= module_list
+ i
;
871 FILE *fp
= fopen(module
->file_name
, "r");
873 if (module
->module_type
== Module::MOD_UNKNOWN
) {
874 // try the ASN.1 and TTCN-3 preparsers
875 boolean asn1_module
= is_asn1_module(module
->file_name
, fp
, NULL
);
876 boolean ttcn3_module
= is_ttcn3_module(module
->file_name
, fp
, NULL
);
878 if (!is_valid_asn1_filename (module
->file_name
)) {
879 ERROR("The file name (without suffix) shall be identical to the module name.\n"
880 "If the name of the ASN.1 module contains a hyphen, the corresponding "
881 "file name shall contain an underscore character instead.");
884 ERROR("File `%s' looks so strange that it can contain both an "
885 "ASN.1 and a TTCN-3 module. Use the command-line switch `-A' or "
886 "`-T' to set its type.", module
->file_name
);
889 for (size_t j
= 0; j
< n_modules
; j
++) {
890 module_struct
*module2
= module_list
+ j
;
891 if (module2
->module_type
== Module::MOD_ASN
&&
892 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
898 ERROR("Input file `%s' was given more than once.",
901 module
->module_type
= Module::MOD_ASN
;
902 asn1_modules_present
= true;
905 } else if (ttcn3_module
) {
907 for (size_t j
= 0; j
< n_modules
; j
++) {
908 module_struct
*module2
= module_list
+ j
;
909 if (module2
->module_type
== Module::MOD_TTCN
&&
910 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
916 ERROR("Input file `%s' was given more than once.",
919 module
->module_type
= Module::MOD_TTCN
;
921 ttcn3_modules_present
= true;
925 ERROR("Cannot recognize file `%s' as an ASN.1 or TTCN-3 module. "
926 "Use the command-line switch `-A' or `-T' to set its type.",
932 ERROR("Cannot open input file `%s' for reading: %s", module
->file_name
,
935 // do not invoke the real parsers on that file
936 module
->module_type
= Module::MOD_UNKNOWN
;
942 if (!semantic_check_only
) {
943 NOTIFY("On native win32 builds code generation is disabled.");
944 semantic_check_only
= TRUE
;
948 /* Checking of required license features */
949 if (asn1_modules_present
&& !check_feature(&lstr
, FEATURE_ASN1
)) {
950 ERROR("The license key does not allow the parsing of "
954 if (ttcn3_modules_present
&& !check_feature(&lstr
, FEATURE_TTCN3
)) {
955 ERROR("The license key does not allow the parsing of "
959 if (!parse_only
&& !semantic_check_only
&&
960 !check_feature(&lstr
, FEATURE_CODEGEN
)) {
961 WARNING("The license key does not allow the generation of "
963 semantic_check_only
= TRUE
;
965 if (generate_skeleton
&& !check_feature(&lstr
, FEATURE_TPGEN
)) {
966 WARNING("The license key does not allow the generation of "
967 "Test Port skeletons.");
968 generate_skeleton
= FALSE
;
970 has_raw_feature
= check_feature(&lstr
, FEATURE_RAW
);
971 has_ber_feature
= check_feature(&lstr
, FEATURE_BER
);
972 has_per_feature
= check_feature(&lstr
, FEATURE_PER
);
973 has_text_feature
= check_feature(&lstr
, FEATURE_TEXT
);
974 has_xer_feature
= check_feature(&lstr
, FEATURE_XER
);
977 if (Kflag
&& !check_file_list(tcov_file_name
, module_list
, n_modules
, tcov_files
)) {
978 ERROR("Error while processing `%s' provided for code coverage data "
979 "generation.", tcov_file_name
);
983 tcov_file_list
*file_list_head
= NULL
;
984 if(!check_file_list(profiler_file_name
, module_list
, n_modules
, file_list_head
)) {
985 ERROR("Error while processing `%s' provided for profiling and code coverage.",
989 init_profiler_data(file_list_head
);
992 STOPWATCH("Parsing modules");
995 if (asn1_modules_present
) asn1_init();
996 modules
= new Common::Modules();
998 for (size_t i
= 0; i
< n_modules
; i
++) {
999 const module_struct
*module
= module_list
+ i
;
1000 switch (module
->module_type
) {
1001 case Module::MOD_ASN
:
1002 asn1_parse_file(module
->file_name
, module
->need_codegen
);
1004 case Module::MOD_TTCN
:
1005 ttcn3_parse_file(module
->file_name
, module
->need_codegen
);
1007 default: // MOD_UNKNOWN ?
1012 for (size_t i
= 0; i
< n_modules
; i
++) Free(module_list
[i
].absolute_path
);
1016 if (!parse_only
&& 0 == Error_Context::get_error_count()) {
1017 NOTIFY("Checking modules...");
1019 STOPWATCH("Semantic check");
1024 if (verb_level
> 7) modules
->dump();
1026 int ret_val
= EXIT_SUCCESS
;
1027 unsigned int error_count
= Error_Context::get_error_count();
1028 if (error_count
> 0) ret_val
= EXIT_FAILURE
;
1030 if (parse_only
|| semantic_check_only
) {
1031 // print detailed statistics
1032 Error_Context::print_error_statistics();
1034 if (error_count
== 0) {
1037 // Ignore SIGPIPE signals
1038 struct sigaction sig_act
;
1039 if (sigaction(SIGPIPE
, NULL
, &sig_act
))
1040 ERROR("System call sigaction() failed when getting signal "
1041 "handling information for %s.", "SIGINT");
1042 sig_act
.sa_handler
= SIG_IGN
;
1043 sig_act
.sa_flags
= 0;
1044 if (sigaction(SIGPIPE
, &sig_act
, NULL
))
1045 ERROR("System call sigaction() failed when disabling signal "
1049 std::stringstream stream
;
1050 stream
<< "compiler";
1051 std::set
<ModuleVersion
> versions
= modules
->getVersionsWithProductNumber();
1052 if (!versions
.empty()) {
1053 stream
<< "&products=";
1054 for (std::set
<ModuleVersion
>::iterator it
= versions
.begin(); it
!= versions
.end(); ++it
) {
1055 if (it
!= versions
.begin()) {
1058 stream
<< it
->toString();
1062 HttpSender
*sender
= new HttpSender
;
1063 UsageData::getInstance().sendDataThreaded(stream
.str(), sender
);
1066 NOTIFY("Generating JSON schema...");
1067 STOPWATCH("Generating JSON schema");
1068 // the Ttcn2Json constructor starts the process
1069 Ttcn::Ttcn2Json
t2j(modules
, json_schema_name
);
1071 NOTIFY("Generating code...");
1072 STOPWATCH("Generating code");
1073 modules
->generate_code(cgh
);
1074 report_nof_updated_files();
1077 NOTIFY("Error%s found in the input module%s. Code will not be generated.",
1078 error_count
> 1 ? "s" : "", n_modules
> 1 ? "s" : "");
1080 modules
->write_checksums();
1086 while (tcov_files
!= NULL
) {
1087 tcov_file_list
*next_file
= tcov_files
->next
;
1088 Free(tcov_files
->file_name
);
1090 tcov_files
= next_file
;
1095 Free(top_level_pdu
);
1096 if (asn1_modules_present
) asn1_free();
1098 Common::Node::chk_counter();
1099 Location::delete_source_file_names();
1100 Free(json_schema_name
);
1102 free_profiler_data();
1105 // dbgnew.hh already does it: check_mem_leak(argv[0]);