1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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
, omit_in_value_list
= 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 // only check the actual file name, not the whole path
353 const char* file_name_start
= strrchr(file_name
, '/');
354 if (0 == strchr(file_name_start
!= NULL
? file_name_start
: file_name
, '-' )) {
363 "usage: %s [-abcdfgijlLOpqrRsStuwxXyY] [-K file] [-z file] [-V verb_level]\n"
364 " [-o dir] [-U none|type] [-P modulename.top_level_pdu_name] [-Q number] ...\n"
365 " [-T] module.ttcn [-A] module.asn ...\n"
367 " or %s --ttcn2json [-jf] ... [-T] module.ttcn [-A] module.asn ... [- schema.json]\n"
370 " -a: force XER in ASN.1 files\n"
371 " -b: disable BER encoder/decoder functions\n"
372 " -c: write out checksums in case of error\n"
373 " -d: treat default fields as omit\n"
374 " -f: force overwriting of output files\n"
375 " -g: emulate GCC error/warning message format\n"
376 " -i: use only line numbers in error/warning messages\n"
377 " -j: disable JSON encoder/decoder functions\n"
378 " -K file: enable selective code coverage\n"
379 " -l: include source line info in C++ code\n"
380 " -L: add source line info for logging\n"
381 " -M: allow 'omit' in template value lists (legacy behavior)\n"
382 " -o dir: output files will be placed into dir\n"
383 " -p: parse only (no semantic check or code generation)\n"
384 " -P pduname: define top-level pdu\n"
385 " -q: suppress all messages (quiet mode)\n"
386 " -Qn: quit after n errors\n"
387 " -r: disable RAW encoder/decoder functions\n"
388 " -R: use function test runtime (TITAN_RUNTIME_2)\n"
389 " -s: parse and semantic check only (no code generation)\n"
390 " -S: suppress context information\n"
391 " -t: generate Test Port skeleton\n"
392 " -u: duplicate underscores in file names\n"
393 " -U none|type: select code splitting mode for the generated C++ code\n"
394 " -V verb_level: set verbosity level bitmask (decimal)\n"
395 " -w: suppress warnings\n"
396 " -x: disable TEXT encoder/decoder functions\n"
397 " -X: disable XER encoder/decoder functions\n"
398 " -y: disable subtype checking\n"
399 " -Y: enforce legacy behaviour for \"out\" function parameters (see refguide)\n"
400 " -z file: enable profiling and code coverage for the TTCN-3 files in the argument\n"
401 " -T file: force interpretation of file as TTCN-3 module\n"
402 " -A file: force interpretation of file as ASN.1 module\n"
403 " -v: show version\n"
404 " --ttcn2json: generate JSON schema from input modules\n"
405 "JSON schema generator options:\n"
406 " -j: only include types with JSON encoding\n"
407 " -f: only generate references to types with JSON encoding/decoding functions\n", argv0
, argv0
, argv0
);
410 #define SET_FLAG(x) if (x##flag) {\
411 ERROR("Flag -" #x " was specified more than once.");\
413 } else x##flag = true
416 extern int ttcn3_debug
;
417 extern int asn1_yydebug
;
418 extern int pattern_yydebug
;
419 extern int pattern_unidebug
;
420 extern int rawAST_debug
;
421 extern int coding_attrib_debug
;
423 int main(int argc
, char *argv
[])
427 asn1_yydebug
= !! getenv("DEBUG_ASN1");
428 ttcn3_debug
= !! getenv("DEBUG_TTCN");
429 pattern_unidebug
= pattern_yydebug
= !! getenv("DEBUG_PATTERN");
430 rawAST_debug
= !! getenv("DEBUG_RAW");
431 coding_attrib_debug
= !!getenv("DEBUG_ATRIB") || getenv("DEBUG_ATTRIB");
435 #if defined(__CYGWIN__) || defined(INTERIX)
438 debug_new_counter
.set_program_name(argv0
);
443 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor, version "
444 PRODUCT_NUMBER
"\n", stderr
);
450 Aflag
= false, Lflag
= false, Yflag
= false,
451 Pflag
= false, Tflag
= false, Vflag
= false, bflag
= false,
452 cflag
= false, fflag
= false, iflag
= false, lflag
= false,
453 oflag
= false, pflag
= false, qflag
= false, rflag
= false, sflag
= false,
454 tflag
= false, uflag
= false, vflag
= false, wflag
= false, xflag
= false,
455 dflag
= false, Xflag
= false, Rflag
= false, gflag
= false, aflag
= false,
456 s0flag
= false, Cflag
= false, yflag
= false, Uflag
= false, Qflag
= false,
457 Sflag
= false, Kflag
= false, jflag
= false, zflag
= false, Fflag
= false,
458 Mflag
= false, errflag
= false, print_usage
= false, ttcn2json
= false;
462 bool asn1_modules_present
= false;
464 bool ttcn3_modules_present
= false;
466 size_t n_modules
= 0;
467 module_struct
*module_list
= NULL
;
468 char* json_schema_name
= NULL
;
470 if (0 == strcmp(argv
[1], "--ttcn2json")) {
472 display_up_to_date
= TRUE
;
473 implicit_json_encoding
= TRUE
;
474 for (int i
= 2; i
< argc
; ++i
) {
475 // A dash (-) is used to separate the schema file name from the input files
476 if (0 == strcmp(argv
[i
], "-")) {
478 json_schema_name
= mcopystr(argv
[i
+ 1]);
480 ERROR("Expected JSON schema name (1 argument) after option `--ttcn2json' and `-'");
485 else if (0 == strcmp(argv
[i
], "-A")) {
488 ERROR("Option `-A' must be followed by an ASN.1 file name");
492 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_ASN
);
493 asn1_modules_present
= true;
495 else if (0 == strcmp(argv
[i
], "-T")) {
498 ERROR("Option `-T' must be followed by a TTCN-3 file name");
502 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_TTCN
);
504 else if (0 == strcmp(argv
[i
], "-j")) {
505 implicit_json_encoding
= FALSE
;
507 else if (0 == strcmp(argv
[i
], "-f")) {
508 json_refs_for_all_types
= FALSE
;
510 else if (0 == strcmp(argv
[i
], "-fj") || 0 == strcmp(argv
[i
], "-jf")) {
511 implicit_json_encoding
= FALSE
;
512 json_refs_for_all_types
= FALSE
;
514 else if (argv
[i
][0] == '-') {
515 ERROR("Invalid option `%s' after option `--ttcn2json'", argv
[i
]);
521 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
525 if (!errflag
&& 0 == n_modules
) {
526 ERROR("No TTCN-3 or ASN.1 modules specified after option `--ttcn2json'");
531 if (!errflag
&& NULL
== json_schema_name
) {
532 // Create the schema name using the first TTCN-3 or ASN.1 file's name
533 const module_struct
& first
= module_list
[0];
534 if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 4, ".asn", 4)) {
535 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 4);
536 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
538 else if (0 == strncmp(first
.file_name
+ strlen(first
.file_name
) - 5, ".ttcn", 5)) {
539 json_schema_name
= mcopystrn(first
.file_name
, strlen(first
.file_name
) - 5);
540 json_schema_name
= mputstrn(json_schema_name
, ".json", 5);
543 json_schema_name
= mprintf("%s.json", first
.file_name
);
550 int c
= getopt(argc
, argv
, "aA:C:K:LP:T:V:bcdfFgilMo:YpqQ:rRs0StuU:vwxXjyz:-");
559 add_module(n_modules
, module_list
, optarg
, Module::MOD_ASN
);
560 asn1_modules_present
= true;
564 expected_platform
= optarg
;
568 include_location_info
= TRUE
;
572 nof_top_level_pdus
++;
573 top_level_pdu
=(const char**)
574 Realloc(top_level_pdu
, nof_top_level_pdus
*sizeof(*top_level_pdu
));
575 top_level_pdu
[nof_top_level_pdus
-1] = optarg
;
579 add_module(n_modules
, module_list
, optarg
, Module::MOD_TTCN
);
581 ttcn3_modules_present
= true;
586 /* set verbosity level bitmask */
587 if (isdigit(optarg
[0])) {
588 verb_level
= atoi(optarg
);
589 // don't bother with overflow
592 ERROR("Option `-V' requires a decimal number as argument instead of "
606 default_as_optional
= TRUE
;
610 force_overwrite
= TRUE
;
618 output_only_linenum
= TRUE
;
622 tcov_file_name
= optarg
;
626 include_line_info
= TRUE
;
634 enable_set_bound_out_param
= TRUE
;
642 /* quiet; suppress all message */
651 use_runtime_2
= TRUE
;
655 semantic_check_only
= TRUE
;
659 suppress_context
= TRUE
;
663 attribute_validation_disabled
= TRUE
;
667 generate_skeleton
= TRUE
;
671 duplicate_underscores
= TRUE
;
675 if (!cgh
.set_split_mode(optarg
)) {
676 ERROR("Wrong code splitting option: '%s'. Valid values are: 'none', "
686 /* suppress warnings and "not supported" messages */
687 verb_level
&= ~(1|2);
691 text_disabled
= TRUE
;
699 json_disabled
= TRUE
;
703 check_subtype
= FALSE
;
707 profiler_file_name
= optarg
;
711 force_gen_seof
= TRUE
;
715 omit_in_value_list
= TRUE
;
721 printf("Q: %s\n", optarg
);
724 max_errs
= strtol(optarg
, (char**)NULL
, 10);
726 || (long)(int)max_errs
!= max_errs
) { // does not fit into int
727 ERROR("Invalid value %s: %s", optarg
, strerror(errno
));
730 else if (max_errs
< 0) {
731 ERROR("Negative value %s not allowed", optarg
);
735 if (max_errs
== 0) max_errs
= 1;
738 Error_Context::set_max_errors(max_errs
);
742 if (!strcmp(argv
[optind
], "--ttcn2json")) {
743 ERROR("Option `--ttcn2json' is only allowed as the first option");
745 ERROR("Invalid option: `%s'", argv
[optind
]);
756 /* Checking incompatible options */
758 if (Aflag
|| Lflag
|| Pflag
|| Tflag
|| Vflag
|| Yflag
||
759 bflag
|| fflag
|| iflag
|| lflag
|| oflag
|| pflag
|| qflag
||
760 rflag
|| sflag
|| tflag
|| uflag
|| wflag
|| xflag
|| Xflag
|| Rflag
||
761 Uflag
|| yflag
|| Kflag
|| jflag
|| zflag
|| Fflag
|| Mflag
) {
768 ERROR("Options `-p' and `-s' are incompatible with each other.");
769 // totally confusing: exit immediately
773 if (Kflag
&& !Lflag
) {
774 ERROR("Source line information `-L' is necessary for code coverage `-K'.");
777 if (zflag
&& !Lflag
) {
778 ERROR("Source line information `-L' is necessary for profiling `-z'.");
781 if (iflag
&& gflag
) {
782 WARNING("Option `-g' overrides `-i'.");
783 iflag
= false; // -g gives more information
785 if (oflag
&& get_path_status(output_dir
) != PS_DIRECTORY
) {
786 ERROR("The argument of -o switch (`%s') must be a directory.",
790 if (optind
== argc
&& n_modules
== 0) {
791 ERROR("No input TTCN-3 or ASN.1 module was given.");
798 if (print_usage
) usage();
799 Free(json_schema_name
);
804 fputs("TTCN-3 and ASN.1 Compiler for the TTCN-3 Test Executor\n"
805 "Product number: " PRODUCT_NUMBER
"\n"
806 "Build date: " __DATE__
" " __TIME__
"\n"
807 "Compiled with: " C_COMPILER_VERSION
"\n\n"
808 COPYRIGHT_STRING
"\n\n", stderr
);
810 print_license_info();
811 fputs("\nUsing ", stderr
);
812 fputs(openssl_version_str(), stderr
);
813 fputs("\n\n", stderr
);
822 int license_valid
= verify_license(&lstr
);
824 if (!license_valid
) {
831 /* the position of '-' switch in argv list */
832 int dash_position
= -1;
834 /* Add the remaining files until switch '-' to the module_list */
835 for(int i
= optind
; i
< argc
; i
++) {
836 if (strcmp(argv
[i
], "-"))
837 add_module(n_modules
, module_list
, argv
[i
], Module::MOD_UNKNOWN
);
844 if (dash_position
== -1) {
845 /** if '-' was not present in the command line code should be generated for
847 for (size_t i
= 0; i
< n_modules
; i
++) module_list
[i
].need_codegen
= true;
849 for (int i
= dash_position
+ 1; i
< argc
; i
++) {
850 char *absolute_path
= canonize_input_file(argv
[i
]);
851 if (absolute_path
== NULL
) continue;
853 for (size_t j
= 0; j
< n_modules
; j
++) {
854 module_struct
*module
= module_list
+ j
;
855 if (!strcmp(module
->absolute_path
, absolute_path
)) {
856 module
->need_codegen
= true;
858 // do not stop: the same file may be present on the list twice
859 // (as both ASN.1 and TTCN-3 module)
864 ERROR("File `%s' was not given before the `-' switch for selective "
865 "code generation.", argv
[i
]);
866 // go further (i.e. check all files after the `-')
873 STOPWATCH("Determining module types");
874 // check the readability of all files and
875 // determine the type of unknown modules
876 for (size_t i
= 0; i
< n_modules
; i
++) {
877 module_struct
*module
= module_list
+ i
;
878 FILE *fp
= fopen(module
->file_name
, "r");
880 if (module
->module_type
== Module::MOD_UNKNOWN
) {
881 // try the ASN.1 and TTCN-3 preparsers
882 boolean asn1_module
= is_asn1_module(module
->file_name
, fp
, NULL
);
883 boolean ttcn3_module
= is_ttcn3_module(module
->file_name
, fp
, NULL
);
885 if (!is_valid_asn1_filename (module
->file_name
)) {
886 ERROR("The file name (without suffix) shall be identical to the module name.\n"
887 "If the name of the ASN.1 module contains a hyphen, the corresponding "
888 "file name shall contain an underscore character instead.");
891 ERROR("File `%s' looks so strange that it can contain both an "
892 "ASN.1 and a TTCN-3 module. Use the command-line switch `-A' or "
893 "`-T' to set its type.", module
->file_name
);
896 for (size_t j
= 0; j
< n_modules
; j
++) {
897 module_struct
*module2
= module_list
+ j
;
898 if (module2
->module_type
== Module::MOD_ASN
&&
899 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
905 ERROR("Input file `%s' was given more than once.",
908 module
->module_type
= Module::MOD_ASN
;
909 asn1_modules_present
= true;
912 } else if (ttcn3_module
) {
914 for (size_t j
= 0; j
< n_modules
; j
++) {
915 module_struct
*module2
= module_list
+ j
;
916 if (module2
->module_type
== Module::MOD_TTCN
&&
917 !strcmp(module
->absolute_path
, module2
->absolute_path
)) {
923 ERROR("Input file `%s' was given more than once.",
926 module
->module_type
= Module::MOD_TTCN
;
928 ttcn3_modules_present
= true;
932 ERROR("Cannot recognize file `%s' as an ASN.1 or TTCN-3 module. "
933 "Use the command-line switch `-A' or `-T' to set its type.",
939 ERROR("Cannot open input file `%s' for reading: %s", module
->file_name
,
942 // do not invoke the real parsers on that file
943 module
->module_type
= Module::MOD_UNKNOWN
;
949 if (!semantic_check_only
) {
950 NOTIFY("On native win32 builds code generation is disabled.");
951 semantic_check_only
= TRUE
;
955 /* Checking of required license features */
956 if (asn1_modules_present
&& !check_feature(&lstr
, FEATURE_ASN1
)) {
957 ERROR("The license key does not allow the parsing of "
961 if (ttcn3_modules_present
&& !check_feature(&lstr
, FEATURE_TTCN3
)) {
962 ERROR("The license key does not allow the parsing of "
966 if (!parse_only
&& !semantic_check_only
&&
967 !check_feature(&lstr
, FEATURE_CODEGEN
)) {
968 WARNING("The license key does not allow the generation of "
970 semantic_check_only
= TRUE
;
972 if (generate_skeleton
&& !check_feature(&lstr
, FEATURE_TPGEN
)) {
973 WARNING("The license key does not allow the generation of "
974 "Test Port skeletons.");
975 generate_skeleton
= FALSE
;
977 has_raw_feature
= check_feature(&lstr
, FEATURE_RAW
);
978 has_ber_feature
= check_feature(&lstr
, FEATURE_BER
);
979 has_per_feature
= check_feature(&lstr
, FEATURE_PER
);
980 has_text_feature
= check_feature(&lstr
, FEATURE_TEXT
);
981 has_xer_feature
= check_feature(&lstr
, FEATURE_XER
);
984 if (Kflag
&& !check_file_list(tcov_file_name
, module_list
, n_modules
, tcov_files
)) {
985 ERROR("Error while processing `%s' provided for code coverage data "
986 "generation.", tcov_file_name
);
990 tcov_file_list
*file_list_head
= NULL
;
991 if(!check_file_list(profiler_file_name
, module_list
, n_modules
, file_list_head
)) {
992 ERROR("Error while processing `%s' provided for profiling and code coverage.",
996 init_profiler_data(file_list_head
);
999 STOPWATCH("Parsing modules");
1002 if (asn1_modules_present
) asn1_init();
1003 modules
= new Common::Modules();
1005 for (size_t i
= 0; i
< n_modules
; i
++) {
1006 const module_struct
*module
= module_list
+ i
;
1007 switch (module
->module_type
) {
1008 case Module::MOD_ASN
:
1009 asn1_parse_file(module
->file_name
, module
->need_codegen
);
1011 case Module::MOD_TTCN
:
1012 ttcn3_parse_file(module
->file_name
, module
->need_codegen
);
1014 default: // MOD_UNKNOWN ?
1019 for (size_t i
= 0; i
< n_modules
; i
++) Free(module_list
[i
].absolute_path
);
1023 if (!parse_only
&& 0 == Error_Context::get_error_count()) {
1024 NOTIFY("Checking modules...");
1026 STOPWATCH("Semantic check");
1031 if (verb_level
> 7) modules
->dump();
1033 int ret_val
= EXIT_SUCCESS
;
1034 unsigned int error_count
= Error_Context::get_error_count();
1035 if (error_count
> 0) ret_val
= EXIT_FAILURE
;
1037 if (parse_only
|| semantic_check_only
) {
1038 // print detailed statistics
1039 Error_Context::print_error_statistics();
1041 if (error_count
== 0) {
1044 // Ignore SIGPIPE signals
1045 struct sigaction sig_act
;
1046 if (sigaction(SIGPIPE
, NULL
, &sig_act
))
1047 ERROR("System call sigaction() failed when getting signal "
1048 "handling information for %s.", "SIGINT");
1049 sig_act
.sa_handler
= SIG_IGN
;
1050 sig_act
.sa_flags
= 0;
1051 if (sigaction(SIGPIPE
, &sig_act
, NULL
))
1052 ERROR("System call sigaction() failed when disabling signal "
1056 std::stringstream stream
;
1057 stream
<< "compiler";
1058 std::set
<ModuleVersion
> versions
= modules
->getVersionsWithProductNumber();
1059 if (!versions
.empty()) {
1060 stream
<< "&products=";
1061 for (std::set
<ModuleVersion
>::iterator it
= versions
.begin(); it
!= versions
.end(); ++it
) {
1062 if (it
!= versions
.begin()) {
1065 stream
<< it
->toString();
1069 HttpSender
*sender
= new HttpSender
;
1070 UsageData::getInstance().sendDataThreaded(stream
.str(), sender
);
1073 NOTIFY("Generating JSON schema...");
1074 STOPWATCH("Generating JSON schema");
1075 // the Ttcn2Json constructor starts the process
1076 Ttcn::Ttcn2Json
t2j(modules
, json_schema_name
);
1078 NOTIFY("Generating code...");
1079 STOPWATCH("Generating code");
1080 modules
->generate_code(cgh
);
1081 report_nof_updated_files();
1084 NOTIFY("Error%s found in the input module%s. Code will not be generated.",
1085 error_count
> 1 ? "s" : "", n_modules
> 1 ? "s" : "");
1087 modules
->write_checksums();
1093 while (tcov_files
!= NULL
) {
1094 tcov_file_list
*next_file
= tcov_files
->next
;
1095 Free(tcov_files
->file_name
);
1097 tcov_files
= next_file
;
1102 Free(top_level_pdu
);
1103 if (asn1_modules_present
) asn1_free();
1105 Common::Node::chk_counter();
1106 Location::delete_source_file_names();
1107 Free(json_schema_name
);
1109 free_profiler_data();
1112 // dbgnew.hh already does it: check_mem_leak(argv[0]);