@@ -3425,16 +3425,12 @@ public function runFrontEnd
34253425 input Boolean relaxedFrontEnd "Do not check for illegal simulation models, so we allow instantation of packages, etc" ;
34263426 input Boolean dumpFlat = false ;
34273427 input Boolean transform = false ;
3428- input Boolean readCommandLineOptions = true ;
34293428 output Option < DAE . DAElist > odae = NONE ();
34303429 output String flatString = "" ;
34313430protected
34323431 DAE . DAElist dae;
34333432 Boolean b;
3434- Flags . Flag flags;
34353433algorithm
3436- flags := if readCommandLineOptions then loadCommandLineOptions(className) else FlagsUtil . loadFlags();
3437-
34383434 // add program to the cache so it can be used to lookup modelica://
34393435 // URIs in external functions IncludeDirectory/LibraryDirectory
34403436 FlagsUtil . setConfigBool(Flags . BUILDING_MODEL , true );
@@ -3459,9 +3455,7 @@ algorithm
34593455 else
34603456 // Return odae=NONE(); needed to update cache and symbol table if we fail
34613457 end try ;
3462-
34633458 FlagsUtil . setConfigBool(Flags . BUILDING_MODEL , false );
3464- FlagsUtil . saveFlags(flags);
34653459end runFrontEnd;
34663460
34673461protected function runFrontEndLoadProgram
@@ -3580,10 +3574,7 @@ protected
35803574 Absyn . Path cls_name = className;
35813575 Obfuscate . Mapping obfuscate_map;
35823576 String obfuscate_mode;
3583- Flags . Flag flags;
35843577algorithm
3585- flags := loadCommandLineOptions(className);
3586-
35873578 (_, builtin_p) := FBuiltin . getInitialFunctions();
35883579 scode_p := SymbolTable . getSCode();
35893580
@@ -3617,9 +3608,7 @@ algorithm
36173608 inst_failed := true ;
36183609 end try ;
36193610
3620- // Restore the flags
36213611 FlagsUtil . set(Flags . NF_API , nf_api);
3622- FlagsUtil . saveFlags(flags);
36233612
36243613 if inst_failed then
36253614 fail();
@@ -3648,6 +3637,10 @@ algorithm
36483637 list< String > libs;
36493638 String file_dir, fileNamePrefix;
36503639 Absyn . Program p;
3640+ Flags . Flag flags;
3641+ String commandLineOptions;
3642+ list< String > args;
3643+ Boolean haveAnnotation;
36513644 SimCode . SimulationSettings simSettings;
36523645 GlobalScript . SimulationOptions defaultSimOpt;
36533646
@@ -3660,8 +3653,32 @@ algorithm
36603653 simSettings := convertSimulationOptionsToSimCode(defaultSimOpt);
36613654 end if ;
36623655
3663- (success, cache, libs, file_dir, resultValues) :=
3664- callTranslateModel(cache, env, className, fileNamePrefix, runBackend, runSilent, SOME (simSettings));
3656+ if Config . ignoreCommandLineOptionsAnnotation() then
3657+ (success, cache, libs, file_dir, resultValues) :=
3658+ callTranslateModel(cache, env, className, fileNamePrefix, runBackend, runSilent, SOME (simSettings));
3659+ else
3660+ // read the __OpenModelica_commandLineOptions
3661+ Absyn . STRING (commandLineOptions) := Interactive . getNamedAnnotationExp(className, SymbolTable . getAbsyn(), Absyn . IDENT
3662+ ("__OpenModelica_commandLineOptions" ), SOME (Absyn . STRING ("" )), Interactive . getAnnotationExp);
3663+ haveAnnotation := boolNot(stringEq(commandLineOptions, "" ));
3664+ // backup the flags.
3665+ flags := if haveAnnotation then FlagsUtil . backupFlags() else FlagsUtil . loadFlags();
3666+ try
3667+ // apply if there are any new flags
3668+ if haveAnnotation then
3669+ args := System . strtok(commandLineOptions, " " );
3670+ FlagsUtil . readArgs(args);
3671+ end if ;
3672+
3673+ (success, cache, libs, file_dir, resultValues) :=
3674+ callTranslateModel(cache, env, className, fileNamePrefix, runBackend, runSilent, SOME (simSettings));
3675+ // reset to the original flags
3676+ FlagsUtil . saveFlags(flags);
3677+ else
3678+ FlagsUtil . saveFlags(flags);
3679+ fail();
3680+ end try ;
3681+ end if ;
36653682 then
36663683 (cache,libs,file_dir,resultValues);
36673684
@@ -4141,6 +4158,10 @@ protected function translateModelFMU
41414158 output Values . Value outValue;
41424159protected
41434160 Absyn . Program p;
4161+ Flags . Flag flags;
4162+ String commandLineOptions;
4163+ list< String > args;
4164+ Boolean haveAnnotation;
41444165algorithm
41454166 // handle encryption
41464167 // if AST contains encrypted class show nothing
@@ -4149,8 +4170,28 @@ algorithm
41494170 Error . addMessage(Error . ACCESS_ENCRYPTED_PROTECTED_CONTENTS , {});
41504171 cache := inCache;
41514172 outValue := Values . STRING ("" );
4152- else
4173+ elseif Config . ignoreCommandLineOptionsAnnotation() then
41534174 (success, cache, outValue) := callTranslateModelFMU(inCache,inEnv,className,FMUVersion ,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
4175+ else
4176+ // read the __OpenModelica_commandLineOptions
4177+ Absyn . STRING (commandLineOptions) := Interactive . getNamedAnnotationExp(className, SymbolTable . getAbsyn(), Absyn . IDENT ("__OpenModelica_commandLineOptions" ), SOME (Absyn . STRING ("" )), Interactive . getAnnotationExp);
4178+ haveAnnotation := boolNot(stringEq(commandLineOptions, "" ));
4179+ // backup the flags.
4180+ flags := if haveAnnotation then FlagsUtil . backupFlags() else FlagsUtil . loadFlags();
4181+ try
4182+ // apply if there are any new flags
4183+ if haveAnnotation then
4184+ args := System . strtok(commandLineOptions, " " );
4185+ FlagsUtil . readArgs(args);
4186+ end if ;
4187+
4188+ (success, cache, outValue) := callTranslateModelFMU(inCache,inEnv,className,FMUVersion ,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
4189+ // reset to the original flags
4190+ FlagsUtil . saveFlags(flags);
4191+ else
4192+ FlagsUtil . saveFlags(flags);
4193+ fail();
4194+ end try ;
41544195 end if ;
41554196end translateModelFMU;
41564197
@@ -4237,6 +4278,10 @@ protected function buildModelFMU
42374278 output Values . Value outValue;
42384279protected
42394280 Absyn . Program p;
4281+ Flags . Flag flags;
4282+ String commandLineOptions;
4283+ list< String > args;
4284+ Boolean haveAnnotation;
42404285algorithm
42414286 // handle encryption
42424287 // if AST contains encrypted class show nothing
@@ -4245,8 +4290,28 @@ algorithm
42454290 Error . addMessage(Error . ACCESS_ENCRYPTED_PROTECTED_CONTENTS , {});
42464291 cache := inCache;
42474292 outValue := Values . STRING ("" );
4248- else
4293+ elseif Config . ignoreCommandLineOptionsAnnotation() then
42494294 (cache, outValue) := callBuildModelFMU(inCache,inEnv,className,FMUVersion ,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
4295+ else
4296+ // read the __OpenModelica_commandLineOptions
4297+ Absyn . STRING (commandLineOptions) := Interactive . getNamedAnnotationExp(className, SymbolTable . getAbsyn(), Absyn . IDENT ("__OpenModelica_commandLineOptions" ), SOME (Absyn . STRING ("" )), Interactive . getAnnotationExp);
4298+ haveAnnotation := boolNot(stringEq(commandLineOptions, "" ));
4299+ // backup the flags.
4300+ flags := if haveAnnotation then FlagsUtil . backupFlags() else FlagsUtil . loadFlags();
4301+ try
4302+ // apply if there are any new flags
4303+ if haveAnnotation then
4304+ args := System . strtok(commandLineOptions, " " );
4305+ FlagsUtil . readArgs(args);
4306+ end if ;
4307+
4308+ (cache, outValue) := callBuildModelFMU(inCache,inEnv,className,FMUVersion ,inFMUType,inFileNamePrefix,addDummy,platforms,inSimSettings);
4309+ // reset to the original flags
4310+ FlagsUtil . saveFlags(flags);
4311+ else
4312+ FlagsUtil . saveFlags(flags);
4313+ fail();
4314+ end try ;
42504315 end if ;
42514316end buildModelFMU;
42524317
@@ -8973,33 +9038,6 @@ algorithm
89739038 end if ;
89749039end findConversionPath;
89759040
8976- public function loadCommandLineOptions
8977- "Applies flags from the __OpenModelica_commandLineOptions annotation of a given class and returns the old flags."
8978- input Absyn . Path className;
8979- output Flags . Flag oldFlags;
8980- protected
8981- String opts;
8982- list< String > args;
8983- algorithm
8984- if Config . ignoreCommandLineOptionsAnnotation() then
8985- oldFlags := FlagsUtil . loadFlags();
8986- return ;
8987- end if ;
8988-
8989- // read the __OpenModelica_commandLineOptions
8990- Absyn . STRING (opts) := Interactive . getNamedAnnotationExp(className, SymbolTable . getAbsyn(),
8991- Absyn . IDENT ("__OpenModelica_commandLineOptions" ), SOME (Absyn . STRING ("" )), Interactive . getAnnotationExp);
8992-
8993- if not stringEmpty(opts) then
8994- // backup the current flags and apply the flags from the annotation
8995- oldFlags := FlagsUtil . backupFlags();
8996- args := System . strtok(opts, " " );
8997- FlagsUtil . readArgs(args);
8998- else
8999- oldFlags := FlagsUtil . loadFlags();
9000- end if ;
9001- end loadCommandLineOptions;
9002-
90039041annotation(__OpenModelica_Interface= "backend" );
90049042
90059043end CevalScriptBackend ;
0 commit comments