@@ -18,7 +18,6 @@ namespace nmodl {
1818
1919using Token = parser::NmodlParser::token;
2020using TokenType = parser::NmodlParser::token_type;
21- using Parser = parser::NmodlParser;
2221
2322// / details of lexer tokens
2423namespace details {
@@ -178,130 +177,75 @@ const static std::map<std::string, MethodInfo> methods = {{"adams", MethodInfo(D
178177 {" cvode_t" , MethodInfo (0 , 0 )},
179178 {" cvode_t_v" , MethodInfo (0 , 0 )}};
180179
181-
182- /* *
183- * Definition type similar to old implementation
184- *
185- * In the original implementation of NMODL (mod2c, nocmodl) different vectors were
186- * created for \c extdef, \c extdef2, \c extdef3, \c extdef4 etc. We are changing
187- * those vectors with <c><name, type></c> map. This will help us to search
188- * in single map and find it's type. The types are defined as follows:
189- *
190- * - DefinitionType::EXT_DOUBLE : external names that can be used as doubles
191- * without giving an error message
192- * - DefinitionType::EXT_2 : external function names that can be used with
193- * array and function name arguments
194- * - DefinitionType::EXT_3 : function names that get two reset arguments
195- * - DefinitionType::EXT_4 : functions that need a first arg of \c NrnThread*
196- * - DefinitionType::EXT_5 : external definition names that are not \c threadsafe
197- *
198- */
199- enum class DefinitionType { EXT_DOUBLE, EXT_2, EXT_3, EXT_4, EXT_5 };
200-
201-
202- const static std::map<std::string, DefinitionType> extern_definitions = {
203- {" first_time" , DefinitionType::EXT_DOUBLE},
204- {" error" , DefinitionType::EXT_DOUBLE},
205- {" f_flux" , DefinitionType::EXT_DOUBLE},
206- {" b_flux" , DefinitionType::EXT_DOUBLE},
207- {" fabs" , DefinitionType::EXT_DOUBLE},
208- {" sqrt" , DefinitionType::EXT_DOUBLE},
209- {" sin" , DefinitionType::EXT_DOUBLE},
210- {" cos" , DefinitionType::EXT_DOUBLE},
211- {" tan" , DefinitionType::EXT_DOUBLE},
212- {" acos" , DefinitionType::EXT_DOUBLE},
213- {" asin" , DefinitionType::EXT_DOUBLE},
214- {" atan" , DefinitionType::EXT_DOUBLE},
215- {" atan2" , DefinitionType::EXT_DOUBLE},
216- {" sinh" , DefinitionType::EXT_DOUBLE},
217- {" cosh" , DefinitionType::EXT_DOUBLE},
218- {" tanh" , DefinitionType::EXT_DOUBLE},
219- {" floor" , DefinitionType::EXT_DOUBLE},
220- {" ceil" , DefinitionType::EXT_DOUBLE},
221- {" fmod" , DefinitionType::EXT_DOUBLE},
222- {" log10" , DefinitionType::EXT_DOUBLE},
223- {" log" , DefinitionType::EXT_DOUBLE},
224- {" pow" , DefinitionType::EXT_DOUBLE},
225- {" printf" , DefinitionType::EXT_DOUBLE},
226- {" prterr" , DefinitionType::EXT_DOUBLE},
227- {" exp" , DefinitionType::EXT_DOUBLE},
228- {" threshold" , DefinitionType::EXT_DOUBLE},
229- {" force" , DefinitionType::EXT_DOUBLE},
230- {" deflate" , DefinitionType::EXT_DOUBLE},
231- {" expfit" , DefinitionType::EXT_DOUBLE},
232- {" derivs" , DefinitionType::EXT_DOUBLE},
233- {" spline" , DefinitionType::EXT_DOUBLE},
234- {" hyperbol" , DefinitionType::EXT_DOUBLE},
235- {" revhyperbol" , DefinitionType::EXT_DOUBLE},
236- {" sigmoid" , DefinitionType::EXT_DOUBLE},
237- {" revsigmoid" , DefinitionType::EXT_DOUBLE},
238- {" harmonic" , DefinitionType::EXT_DOUBLE},
239- {" squarewave" , DefinitionType::EXT_DOUBLE},
240- {" sawtooth" , DefinitionType::EXT_DOUBLE},
241- {" revsawtooth" , DefinitionType::EXT_DOUBLE},
242- {" ramp" , DefinitionType::EXT_DOUBLE},
243- {" pulse" , DefinitionType::EXT_DOUBLE},
244- {" perpulse" , DefinitionType::EXT_DOUBLE},
245- {" step" , DefinitionType::EXT_DOUBLE},
246- {" perstep" , DefinitionType::EXT_DOUBLE},
247- {" erf" , DefinitionType::EXT_DOUBLE},
248- {" exprand" , DefinitionType::EXT_DOUBLE},
249- {" factorial" , DefinitionType::EXT_DOUBLE},
250- {" gauss" , DefinitionType::EXT_DOUBLE},
251- {" normrand" , DefinitionType::EXT_DOUBLE},
252- {" poisrand" , DefinitionType::EXT_DOUBLE},
253- {" poisson" , DefinitionType::EXT_DOUBLE},
254- {" setseed" , DefinitionType::EXT_DOUBLE},
255- {" scop_random" , DefinitionType::EXT_DOUBLE},
256- {" boundary" , DefinitionType::EXT_DOUBLE},
257- {" romberg" , DefinitionType::EXT_DOUBLE},
258- {" legendre" , DefinitionType::EXT_DOUBLE},
259- {" invert" , DefinitionType::EXT_DOUBLE},
260- {" stepforce" , DefinitionType::EXT_DOUBLE},
261- {" schedule" , DefinitionType::EXT_DOUBLE},
262- {" set_seed" , DefinitionType::EXT_DOUBLE},
263- {" nrn_pointing" , DefinitionType::EXT_DOUBLE},
264- {" state_discontinuity" , DefinitionType::EXT_DOUBLE},
265- {" net_send" , DefinitionType::EXT_DOUBLE},
266- {" net_move" , DefinitionType::EXT_DOUBLE},
267- {" net_event" , DefinitionType::EXT_DOUBLE},
268- {" nrn_random_play" , DefinitionType::EXT_DOUBLE},
269- {" nrn_ghk" , DefinitionType::EXT_DOUBLE},
270- {" romberg" , DefinitionType::EXT_2},
271- {" legendre" , DefinitionType::EXT_2},
272- {" deflate" , DefinitionType::EXT_2},
273- {" threshold" , DefinitionType::EXT_3},
274- {" squarewave" , DefinitionType::EXT_3},
275- {" sawtooth" , DefinitionType::EXT_3},
276- {" revsawtooth" , DefinitionType::EXT_3},
277- {" ramp" , DefinitionType::EXT_3},
278- {" pulse" , DefinitionType::EXT_3},
279- {" perpulse" , DefinitionType::EXT_3},
280- {" step" , DefinitionType::EXT_3},
281- {" perstep" , DefinitionType::EXT_3},
282- {" stepforce" , DefinitionType::EXT_3},
283- {" schedule" , DefinitionType::EXT_3},
284- {" at_time" , DefinitionType::EXT_4},
285- {" force" , DefinitionType::EXT_5},
286- {" deflate" , DefinitionType::EXT_5},
287- {" expfit" , DefinitionType::EXT_5},
288- {" derivs" , DefinitionType::EXT_5},
289- {" spline" , DefinitionType::EXT_5},
290- {" exprand" , DefinitionType::EXT_5},
291- {" gauss" , DefinitionType::EXT_5},
292- {" normrand" , DefinitionType::EXT_5},
293- {" poisrand" , DefinitionType::EXT_5},
294- {" poisson" , DefinitionType::EXT_5},
295- {" setseed" , DefinitionType::EXT_5},
296- {" scop_random" , DefinitionType::EXT_5},
297- {" boundary" , DefinitionType::EXT_5},
298- {" romberg" , DefinitionType::EXT_5},
299- {" invert" , DefinitionType::EXT_5},
300- {" stepforce" , DefinitionType::EXT_5},
301- {" schedule" , DefinitionType::EXT_5},
302- {" set_seed" , DefinitionType::EXT_5},
303- {" nrn_random_play" , DefinitionType::EXT_5}};
304-
180+ const static std::vector<std::string> extern_definitions = {" acos" ,
181+ " asin" ,
182+ " at_time" ,
183+ " atan" ,
184+ " atan2" ,
185+ " b_flux" ,
186+ " boundary" ,
187+ " ceil" ,
188+ " cos" ,
189+ " cosh" ,
190+ " deflate" ,
191+ " derivs" ,
192+ " erf" ,
193+ " error" ,
194+ " exp" ,
195+ " expfit" ,
196+ " exprand" ,
197+ " f_flux" ,
198+ " fabs" ,
199+ " factorial" ,
200+ " first_time" ,
201+ " floor" ,
202+ " fmod" ,
203+ " force" ,
204+ " gauss" ,
205+ " harmonic" ,
206+ " hyperbol" ,
207+ " invert" ,
208+ " legendre" ,
209+ " log" ,
210+ " log10" ,
211+ " net_event" ,
212+ " net_move" ,
213+ " net_send" ,
214+ " normrand" ,
215+ " nrn_ghk" ,
216+ " nrn_pointing" ,
217+ " nrn_random_play" ,
218+ " perpulse" ,
219+ " perstep" ,
220+ " poisrand" ,
221+ " poisson" ,
222+ " pow" ,
223+ " printf" ,
224+ " prterr" ,
225+ " pulse" ,
226+ " ramp" ,
227+ " revhyperbol" ,
228+ " revsawtooth" ,
229+ " revsigmoid" ,
230+ " romberg" ,
231+ " sawtooth" ,
232+ " schedule" ,
233+ " scop_random" ,
234+ " set_seed" ,
235+ " setseed" ,
236+ " sigmoid" ,
237+ " sin" ,
238+ " sinh" ,
239+ " spline" ,
240+ " sqrt" ,
241+ " squarewave" ,
242+ " state_discontinuity" ,
243+ " step" ,
244+ " stepforce" ,
245+ " tan" ,
246+ " tanh" ,
247+ " threshold" };
248+ const static std::vector<std::string> need_nt = {" at_time" };
305249
306250/* *
307251 * Checks if \c token is one of the functions coming from NEURON/CoreNEURON and needs
@@ -311,8 +255,7 @@ const static std::map<std::string, DefinitionType> extern_definitions = {
311255 * @return True or false depending if the function needs NrnThread* argument
312256 */
313257bool needs_neuron_thread_first_arg (const std::string& token) {
314- auto extern_def = extern_definitions.find (token);
315- return extern_def != extern_definitions.end () && extern_def->second == DefinitionType::EXT_4;
258+ return std::find (need_nt.cbegin (), need_nt.cend (), token) != need_nt.cend ();
316259}
317260
318261
@@ -341,7 +284,7 @@ TokenType keyword_type(const std::string& name) {
341284 * @return true if name is a keyword
342285 */
343286bool is_keyword (const std::string& name) {
344- return ( details::keywords.find (name) != details::keywords.end () );
287+ return details::keywords.find (name) != details::keywords.end ();
345288}
346289
347290
@@ -376,9 +319,7 @@ TokenType token_type(const std::string& name) {
376319 * @return vector of NEURON variables
377320 */
378321std::vector<std::string> get_external_variables () {
379- std::vector<std::string> result;
380- result.insert (result.end (), details::NEURON_VARIABLES.begin (), details::NEURON_VARIABLES.end ());
381- return result;
322+ return details::NEURON_VARIABLES;
382323}
383324
384325
@@ -388,13 +329,13 @@ std::vector<std::string> get_external_variables() {
388329 */
389330std::vector<std::string> get_external_functions () {
390331 std::vector<std::string> result;
391- result.reserve (details::methods.size ());
332+ result.reserve (details::methods.size () + details::extern_definitions. size () );
392333 for (auto & method: details::methods) {
393334 result.push_back (method.first );
394335 }
395- for ( auto & definition: details::extern_definitions) {
396- result. push_back (definition. first );
397- }
336+ result. insert (result. cend (),
337+ details::extern_definitions. begin (),
338+ details::extern_definitions. end ());
398339 return result;
399340}
400341
0 commit comments