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
,
70 implicit_json_encoding
= FALSE
, json_refs_for_all_types
= TRUE
,
71 profiler_enabled
= FALSE
;
73 // Default code splitting mode is set to 'no splitting'.
74 CodeGenHelper::split_type code_splitting_mode
= CodeGenHelper::SPLIT_NONE
;
76 #if defined SOLARIS || defined SOLARIS8
77 /** Automatic detection of Solaris version based on uname() system call.
78 * Distinguishing is needed because some socket functions use socklen_t
79 * (which is an alias for unsigned int) as length arguments on Solaris 8.
80 * On Solaris 2.6 the argument type is simply int and no socklen_t or other
82 * Note: It was discovered later that Solaris 7 (which is used rarely within
83 * Ericsson) already uses socklen_t thus the SOLARIS8 platform identifier is a
85 static const char *get_platform_string(void)
89 if (uname(&name
) < 0) {
90 WARNING("System call uname() failed: %s", strerror(errno
));
94 if (sscanf(name
.release
, "%d.%d", &major
, &minor
) == 2 && major
== 5) {
95 if (minor
<= 6) return "SOLARIS";
96 else return "SOLARIS8";
98 ERROR("Invalid OS release: %s", name
.release
);
103 #define get_platform_string() "LINUX"
104 #elif defined FREEBSD
105 #define get_platform_string() "FREEBSD"
107 #define get_platform_string() "WIN32"
108 #elif defined INTERIX
109 #define get_platform_string() "INTERIX"
111 #error Platform was not set.
115 const char *expected_platform
= get_platform_string();
118 Modules
*modules
= NULL
;
120 // Features can be disabled in the license or by commandline switches
121 static bool raw_disabled
= false, ber_disabled
= false, per_disabled
= false,
122 text_disabled
= false, xer_disabled
= false, json_disabled
= false;
123 static bool attribute_validation_disabled
= FALSE
;
125 static bool has_raw_feature
= false, has_ber_feature
= false,
126 has_per_feature
= false, has_text_feature
= false, has_xer_feature
= false;
131 if (raw_disabled
) return FALSE
;
133 if (!has_raw_feature
) {
134 WARNING("The license key does not allow the generation of "
135 "RAW encoder/decoder functions.");
145 if (ber_disabled
) return FALSE
;
147 if (!has_ber_feature
) {
148 WARNING("The license key does not allow the generation of "
149 "BER encoder/decoder functions.");
159 if (per_disabled
) return FALSE
;
161 if (!has_per_feature
) {
162 WARNING("The license key does not allow the generation of "
163 "PER encoder/decoder functions.");
171 boolean
enable_text()
173 if (text_disabled
) return FALSE
;
175 if (!has_text_feature
) {
176 WARNING("The license key does not allow the generation of "
177 "TEXT encoder/decoder functions.");
178 text_disabled
= true;
187 if (xer_disabled
) return FALSE
;
189 if (!has_xer_feature
) {
190 WARNING("The license key does not allow the generation of "
191 "XER encoder/decoder functions.");
199 boolean
enable_json()
201 return !json_disabled
;
204 boolean
disable_attribute_validation()
206 if (attribute_validation_disabled
) return TRUE
;
211 char *canonize_input_file(const char *path_name
)
213 switch (get_path_status(path_name
)) {
215 ERROR("Input file `%s' does not exist.", path_name
);
218 ERROR("Argument `%s' is a directory.", path_name
);
223 char *dir_name
= get_dir_from_path(path_name
);
224 char *abs_dir
= get_absolute_dir(dir_name
, NULL
);
226 char *file_name
= get_file_from_path(path_name
);
227 char *ret_val
= compose_path_name(abs_dir
, file_name
);
233 struct module_struct
{
234 const char *file_name
;
236 Module::moduletype_t module_type
;
237 bool need_codegen
; /**< Code is generated for a module if
238 - the module appears on the command line after the dash, or
239 - there is no dash (code is generated for all modules) */
242 static void add_module(size_t& n_modules
, module_struct
*& module_list
,
243 const char *file_name
, Module::moduletype_t module_type
)
245 char *absolute_path
= canonize_input_file(file_name
);
246 if (absolute_path
== NULL
) return;
247 for (size_t i
= 0; i
< n_modules
; i
++) {
248 const module_struct
*module
= module_list
+ i
;
249 if (module
->module_type
== module_type
&&
250 !strcmp(module
->absolute_path
, absolute_path
)) {
251 ERROR("Input file `%s' was given more than once.", file_name
);
256 module_list
= (module_struct
*)
257 Realloc(module_list
, (n_modules
+ 1) * sizeof(module_struct
));
258 module_struct
*module
= module_list
+ n_modules
;
259 module
->file_name
= file_name
;
260 module
->absolute_path
= absolute_path
;
261 module
->module_type
= module_type
;
262 module
->need_codegen
= false;
266 const char *get_tcov_file_name(const char *file_name
)
268 tcov_file_list
*tcov_file
= tcov_files
;
269 expstring_t file_name_pp
= mputprintf(NULL
, "%spp", file_name
);
270 while (tcov_file
!= NULL
) {
271 // This name can be a `.ttcnpp' too.
272 const char *real_file_name
= static_cast<const char *>(tcov_file
->file_name
);
273 if (!strcmp(file_name
, real_file_name
) ||
274 !strcmp(static_cast<const char *>(file_name_pp
), real_file_name
)) {
276 return real_file_name
;
278 tcov_file
= tcov_file
->next
;
284 boolean
in_tcov_files(const char *file_name
)
286 return get_tcov_file_name(file_name
) ? TRUE
: FALSE
;
289 static bool check_file_list(const char *file_name
, module_struct
*module_list
, size_t n_modules
)
291 FILE *fp
= fopen(file_name
, "r");
293 ERROR("File `%s' does not exist.", file_name
);
297 #define PATH_MAX 1024
300 bool unlisted_files
= false;
301 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
302 // Remove trailing '\n'.
303 size_t line_len
= strlen(line
) - 1;
304 if (line
[line_len
] == '\n')
306 // Handle `.ttcnpp' files in input file.
308 char last
= line
[line_len
- 1];
309 char before_last
= line
[line_len
- 2];
310 if (last
== 'p' && before_last
== 'p')
316 for (; i
< n_modules
; ++i
) {
317 const module_struct
*module
= module_list
+ i
;
318 if (!strncmp(module
->file_name
, line
, line_len
)) {
319 tcov_file_list
*next_file
= new tcov_file_list
;
320 next_file
->next
= tcov_files
;
321 // We'll need the `.ttcnpp' file name.
322 next_file
->file_name
= mcopystr(line
);
323 tcov_files
= next_file
;
327 if (i
== n_modules
) {
328 ERROR("File `%s' was listed in `%s', but not in the command line.",
330 unlisted_files
= true;
334 if (unlisted_files
) {
335 while (tcov_files
!= NULL
) {
336 tcov_file_list
*next_file
= tcov_files
->next
;
337 Free(tcov_files
->file_name
);
339 tcov_files
= next_file
;
343 return !unlisted_files
;
346 static boolean
is_valid_asn1_filename(const char* file_name
)
348 if (0 == strchr(file_name
, '-' )) {
357 "usage: %s [-abcdfgilLOpqrRsStuwxXjy] [-K file] [-V verb_level] [-o dir]\n"
358 " [-U none|type] [-P modulename.top_level_pdu_name] [-Q number] ...\n"
359 " [-T] module.ttcn [-A] module.asn ...\n"
361 " or %s --ttcn2json [-jf] ... [-T] module.ttcn [-A] module.asn ... [- schema.json]\n"
364 " -a: force XER in ASN.1 files\n"
365 " -b: disable BER encoder/decoder functions\n"
366 " -c: write out checksums in case of error\n"
367 " -d: treat default fields as omit\n"
368 " -f: force overwriting of output files\n"
369 " -g: emulate GCC error/warning message format\n"
370 " -i: use only line numbers in error/warning messages\n"
371 " -j: disable JSON encoder/decoder functions\n"
372 " -l: include source line info in C++ code\n"
373 " -L: add source line info for logging\n"
374 " -K file: enable selective code coverage\n"
375 " -o dir: output files will be placed into dir\n"
376 " -p: parse only (no semantic check or code generation)\n"
377 " -P pduname: define top-level pdu\n"
378 " -q: suppress all messages (quiet mode)\n"
379 " -Qn: quit after n errors\n"
380 " -r: disable RAW encoder/decoder functions\n"
381 " -R: use function test runtime (TITAN_RUNTIME_2)\n"
382 " -s: parse and semantic check only (no code generation)\n"
383 " -S: suppress context information\n"
384 " -t: generate Test Port skeleton\n"
385 " -u: duplicate underscores in file names\n"
386 " -U none|type: select code splitting mode for the generated C++ code\n"
387 " -V verb_level: set verbosity level bitmask (decimal)\n"
388 " -w: suppress warnings\n"
389 " -x: disable TEXT encoder/decoder functions\n"
390 " -X: disable XER encoder/decoder functions\n"
391 " -y: disable subtype checking\n"
392 " -Y: Enforces legacy behaviour of the \"out\" function parameters (see refguide)\n"
393 //" -z: enable profiling and code coverage for TTCN-3 files\n" - not open to the public yet
394 " -T file: force interpretation of file as TTCN-3 module\n"
395 " -A file: force interpretation of file as ASN.1 module\n"
396 " -v: show version\n"
397 " --ttcn2json: generate JSON schema from input modules\n"
398 "JSON schema generator options:\n"
399 " -j: only include types with JSON encoding\n"
400 " -f: only generate references to types with JSON encoding/decoding functions\n", argv0
, argv0
, argv0
);
403 #define SET_FLAG(x) if (x##flag) {\
404 ERROR("Flag -" #x " was specified more than once.");\
406 } else x##flag = true
409 extern int ttcn3_debug
;
410 extern int asn1_yydebug
;
411 extern int pattern_yydebug
;
412 extern int pattern_unidebug
;
413 extern int rawAST_debug
;
414 extern int coding_attrib_debug
;
416 int main(int argc
, char *argv
[])
420 asn1_yydebug
= !! getenv("DEBUG_ASN1");
421 ttcn3_debug
= !! getenv("DEBUG_TTCN");
422 pattern_unidebug
= pattern_yydebug
= !! getenv("DEBUG_PATTERN");
423 rawAST_debug
= !! getenv("DEBUG_RAW");
424 coding_attrib_debug
= !!getenv("DEBUG_ATRIB") || getenv("DEBUG_ATTRIB");
428 #if defined(__CYGWIN__) || defined(INTERIX)
431 debug_new_counter
.set_program_name(argv0
);
436 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version "
437 PRODUCT_NUMBER
"\n", stderr
);
443 Aflag
= false, Lflag
= false, Yflag
= false,
444 Pflag
= false, Tflag
= false, Vflag
= false, bflag
= false,
445 cflag
= false, fflag
= false, iflag
= false, lflag
= false,
446 oflag
= false, pflag
= false, qflag
= false, rflag
= false, sflag
= false,
447 tflag
= false, uflag
= false, vflag
= false, wflag
= false, xflag
= false,
448 dflag
= false, Xflag
= false, Rflag
= false, gflag
= false, aflag
= false,
449 s0flag
= false, Cflag
= false, yflag
= false, Uflag
= false, Qflag
= false,
450 Sflag
= false, Kflag
= false, jflag
= false, zflag
= false,
451 errflag
= false, print_usage
= false, ttcn2json
= false;
455 bool asn1_modules_present
= false;
457 bool ttcn3_modules_present
= false;
459 size_t n_modules
= 0;
460 module_struct
*module_list
= NULL
;
461 char* json_schema_name
= NULL
;
463 if (0 == strcmp(argv
[1], "--ttcn2json")) {
465 display_up_to_date
= TRUE
;
466 implicit_json_encoding
= TRUE
;
467 for (int i
= 2; i
< argc
; ++i
) {
468 // A dash (-) is used to separate the schema file name from the input files
469 if (0 == strcmp(argv
[i
], "-")) {
471 json_schema_name
= mcopystr(argv
[i
+ 1]);
473 ERROR("Expected JSON schema name (1 argument) after option `--ttcn2json' and `-'");
478 else if (0 == strcmp(argv
[i
], "-A")) {
481 ERROR("Option `-A' must be followed by an ASN.1 file name");
485 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_ASN
);
486 asn1_modules_present
= true;
488 else if (0 == strcmp(argv
[i
], "-T")) {
491 ERROR("Option `-T' must be followed by a TTCN-3 file name");
495 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_TTCN
);
497 else if (0 == strcmp(argv
[i
], "-j")) {
498 implicit_json_encoding
= FALSE
;
500 else if (0 == strcmp(argv
[i
], "-f")) {
501 json_refs_for_all_types
= FALSE
;
503 else if (0 == strcmp(argv
[i
], "-fj") || 0 == strcmp(argv
[i
], "-jf")) {
504 implicit_json_encoding
= FALSE
;
505 json_refs_for_all_types
= FALSE
;
507 else if (argv
[i
][0] == '-') {
508 ERROR("Invalid option `%s' after option `--ttcn2json'", argv
[i
]);
514 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
518 if (!errflag
&& 0 == n_modules
) {
519 ERROR("No TTCN-3 or ASN.1 modules specified after option `--ttcn2json'");
524 if (!errflag
&& NULL
== json_schema_name
) {
525 // Create the schema name using the first TTCN-3 or ASN.1 file's name
526 const module_struct
& first
= module_list
[0];
527 if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 4, ".asn", 4)) {
528 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 4);
529 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
531 else if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 5, ".ttcn", 5)) {
532 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 5);
533 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
536 json_schema_name
= mprintf("%s.json", first
.file_name
);
543 int c
= getopt(argc
, argv
, "aA:C:K:LP:T:V:bcdfgilo:YpqQ:rRs0StuU:vwxXjyz-");
552 add_module(n_modules
, module_list
, optarg
, Module::MOD_ASN
);
553 asn1_modules_present
= true;
557 expected_platform
= optarg
;
561 include_location_info
= TRUE
;
565 nof_top_level_pdus
++;
566 top_level_pdu
=(const char**)
567 Realloc(top_level_pdu
, nof_top_level_pdus
*sizeof(*top_level_pdu
));
568 top_level_pdu
[nof_top_level_pdus
-1] = optarg
;
572 add_module(n_modules
, module_list
, optarg
, Module::MOD_TTCN
);
574 ttcn3_modules_present
= true;
579 /* set verbosity level bitmask */
580 if (isdigit(optarg
[0])) {
581 verb_level
= atoi(optarg
);
582 // don't bother with overflow
585 ERROR("Option `-V' requires a decimal number as argument instead of "
599 default_as_optional
= TRUE
;
603 force_overwrite
= TRUE
;
611 output_only_linenum
= TRUE
;
615 tcov_file_name
= optarg
;
619 include_line_info
= TRUE
;
627 enable_set_bound_out_param
= TRUE
;
635 /* quiet; suppress all message */
644 use_runtime_2
= TRUE
;
648 semantic_check_only
= TRUE
;
652 suppress_context
= TRUE
;
656 attribute_validation_disabled
= TRUE
;
660 generate_skeleton
= TRUE
;
664 duplicate_underscores
= TRUE
;
668 if (!cgh
.set_split_mode(optarg
)) {
669 ERROR("Wrong code splitting option: '%s'. Valid values are: 'none', "
679 /* suppress warnings and "not supported" messages */
680 verb_level
&= ~(1|2);
684 text_disabled
= TRUE
;
692 json_disabled
= TRUE
;
696 check_subtype
= FALSE
;
700 profiler_enabled
= TRUE
;
706 printf("Q: %s\n", optarg
);
709 max_errs
= strtol(optarg
, (char**)NULL
, 10);
711 || (long)(int)max_errs
!= max_errs
) { // does not fit into int
712 ERROR("Invalid value %s: %s", optarg
, strerror(errno
));
715 else if (max_errs
< 0) {
716 ERROR("Negative value %s not allowed", optarg
);
720 if (max_errs
== 0) max_errs
= 1;
723 Error_Context::set_max_errors(max_errs
);
727 if (!strcmp(argv
[optind
], "--ttcn2json")) {
728 ERROR("Option `--ttcn2json' is only allowed as the first option");
730 ERROR("Invalid option: `%s'", argv
[optind
]);
741 /* Checking incompatible options */
743 if (Aflag
|| Lflag
|| Pflag
|| Tflag
|| Vflag
|| Yflag
||
744 bflag
|| fflag
|| iflag
|| lflag
|| oflag
|| pflag
|| qflag
||
745 rflag
|| sflag
|| tflag
|| uflag
|| wflag
|| xflag
|| Xflag
|| Rflag
||
746 Uflag
|| yflag
|| Kflag
|| jflag
|| zflag
) {
753 ERROR("Options `-p' and `-s' are incompatible with each other.");
754 // totally confusing: exit immediately
758 if (Kflag
&& !Lflag
) {
759 ERROR("Source line information `-L' is necessary for code coverage `-K'.");
762 if (zflag
&& !Lflag
) {
763 ERROR("Source line information `-L' is necessary for profiling `-z'.");
766 if (iflag
&& gflag
) {
767 WARNING("Option `-g' overrides `-i'.");
768 iflag
= false; // -g gives more information
770 if (oflag
&& get_path_status(output_dir
) != PS_DIRECTORY
) {
771 ERROR("The argument of -o switch (`%s') must be a directory.",
775 if (optind
== argc
&& n_modules
== 0) {
776 ERROR("No input TTCN-3 or ASN.1 module was given.");
783 if (print_usage
) usage();
784 Free(json_schema_name
);
789 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor\n"
790 "Product number: " PRODUCT_NUMBER
"\n"
791 "Build date: " __DATE__
" " __TIME__
"\n"
792 "Compiled with: " C_COMPILER_VERSION
"\n\n"
793 COPYRIGHT_STRING
"\n\n", stderr
);
795 print_license_info();
796 fputs("\nUsing ", stderr
);
797 fputs(openssl_version_str(), stderr
);
798 fputs("\n\n", stderr
);
807 int license_valid
= verify_license(&lstr
);
809 if (!license_valid
) {
816 /* the position of '-' switch in argv list */
817 int dash_position
= -1;
819 /* Add the remaining files until switch '-' to the module_list */
820 for(int i
= optind
; i
< argc
; i
++) {
821 if (strcmp(argv
[i
], "-"))
822 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
829 if (dash_position
== -1) {
830 /** if '-' was not present in the command line code should be generated for
832 for (size_t i
= 0; i
< n_modules
; i
++) module_list
[i
].need_codegen
= true;
834 for (int i
= dash_position
+ 1; i
< argc
; i
++) {
835 char *absolute_path
= canonize_input_file(argv
[i
]);
836 if (absolute_path
== NULL
) continue;
838 for (size_t j
= 0; j
< n_modules
; j
++) {
839 module_struct
*module
= module_list
+ j
;
840 if (!strcmp(module
->absolute_path
, absolute_path
)) {
841 module
->need_codegen
= true;
843 // do not stop: the same file may be present on the list twice
844 // (as both ASN.1 and TTCN-3 module)
849 ERROR("File `%s' was not given before the `-' switch for selective "
850 "code generation.", argv
[i
]);
851 // go further (i.e. check all files after the `-')
858 STOPWATCH("Determining module types");
859 // check the readability of all files and
860 // determine the type of unknown modules
861 for (size_t i
= 0; i
< n_modules
; i
++) {
862 module_struct
*module
= module_list
+ i
;
863 FILE *fp
= fopen(module
->file_name
, "r");
865 if (module
->module_type
== Module::MOD_UNKNOWN
) {
866 // try the ASN.1 and TTCN-3 preparsers
867 boolean asn1_module
= is_asn1_module(module
->file_name
, fp
, NULL
);
868 boolean ttcn3_module
= is_ttcn3_module(module
->file_name
, fp
, NULL
);
870 if (!is_valid_asn1_filename (module
->file_name
)) {
871 ERROR("The file name (without suffix) shall be identical to the module name.\n"
872 "If the name of the ASN.1 module contains a hyphen, the corresponding "
873 "file name shall contain an underscore character instead.");
876 ERROR("File `%s' looks so strange that it can contain both an "
877 "ASN.1 and a TTCN-3 module. Use the command-line switch `-A' or "
878 "`-T' to set its type.", module
->file_name
);
881 for (size_t j
= 0; j
< n_modules
; j
++) {
882 module_struct
*module2
= module_list
+ j
;
883 if (module2
->module_type
== Module::MOD_ASN
&&
884 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
890 ERROR("Input file `%s' was given more than once.",
893 module
->module_type
= Module::MOD_ASN
;
894 asn1_modules_present
= true;
897 } else if (ttcn3_module
) {
899 for (size_t j
= 0; j
< n_modules
; j
++) {
900 module_struct
*module2
= module_list
+ j
;
901 if (module2
->module_type
== Module::MOD_TTCN
&&
902 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
908 ERROR("Input file `%s' was given more than once.",
911 module
->module_type
= Module::MOD_TTCN
;
913 ttcn3_modules_present
= true;
917 ERROR("Cannot recognize file `%s' as an ASN.1 or TTCN-3 module. "
918 "Use the command-line switch `-A' or `-T' to set its type.",
924 ERROR("Cannot open input file `%s' for reading: %s", module
->file_name
,
927 // do not invoke the real parsers on that file
928 module
->module_type
= Module::MOD_UNKNOWN
;
934 if (!semantic_check_only
) {
935 NOTIFY("On native win32 builds code generation is disabled.");
936 semantic_check_only
= TRUE
;
940 /* Checking of required license features */
941 if (asn1_modules_present
&& !check_feature(&lstr
, FEATURE_ASN1
)) {
942 ERROR("The license key does not allow the parsing of "
946 if (ttcn3_modules_present
&& !check_feature(&lstr
, FEATURE_TTCN3
)) {
947 ERROR("The license key does not allow the parsing of "
951 if (!parse_only
&& !semantic_check_only
&&
952 !check_feature(&lstr
, FEATURE_CODEGEN
)) {
953 WARNING("The license key does not allow the generation of "
955 semantic_check_only
= TRUE
;
957 if (generate_skeleton
&& !check_feature(&lstr
, FEATURE_TPGEN
)) {
958 WARNING("The license key does not allow the generation of "
959 "Test Port skeletons.");
960 generate_skeleton
= FALSE
;
962 has_raw_feature
= check_feature(&lstr
, FEATURE_RAW
);
963 has_ber_feature
= check_feature(&lstr
, FEATURE_BER
);
964 has_per_feature
= check_feature(&lstr
, FEATURE_PER
);
965 has_text_feature
= check_feature(&lstr
, FEATURE_TEXT
);
966 has_xer_feature
= check_feature(&lstr
, FEATURE_XER
);
969 if (Kflag
&& !check_file_list(tcov_file_name
, module_list
, n_modules
)) {
970 ERROR("Error while processing `%s' provided for code coverage data "
971 "generation.", tcov_file_name
);
975 STOPWATCH("Parsing modules");
978 if (asn1_modules_present
) asn1_init();
979 modules
= new Common::Modules();
981 for (size_t i
= 0; i
< n_modules
; i
++) {
982 const module_struct
*module
= module_list
+ i
;
983 switch (module
->module_type
) {
984 case Module::MOD_ASN
:
985 asn1_parse_file(module
->file_name
, module
->need_codegen
);
987 case Module::MOD_TTCN
:
988 ttcn3_parse_file(module
->file_name
, module
->need_codegen
);
990 default: // MOD_UNKNOWN ?
995 for (size_t i
= 0; i
< n_modules
; i
++) Free(module_list
[i
].absolute_path
);
999 if (!parse_only
&& 0 == Error_Context::get_error_count()) {
1000 NOTIFY("Checking modules...");
1002 STOPWATCH("Semantic check");
1007 if (verb_level
> 7) modules
->dump();
1009 int ret_val
= EXIT_SUCCESS
;
1010 unsigned int error_count
= Error_Context::get_error_count();
1011 if (error_count
> 0) ret_val
= EXIT_FAILURE
;
1013 if (parse_only
|| semantic_check_only
) {
1014 // print detailed statistics
1015 Error_Context::print_error_statistics();
1017 if (error_count
== 0) {
1020 // Ignore SIGPIPE signals
1021 struct sigaction sig_act
;
1022 if (sigaction(SIGPIPE
, NULL
, &sig_act
))
1023 ERROR("System call sigaction() failed when getting signal "
1024 "handling information for %s.", "SIGINT");
1025 sig_act
.sa_handler
= SIG_IGN
;
1026 sig_act
.sa_flags
= 0;
1027 if (sigaction(SIGPIPE
, &sig_act
, NULL
))
1028 ERROR("System call sigaction() failed when disabling signal "
1032 std::stringstream stream
;
1033 stream
<< "compiler";
1034 std::set
<ModuleVersion
> versions
= modules
->getVersionsWithProductNumber();
1035 if (!versions
.empty()) {
1036 stream
<< "&products=";
1037 for (std::set
<ModuleVersion
>::iterator it
= versions
.begin(); it
!= versions
.end(); ++it
) {
1038 if (it
!= versions
.begin()) {
1041 stream
<< it
->toString();
1045 HttpSender
*sender
= new HttpSender
;
1046 UsageData::getInstance().sendDataThreaded(stream
.str(), sender
);
1049 NOTIFY("Generating JSON schema...");
1050 STOPWATCH("Generating JSON schema");
1051 // the Ttcn2Json constructor starts the process
1052 Ttcn::Ttcn2Json
t2j(modules
, json_schema_name
);
1054 NOTIFY("Generating code...");
1055 STOPWATCH("Generating code");
1056 modules
->generate_code(cgh
);
1057 report_nof_updated_files();
1060 NOTIFY("Error%s found in the input module%s. Code will not be generated.",
1061 error_count
> 1 ? "s" : "", n_modules
> 1 ? "s" : "");
1063 modules
->write_checksums();
1069 while (tcov_files
!= NULL
) {
1070 tcov_file_list
*next_file
= tcov_files
->next
;
1071 Free(tcov_files
->file_name
);
1073 tcov_files
= next_file
;
1078 Free(top_level_pdu
);
1079 if (asn1_modules_present
) asn1_free();
1081 Common::Node::chk_counter();
1082 Location::delete_source_file_names();
1083 Free(json_schema_name
);
1085 // dbgnew.hh already does it: check_mem_leak(argv[0]);