User Guide
codegen_cpp_visitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 /**
11  * \dir
12  * \brief Code generation backend implementations for CoreNEURON
13  *
14  * \file
15  * \brief \copybrief nmodl::codegen::CodegenCppVisitor
16  */
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <ctime>
21 #include <numeric>
22 #include <ostream>
23 #include <string>
24 #include <string_view>
25 #include <utility>
26 
27 #include "codegen/codegen_info.hpp"
29 #include "printer/code_printer.hpp"
30 #include "symtab/symbol_table.hpp"
31 #include "utils/logger.hpp"
32 #include "visitors/ast_visitor.hpp"
33 
34 /// encapsulates code generation backend implementations
35 namespace nmodl {
36 
37 namespace codegen {
38 
39 /**
40  * \defgroup codegen Code Generation Implementation
41  * \brief Implementations of code generation backends
42  *
43  * \defgroup codegen_details Codegen Helpers
44  * \ingroup codegen
45  * \brief Helper routines/types for code generation
46  * \{
47  */
48 
49 /**
50  * \enum BlockType
51  * \brief Helper to represent various block types
52  *
53  * Note: do not assign integers to these enums
54  *
55  */
56 enum class BlockType {
57  /// initial block
58  Initial,
59 
60  /// constructor block
62 
63  /// destructor block
64  Destructor,
65 
66  /// breakpoint block
67  Equation,
68 
69  /// derivative block
70  State,
71 
72  /// watch block
73  Watch,
74 
75  /// net_receive block
76  NetReceive,
77 
78  /// before / after block
80 
81  /// fake ending block type for loops on the enums. Keep it at the end
83 };
84 
85 
86 /**
87  * \enum MemberType
88  * \brief Helper to represent various variables types
89  *
90  */
91 enum class MemberType {
92  /// index / int variables
93  index,
94 
95  /// range / double variables
96  range,
97 
98  /// global variables
99  global,
100 
101  /// thread variables
102  thread
103 };
104 
105 
106 /**
107  * \class IndexVariableInfo
108  * \brief Helper to represent information about index/int variables
109  *
110  */
112  /// symbol for the variable
113  const std::shared_ptr<symtab::Symbol> symbol;
114 
115  /// if variable resides in vdata field of NrnThread
116  /// typically true for bbcore pointer
117  bool is_vdata = false;
118 
119  /// if this is pure index (e.g. style_ion) variables is directly
120  /// index and shouldn't be printed with data/vdata
121  bool is_index = false;
122 
123  /// if this is an integer (e.g. tqitem, point_process) variable which
124  /// is printed as array accesses
125  bool is_integer = false;
126 
127  /// if the variable is qualified as constant (this is property of IndexVariable)
128  bool is_constant = false;
129 
130  explicit IndexVariableInfo(std::shared_ptr<symtab::Symbol> symbol,
131  bool is_vdata = false,
132  bool is_index = false,
133  bool is_integer = false)
134  : symbol(std::move(symbol))
135  , is_vdata(is_vdata)
136  , is_index(is_index)
137  , is_integer(is_integer) {}
138 };
139 
140 
141 /**
142  * \class ShadowUseStatement
143  * \brief Represents ion write statement during code generation
144  *
145  * Ion update statement needs use of shadow vectors for certain backends
146  * as atomics operations are not supported on cpu backend.
147  *
148  * \todo If shadow_lhs is empty then we assume shadow statement not required
149  */
151  std::string lhs;
152  std::string op;
153  std::string rhs;
154 };
155 
156 /** \} */ // end of codegen_details
157 
158 
160 
161 
162 /**
163  * \defgroup codegen_backends Codegen Backends
164  * \ingroup codegen
165  * \brief Code generation backends for CoreNEURON
166  * \{
167  */
168 
169 /**
170  * \class CodegenCppVisitor
171  * \brief %Visitor for printing C++ code compatible with legacy api of CoreNEURON
172  *
173  * \todo
174  * - Handle define statement (i.e. macros)
175  * - If there is a return statement in the verbatim block
176  * of inlined function then it will be error. Need better
177  * error checking. For example, see netstim.mod where we
178  * have removed return from verbatim block.
179  */
181  public:
182  /**
183  * \brief Constructs the C++ code generator visitor
184  *
185  * This constructor instantiates an NMODL C++ code generator and allows writing generated code
186  * directly to a file in \c [output_dir]/[mod_filename].cpp.
187  *
188  * \note No code generation is performed at this stage. Since the code
189  * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
190  * visit_program in order to generate the C++ code corresponding to the AST.
191  *
192  * \param mod_filename The name of the model for which code should be generated.
193  * It is used for constructing an output filename.
194  * \param output_dir The directory where target C++ file should be generated.
195  * \param float_type The float type to use in the generated code. The string will be used
196  * as-is in the target code. This defaults to \c double.
197  */
199  const std::string& output_dir,
200  std::string float_type,
201  const bool optimize_ionvar_copies,
202  size_t blame_line = 0)
203  : printer(
204  std::make_unique<CodePrinter>(output_dir + "/" + mod_filename + ".cpp", blame_line))
205  , mod_filename(std::move(mod_filename))
206  , float_type(std::move(float_type))
208 
209 
210  /**
211  * \brief Constructs the C++ code generator visitor
212  *
213  * This constructor instantiates an NMODL C++ code generator and allows writing generated code
214  * into an output stream.
215  *
216  * \note No code generation is performed at this stage. Since the code
217  * generator classes are all based on \c AstVisitor the AST must be visited using e.g. \c
218  * visit_program in order to generate the C++ code corresponding to the AST.
219  *
220  * \param mod_filename The name of the model for which code should be generated.
221  * It is used for constructing an output filename.
222  * \param stream The output stream onto which to write the generated code
223  * \param float_type The float type to use in the generated code. The string will be used
224  * as-is in the target code. This defaults to \c double.
225  */
227  std::ostream& stream,
228  std::string float_type,
229  const bool optimize_ionvar_copies,
230  size_t blame_line = 0)
231  : printer(std::make_unique<CodePrinter>(stream, blame_line))
232  , mod_filename(std::move(mod_filename))
233  , float_type(std::move(float_type))
235 
236 
237  protected:
238  using SymbolType = std::shared_ptr<symtab::Symbol>;
239 
240 
241  /**
242  * A vector of parameters represented by a 4-tuple of strings:
243  *
244  * - type qualifier (e.g. \c const)
245  * - type (e.g. \c double)
246  * - pointer qualifier (e.g. \c \_\_restrict\_\_)
247  * - parameter name (e.g. \c data)
248  *
249  */
250  using ParamVector = std::vector<std::tuple<std::string, std::string, std::string, std::string>>;
251 
252 
253  /****************************************************************************************/
254  /* Member variables */
255  /****************************************************************************************/
256 
257  /**
258  * Code printer object for target (C++)
259  */
260  std::unique_ptr<CodePrinter> printer;
261 
262 
263  /**
264  * Name of mod file (without .mod suffix)
265  */
266  std::string mod_filename;
267 
268 
269  /**
270  * Data type of floating point variables
271  */
273 
274 
275  /**
276  * Flag to indicate if visitor should avoid ion variable copies
277  */
279 
280 
281  /**
282  * All ast information for code generation
283  */
285 
286 
287  /**
288  * Symbol table for the program
289  */
291 
292 
293  /**
294  * All float variables for the model
295  */
296  std::vector<SymbolType> codegen_float_variables;
297 
298 
299  /**
300  * All int variables for the model
301  */
302  std::vector<IndexVariableInfo> codegen_int_variables;
303 
304 
305  /**
306  * All global variables for the model
307  * \todo: this has become different than CodegenInfo
308  */
309  std::vector<SymbolType> codegen_global_variables;
310 
311 
312  /**
313  * Variable name should be converted to instance name (but not for function arguments)
314  */
316 
317 
318  /**
319  * \c true if currently net_receive block being printed
320  */
321  bool printing_net_receive = false;
322 
323 
324  /**
325  * \c true if currently initial block of net_receive being printed
326  */
327  bool printing_net_init = false;
328 
329 
330  /**
331  * \c true if currently printing top level verbatim blocks
332  */
334 
335 
336  /**
337  * \c true if internal method call was encountered while processing verbatim block
338  */
340 
341 
342  /**
343  * Index of watch statement being printed
344  */
346 
347 
348  /****************************************************************************************/
349  /* Generic information getters */
350  /****************************************************************************************/
351 
352  /**
353  * Return Nmodl language version
354  * \return A version
355  */
356  std::string nmodl_version() const noexcept {
358  }
359 
360 
361  /**
362  * Name of the simulator the code was generated for
363  */
364  virtual std::string simulator_name() = 0;
365 
366 
367  /**
368  * Name of structure that wraps range variables
369  */
370  std::string instance_struct() const {
371  return fmt::format("{}_Instance", info.mod_suffix);
372  }
373 
374  /**
375  * Name of structure that wraps node variables
376  */
377  std::string node_data_struct() const {
378  return fmt::format("{}_NodeData", info.mod_suffix);
379  }
380 
381 
382  /**
383  * Name of structure that wraps global variables
384  */
385  std::string global_struct() const {
386  return fmt::format("{}_Store", info.mod_suffix);
387  }
388 
389 
390  /**
391  * Name of the (host-only) global instance of `global_struct`
392  */
393  std::string global_struct_instance() const {
394  return info.mod_suffix + "_global";
395  }
396 
397 
398  /**
399  * Name of the code generation backend
400  */
401  virtual std::string backend_name() const = 0;
402 
403 
404  /**
405  * Data type for the local variables
406  */
407  const char* local_var_type() const noexcept {
409  }
410 
411 
412  /**
413  * Check if a semicolon is required at the end of given statement
414  * \param node The AST Statement node to check
415  * \return \c true if this Statement requires a semicolon
416  */
417  static bool need_semicolon(const ast::Statement& node);
418 
419 
420  /**
421  * Default data type for floating point elements
422  */
423  const char* default_float_data_type() const noexcept {
425  }
426 
427 
428  /**
429  * Data type for floating point elements specified on command line
430  */
431  const std::string& float_data_type() const noexcept {
432  return float_type;
433  }
434 
435 
436  /**
437  * Default data type for integer (offset) elements
438  */
439  const char* default_int_data_type() const noexcept {
441  }
442 
443 
444  /**
445  * Operator for rhs vector update (matrix update)
446  */
447  const char* operator_for_rhs() const noexcept {
448  return info.electrode_current ? "+=" : "-=";
449  }
450 
451 
452  /**
453  * Operator for diagonal vector update (matrix update)
454  */
455  const char* operator_for_d() const noexcept {
456  return info.electrode_current ? "-=" : "+=";
457  }
458 
459  /**
460  * Name of channel info variable
461  *
462  */
463  std::string get_channel_info_var_name() const noexcept {
464  return std::string("mechanism_info");
465  }
466 
467 
468  /****************************************************************************************/
469  /* Common helper routines accross codegen functions */
470  /****************************************************************************************/
471 
472  /**
473  * Check if a structure for ion variables is required
474  * \return \c true if a structure fot ion variables must be generated
475  */
476  bool ion_variable_struct_required() const;
477 
478 
479  /**
480  * Generate the string representing the procedure parameter declaration
481  *
482  * The procedure parameters are stored in a vector of 4-tuples each representing a parameter.
483  *
484  * \param params The parameters that should be concatenated into the function parameter
485  * declaration
486  * \return The string representing the declaration of function parameters
487  */
488  static std::string get_parameter_str(const ParamVector& params);
489 
490 
491  /**
492  * Check if function or procedure node has parameter with given name
493  *
494  * \tparam T Node type (either procedure or function)
495  * \param node AST node (either procedure or function)
496  * \param name Name of parameter
497  * \return True if argument with name exist
498  */
499  template <typename T>
500  bool has_parameter_of_name(const T& node, const std::string& name);
501 
502 
503  /**
504  * Check if given statement should be skipped during code generation
505  * \param node The AST Statement node to check
506  * \return \c true if this Statement is to be skipped
507  */
508  static bool statement_to_skip(const ast::Statement& node);
509 
510 
511  /**
512  * Check if net_send_buffer is required
513  */
514  bool net_send_buffer_required() const noexcept;
515 
516 
517  /**
518  * Check if net receive/send buffering kernels required
519  */
520  bool net_receive_buffering_required() const noexcept;
521 
522 
523  /**
524  * Check if nrn_state function is required
525  */
526  bool nrn_state_required() const noexcept;
527 
528 
529  /**
530  * Check if nrn_cur function is required
531  */
532  bool nrn_cur_required() const noexcept;
533 
534 
535  /**
536  * Check if net_receive function is required
537  */
538  bool net_receive_required() const noexcept;
539 
540 
541  /**
542  * Check if setup_range_variable function is required
543  * \return
544  */
545  bool range_variable_setup_required() const noexcept;
546 
547 
548  /**
549  * Check if net_receive node exist
550  */
551  bool net_receive_exist() const noexcept;
552 
553 
554  /**
555  * Check if breakpoint node exist
556  */
557  bool breakpoint_exist() const noexcept;
558 
559 
560  /**
561  * Check if given method is defined in this model
562  * \param name The name of the method to check
563  * \return \c true if the method is defined
564  */
565  bool defined_method(const std::string& name) const;
566 
567 
568  /**
569  * Checks if given function name is \c net_send
570  * \param name The function name to check
571  * \return \c true if the function is net_send
572  */
573  bool is_net_send(const std::string& name) const noexcept {
574  return name == codegen::naming::NET_SEND_METHOD;
575  }
576 
577 
578  /**
579  * Checks if given function name is \c net_move
580  * \param name The function name to check
581  * \return \c true if the function is net_move
582  */
583  bool is_net_move(const std::string& name) const noexcept {
584  return name == codegen::naming::NET_MOVE_METHOD;
585  }
586 
587 
588  /**
589  * Checks if given function name is \c net_event
590  * \param name The function name to check
591  * \return \c true if the function is net_event
592  */
593  bool is_net_event(const std::string& name) const noexcept {
594  return name == codegen::naming::NET_EVENT_METHOD;
595  }
596 
597 
598  /**
599  * Determine the position in the data array for a given float variable
600  * \param name The name of a float variable
601  * \return The position index in the data array
602  */
603  virtual int position_of_float_var(const std::string& name) const = 0;
604 
605 
606  /**
607  * Determine the position in the data array for a given int variable
608  * \param name The name of an int variable
609  * \return The position index in the data array
610  */
611  virtual int position_of_int_var(const std::string& name) const = 0;
612 
613 
614  /**
615  * Number of float variables in the model
616  */
617  int float_variables_size() const;
618 
619 
620  /**
621  * Number of integer variables in the model
622  */
623  int int_variables_size() const;
624 
625 
626  /**
627  * Convert a given \c double value to its string representation
628  * \param value The number to convert given as string as it is parsed by the modfile
629  * \return Its string representation
630  */
631  std::string format_double_string(const std::string& value);
632 
633 
634  /**
635  * Convert a given \c float value to its string representation
636  * \param value The number to convert given as string as it is parsed by the modfile
637  * \return Its string representation
638  */
639  std::string format_float_string(const std::string& value);
640 
641 
642  /**
643  * populate all index semantics needed for registration with coreneuron
644  */
645  void update_index_semantics();
646 
647 
648  /**
649  * Determine all \c float variables required during code generation
650  * \return A \c vector of \c float variables
651  */
652  std::vector<SymbolType> get_float_variables() const;
653 
654 
655  /**
656  * Determine all \c int variables required during code generation
657  * \return A \c vector of \c int variables
658  */
659  std::vector<IndexVariableInfo> get_int_variables();
660 
661 
662  /**
663  * For a given output block type, return statements for all read ion variables
664  *
665  * \param type The type of code block being generated
666  * \return A \c vector of strings representing the reading of ion variables
667  */
668  std::vector<std::string> ion_read_statements(BlockType type) const;
669 
670 
671  /**
672  * For a given output block type, return minimal statements for all read ion variables
673  *
674  * \param type The type of code block being generated
675  * \return A \c vector of strings representing the reading of ion variables
676  */
677  std::vector<std::string> ion_read_statements_optimized(BlockType type) const;
678 
679 
680  /**
681  * For a given output block type, return statements for writing back ion variables
682  *
683  * \param type The type of code block being generated
684  * \return A \c vector of strings representing the write-back of ion variables
685  */
686  std::vector<ShadowUseStatement> ion_write_statements(BlockType type);
687 
688 
689  /**
690  * Process shadow update statement
691  *
692  * If the statement requires reduction then add it to vector of reduction statement and return
693  * statement using shadow update
694  *
695  * \param statement The statement that might require shadow updates
696  * \param type The target backend code block type
697  * \return The generated target backend code
698  */
699  std::string process_shadow_update_statement(const ShadowUseStatement& statement,
700  BlockType type);
701 
702 
703  /**
704  * Determine the variable name for the "current" used in breakpoint block taking into account
705  * intermediate code transformations.
706  * \param current The variable name for the current used in the model
707  * \return The name for the current to be printed in C++
708  */
709  std::string breakpoint_current(std::string current) const;
710 
711 
712  /****************************************************************************************/
713  /* Backend specific routines */
714  /****************************************************************************************/
715 
716 
717  /**
718  * Print atomic update pragma for reduction statements
719  */
720  virtual void print_atomic_reduction_pragma() = 0;
721 
722 
723  /**
724  * Instantiate global var instance
725  *
726  * For C++ code generation this is empty
727  * \return ""
728  */
729  virtual void print_global_var_struct_decl();
730 
731  /**
732  * Check if ion variable copies should be avoided
733  */
734  virtual bool optimize_ion_variable_copies() const = 0;
735 
736  /****************************************************************************************/
737  /* Printing routines for code generation */
738  /****************************************************************************************/
739 
740 
741  /**
742  * Print any statement block in nmodl with option to (not) print braces
743  *
744  * The individual statements (of type nmodl::ast::Statement) in the StatementBlock are printed
745  * by accepting \c this visistor.
746  *
747  * \param node A (possibly empty) statement block AST node
748  * \param open_brace Print an opening brace if \c false
749  * \param close_brace Print a closing brace if \c true
750  */
752  bool open_brace = true,
753  bool close_brace = true);
754 
755 
756  /**
757  * Print call to internal or external function
758  * \param node The AST node representing a function call
759  */
760  virtual void print_function_call(const ast::FunctionCall& node);
761 
762  /**
763  * Print call to \c net\_send
764  * \param node The AST node representing the function call
765  */
766  virtual void print_net_send_call(const ast::FunctionCall& node) = 0;
767 
768 
769  /**
770  * Print call to net\_move
771  * \param node The AST node representing the function call
772  */
773  virtual void print_net_move_call(const ast::FunctionCall& node) = 0;
774 
775 
776  /**
777  * Print call to net\_event
778  * \param node The AST node representing the function call
779  */
780  virtual void print_net_event_call(const ast::FunctionCall& node) = 0;
781 
782  /**
783  * Print function and procedures prototype declaration
784  */
785  virtual void print_function_prototypes() = 0;
786 
787 
788  /**
789  * Print nmodl function or procedure (common code)
790  * \param node the AST node representing the function or procedure in NMODL
791  * \param name the name of the function or procedure
792  */
793  virtual void print_function_or_procedure(const ast::Block& node, const std::string& name) = 0;
794 
795 
796  /**
797  * Common helper function to help printing function or procedure blocks
798  * \param node the AST node representing the function or procedure in NMODL
799  */
800  virtual void print_function_procedure_helper(const ast::Block& node) = 0;
801 
802 
803  /**
804  * Print NMODL procedure in target backend code
805  * \param node
806  */
807  virtual void print_procedure(const ast::ProcedureBlock& node) = 0;
808 
809 
810  /**
811  * Print NMODL function in target backend code
812  * \param node
813  */
814  virtual void print_function(const ast::FunctionBlock& node) = 0;
815 
816 
817  /**
818  * Rename function/procedure arguments that conflict with default arguments
819  */
821 
822 
823  /**
824  * Print the items in a vector as a list
825  *
826  * This function prints a given vector of elements as a list with given separator onto the
827  * current printer. Elements are expected to be of type nmodl::ast::Ast and are printed by being
828  * visited. Care is taken to omit the separator after the the last element.
829  *
830  * \tparam T The element type in the vector, which must be of type nmodl::ast::Ast
831  * \param elements The vector of elements to be printed
832  * \param separator The separator string to print between all elements
833  * \param prefix A prefix string to print before each element
834  */
835  template <typename T>
836  void print_vector_elements(const std::vector<T>& elements,
837  const std::string& separator,
838  const std::string& prefix = "");
839 
840 
841  /****************************************************************************************/
842  /* Code-specific helper routines */
843  /****************************************************************************************/
844 
845 
846  /**
847  * Arguments for functions that are defined and used internally.
848  * \return the method arguments
849  */
850  virtual std::string internal_method_arguments() = 0;
851 
852 
853  /**
854  * Parameters for internally defined functions
855  * \return the method parameters
856  */
858 
859 
860  /**
861  * Arguments for external functions called from generated code
862  * \return A string representing the arguments passed to an external function
863  */
864  virtual const char* external_method_arguments() noexcept = 0;
865 
866 
867  /**
868  * Parameters for functions in generated code that are called back from external code
869  *
870  * Functions registered in NEURON during initialization for callback must adhere to a prescribed
871  * calling convention. This method generates the string representing the function parameters for
872  * these externally called functions.
873  * \param table
874  * \return A string representing the parameters of the function
875  */
876  virtual const char* external_method_parameters(bool table = false) noexcept = 0;
877 
878 
879  /**
880  * Arguments for "_threadargs_" macro in neuron implementation
881  */
882  virtual std::string nrn_thread_arguments() const = 0;
883 
884 
885  /**
886  * Arguments for "_threadargs_" macro in neuron implementation
887  */
888  virtual std::string nrn_thread_internal_arguments() = 0;
889 
890  /**
891  * Process a verbatim block for possible variable renaming
892  * \param text The verbatim code to be processed
893  * \return The code with all variables renamed as needed
894  */
895  virtual std::string process_verbatim_text(std::string const& text) = 0;
896 
897 
898  /**
899  * Arguments for register_mech or point_register_mech function
900  */
901  virtual std::string register_mechanism_arguments() const = 0;
902 
903 
904  /**
905  * Add quotes to string to be output
906  *
907  * \param text The string to be quoted
908  * \return The same string with double-quotes pre- and postfixed
909  */
910  std::string add_escape_quote(const std::string& text) const {
911  return "\"" + text + "\"";
912  }
913 
914 
915  /**
916  * Constructs the name of a function or procedure
917  * \param name The name of the function or procedure
918  * \return The name of the function or procedure postfixed with the model name
919  */
920  std::string method_name(const std::string& name) const {
921  return name + "_" + info.mod_suffix;
922  }
923 
924 
925  /**
926  * Creates a temporary symbol
927  * \param name The name of the symbol
928  * \return A symbol based on the given name
929  */
930  SymbolType make_symbol(const std::string& name) const {
931  return std::make_shared<symtab::Symbol>(name, ModToken());
932  }
933 
934  /**
935  * Generate Function call statement for nrn_wrote_conc
936  * \param ion_name The name of the ion variable
937  * \param concentration The name of the concentration variable
938  * \param index
939  * \return The string representing the function call
940  */
941  virtual std::string conc_write_statement(const std::string& ion_name,
942  const std::string& concentration,
943  int index) = 0;
944 
945  /****************************************************************************************/
946  /* Code-specific printing routines for code generations */
947  /****************************************************************************************/
948 
949 
950  /**
951  * Prints the start of the simulator namespace
952  */
953  virtual void print_namespace_start() = 0;
954 
955 
956  /**
957  * Prints the end of the simulator namespace
958  */
959  virtual void print_namespace_stop() = 0;
960 
961 
962  /****************************************************************************************/
963  /* Routines for returning variable name */
964  /****************************************************************************************/
965 
966  /**
967  * Determine the updated name if the ion variable has been optimized
968  * \param name The ion variable name
969  * \return The updated name of the variable has been optimized (e.g. \c ena --> \c ion_ena)
970  */
971  std::string update_if_ion_variable_name(const std::string& name) const;
972 
973 
974  /**
975  * Determine the name of a \c float variable given its symbol
976  *
977  * This function typically returns the accessor expression in backend code for the given symbol.
978  * Since the model variables are stored in data arrays and accessed by offset, this function
979  * will return the C++ string representing the array access at the correct offset
980  *
981  * \param symbol The symbol of a variable for which we want to obtain its name
982  * \param use_instance Should the variable be accessed via instance or data array
983  * \return The backend code string representing the access to the given variable
984  * symbol
985  */
986  virtual std::string float_variable_name(const SymbolType& symbol, bool use_instance) const = 0;
987 
988 
989  /**
990  * Determine the name of an \c int variable given its symbol
991  *
992  * This function typically returns the accessor expression in backend code for the given symbol.
993  * Since the model variables are stored in data arrays and accessed by offset, this function
994  * will return the C++ string representing the array access at the correct offset
995  *
996  * \param symbol The symbol of a variable for which we want to obtain its name
997  * \param name The name of the index variable
998  * \param use_instance Should the variable be accessed via instance or data array
999  * \return The backend code string representing the access to the given variable
1000  * symbol
1001  */
1002  virtual std::string int_variable_name(const IndexVariableInfo& symbol,
1003  const std::string& name,
1004  bool use_instance) const = 0;
1005 
1006 
1007  /**
1008  * Determine the variable name for a global variable given its symbol
1009  * \param symbol The symbol of a variable for which we want to obtain its name
1010  * \param use_instance Should the variable be accessed via the (host-only)
1011  * global variable or the instance-specific copy (also available on GPU).
1012  * \return The C++ string representing the access to the global variable
1013  */
1014  virtual std::string global_variable_name(const SymbolType& symbol,
1015  bool use_instance = true) const = 0;
1016 
1017 
1018  /**
1019  * Determine variable name in the structure of mechanism properties
1020  *
1021  * \param name Variable name that is being printed
1022  * \param use_instance Should the variable be accessed via instance or data array
1023  * \return The C++ string representing the access to the variable in the neuron
1024  * thread structure
1025  */
1026  virtual std::string get_variable_name(const std::string& name,
1027  bool use_instance = true) const = 0;
1028 
1029 
1030  /**
1031  * Return ion variable name and corresponding ion read variable name.
1032  *
1033  * Example:
1034  * {"ena", "ion_ena"} = read_ion_variable_name("ena");
1035  *
1036  * \param name The ion variable name
1037  * \return The ion read variable name
1038  */
1039  static std::pair<std::string, std::string> read_ion_variable_name(const std::string& name);
1040 
1041 
1042  /**
1043  * Return ion variable name and corresponding ion write variable name
1044  *
1045  * Example:
1046  * {"ion_ena", "ena"} = write_ion_variable_name("ena");
1047  *
1048  * \param name The ion variable name
1049  * \return The ion write variable name
1050  */
1051  static std::pair<std::string, std::string> write_ion_variable_name(const std::string& name);
1052 
1053 
1054  /****************************************************************************************/
1055  /* Main printing routines for code generation */
1056  /****************************************************************************************/
1057 
1058 
1059  /**
1060  * Print top file header printed in generated code
1061  */
1062  virtual void print_backend_info() = 0;
1063 
1064 
1065  /**
1066  * Print standard C/C++ includes
1067  */
1068  virtual void print_standard_includes() = 0;
1069 
1070 
1071  virtual void print_sdlists_init(bool print_initializers) = 0;
1072 
1073 
1074  /**
1075  * Print the structure that wraps all global variables used in the NMODL
1076  *
1077  * \param print_initializers Whether to include default values in the struct
1078  * definition (true: int foo{42}; false: int foo;)
1079  */
1080  virtual void print_mechanism_global_var_structure(bool print_initializers) = 0;
1081 
1082 
1083  /**
1084  * Print static assertions about the global variable struct.
1085  */
1086  virtual void print_global_var_struct_assertions() const;
1087 
1088 
1089  /**
1090  * Print declaration of macro NRN_PRCELLSTATE for debugging
1091  */
1092  void print_prcellstate_macros() const;
1093 
1094 
1095  /**
1096  * Print backend code for byte array that has mechanism information (to be registered
1097  * with NEURON/CoreNEURON)
1098  */
1099  void print_mechanism_info();
1100 
1101 
1102  /**
1103  * Print byte arrays that register scalar and vector variables for hoc interface
1104  *
1105  */
1106  virtual void print_global_variables_for_hoc() = 0;
1107 
1108 
1109  /**
1110  * Print the mechanism registration function
1111  *
1112  */
1113  virtual void print_mechanism_register() = 0;
1114 
1115 
1116  /**
1117  * Print common code for global functions like nrn_init, nrn_cur and nrn_state
1118  * \param type The target backend code block type
1119  */
1120  virtual void print_global_function_common_code(BlockType type,
1121  const std::string& function_name = "") = 0;
1122 
1123 
1124  /**
1125  * Print nrn_constructor function definition
1126  *
1127  */
1128  virtual void print_nrn_constructor() = 0;
1129 
1130 
1131  /**
1132  * Print nrn_destructor function definition
1133  *
1134  */
1135  virtual void print_nrn_destructor() = 0;
1136 
1137 
1138  /**
1139  * Print nrn_alloc function definition
1140  *
1141  */
1142  virtual void print_nrn_alloc() = 0;
1143 
1144 
1145  /****************************************************************************************/
1146  /* Print nrn_state routine */
1147  /****************************************************************************************/
1148 
1149 
1150  /**
1151  * Print nrn_state / state update function definition
1152  */
1153  virtual void print_nrn_state() = 0;
1154 
1155 
1156  /****************************************************************************************/
1157  /* Print nrn_cur related routines */
1158  /****************************************************************************************/
1159 
1160 
1161  /**
1162  * Print the \c nrn_current kernel
1163  *
1164  * \note nrn_cur_kernel will have two calls to nrn_current if no conductance keywords specified
1165  * \param node the AST node representing the NMODL breakpoint block
1166  */
1167  virtual void print_nrn_current(const ast::BreakpointBlock& node) = 0;
1168 
1169 
1170  /**
1171  * Print the \c nrn\_cur kernel with NMODL \c conductance keyword provisions
1172  *
1173  * If the NMODL \c conductance keyword is used in the \c breakpoint block, then
1174  * CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer
1175  *
1176  * \param node the AST node representing the NMODL breakpoint block
1177  */
1178  virtual void print_nrn_cur_conductance_kernel(const ast::BreakpointBlock& node) = 0;
1179 
1180 
1181  /**
1182  * Print the \c nrn\_cur kernel without NMODL \c conductance keyword provisions
1183  *
1184  * If the NMODL \c conductance keyword is \b not used in the \c breakpoint block, then
1185  * CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer
1186  */
1187  virtual void print_nrn_cur_non_conductance_kernel() = 0;
1188 
1189 
1190  /**
1191  * Print main body of nrn_cur function
1192  * \param node the AST node representing the NMODL breakpoint block
1193  */
1194  virtual void print_nrn_cur_kernel(const ast::BreakpointBlock& node) = 0;
1195 
1196 
1197  /**
1198  * Print fast membrane current calculation code
1199  */
1200  virtual void print_fast_imem_calculation() = 0;
1201 
1202 
1203  /**
1204  * Print nrn_cur / current update function definition
1205  */
1206  virtual void print_nrn_cur() = 0;
1207 
1208 
1209  /****************************************************************************************/
1210  /* Main code printing entry points */
1211  /****************************************************************************************/
1212 
1213 
1214  /**
1215  * Print all includes
1216  *
1217  */
1218  virtual void print_headers_include() = 0;
1219 
1220 
1221  /**
1222  * Print start of namespaces
1223  *
1224  */
1225  virtual void print_namespace_begin() = 0;
1226 
1227 
1228  /**
1229  * Print end of namespaces
1230  *
1231  */
1232  virtual void print_namespace_end() = 0;
1233 
1234 
1235  /**
1236  * Print all classes
1237  * \param print_initializers Whether to include default values.
1238  */
1239  virtual void print_data_structures(bool print_initializers) = 0;
1240 
1241 
1242  /**
1243  * Set v_unused (voltage) for NRN_PRCELLSTATE feature
1244  */
1245  virtual void print_v_unused() const = 0;
1246 
1247 
1248  /**
1249  * Set g_unused (conductance) for NRN_PRCELLSTATE feature
1250  */
1251  virtual void print_g_unused() const = 0;
1252 
1253 
1254  /**
1255  * Print all compute functions for every backend
1256  *
1257  */
1258  virtual void print_compute_functions() = 0;
1259 
1260 
1261  /**
1262  * Print entry point to code generation
1263  *
1264  */
1265  virtual void print_codegen_routines() = 0;
1266 
1267 
1268  /**
1269  * Print the nmodl constants used in backend code
1270  *
1271  * Currently we define three basic constants, which are assumed to be present in NMODL, directly
1272  * in the backend code:
1273  *
1274  * \code
1275  * static const double FARADAY = 96485.3;
1276  * static const double PI = 3.14159;
1277  * static const double R = 8.3145;
1278  * \endcode
1279  */
1280  void print_nmodl_constants();
1281 
1282 
1283  /****************************************************************************************/
1284  /* Overloaded visitor routines */
1285  /****************************************************************************************/
1286 
1287  void visit_binary_expression(const ast::BinaryExpression& node) override;
1288  void visit_binary_operator(const ast::BinaryOperator& node) override;
1289  void visit_boolean(const ast::Boolean& node) override;
1290  void visit_double(const ast::Double& node) override;
1291  void visit_else_if_statement(const ast::ElseIfStatement& node) override;
1292  void visit_else_statement(const ast::ElseStatement& node) override;
1293  void visit_float(const ast::Float& node) override;
1294  void visit_from_statement(const ast::FromStatement& node) override;
1295  void visit_function_call(const ast::FunctionCall& node) override;
1296  void visit_if_statement(const ast::IfStatement& node) override;
1297  void visit_indexed_name(const ast::IndexedName& node) override;
1298  void visit_integer(const ast::Integer& node) override;
1299  void visit_local_list_statement(const ast::LocalListStatement& node) override;
1300  void visit_name(const ast::Name& node) override;
1301  void visit_paren_expression(const ast::ParenExpression& node) override;
1302  void visit_prime_name(const ast::PrimeName& node) override;
1303  void visit_statement_block(const ast::StatementBlock& node) override;
1304  void visit_string(const ast::String& node) override;
1305  void visit_unary_operator(const ast::UnaryOperator& node) override;
1306  void visit_unit(const ast::Unit& node) override;
1307  void visit_var_name(const ast::VarName& node) override;
1308  void visit_verbatim(const ast::Verbatim& node) override;
1309  void visit_while_statement(const ast::WhileStatement& node) override;
1310  void visit_update_dt(const ast::UpdateDt& node) override;
1311  void visit_protect_statement(const ast::ProtectStatement& node) override;
1312  void visit_mutex_lock(const ast::MutexLock& node) override;
1313  void visit_mutex_unlock(const ast::MutexUnlock& node) override;
1314  void visit_solution_expression(const ast::SolutionExpression& node) override;
1315 
1316  std::string compute_method_name(BlockType type) const;
1317 
1318  public:
1319  /** Setup the target backend code generator
1320  *
1321  * Typically called from within \c visit\_program but may be called from
1322  * specialized targets to setup this Code generator as fallback.
1323  */
1324  void setup(const ast::Program& node);
1325 
1326 
1327  /**
1328  * Main and only member function to call after creating an instance of this class.
1329  * \param program the AST to translate to C++ code
1330  */
1331  void visit_program(const ast::Program& program) override;
1332 
1333 
1334  /****************************************************************************************/
1335  /* Public printing routines for code generation for use in unit tests */
1336  /****************************************************************************************/
1337 
1338 
1339  /**
1340  * Print the structure that wraps all range and int variables required for the NMODL
1341  *
1342  * \param print_initializers Whether or not default values for variables
1343  * be included in the struct declaration.
1344  */
1345  virtual void print_mechanism_range_var_structure(bool print_initializers) = 0;
1346 };
1347 
1348 /* Templated functions need to be defined in header file */
1349 template <typename T>
1350 void CodegenCppVisitor::print_vector_elements(const std::vector<T>& elements,
1351  const std::string& separator,
1352  const std::string& prefix) {
1353  for (auto iter = elements.begin(); iter != elements.end(); iter++) {
1354  printer->add_text(prefix);
1355  (*iter)->accept(*this);
1356  if (!separator.empty() && !nmodl::utils::is_last(iter, elements)) {
1357  printer->add_text(separator);
1358  }
1359  }
1360 }
1361 
1362 
1363 /** \} */ // end of codegen_backends
1364 
1365 } // namespace codegen
1366 } // namespace nmodl
nmodl::codegen::CodegenCppVisitor::print_nrn_constructor
virtual void print_nrn_constructor()=0
Print nrn_constructor function definition.
nmodl::codegen::CodegenCppVisitor::ion_variable_struct_required
bool ion_variable_struct_required() const
Check if a structure for ion variables is required.
Definition: codegen_cpp_visitor.cpp:29
nmodl::utils::is_last
bool is_last(Iter iter, const Cont &cont)
Check if the iterator is pointing to last element in the container.
Definition: common_utils.hpp:37
nmodl::codegen::CodegenCppVisitor::need_semicolon
static bool need_semicolon(const ast::Statement &node)
Check if a semicolon is required at the end of given statement.
Definition: codegen_cpp_visitor.cpp:188
nmodl::ast::UnaryOperator
TODO.
Definition: unary_operator.hpp:38
nmodl::codegen::CodegenCppVisitor::update_index_semantics
void update_index_semantics()
populate all index semantics needed for registration with coreneuron
Definition: codegen_cpp_visitor.cpp:856
nmodl::ast::Unit
TODO.
Definition: unit.hpp:38
nmodl::codegen::CodegenCppVisitor::register_mechanism_arguments
virtual std::string register_mechanism_arguments() const =0
Arguments for register_mech or point_register_mech function.
nmodl::codegen::CodegenCppVisitor::print_g_unused
virtual void print_g_unused() const =0
Set g_unused (conductance) for NRN_PRCELLSTATE feature.
nmodl::codegen::IndexVariableInfo::is_index
bool is_index
if this is pure index (e.g.
Definition: codegen_cpp_visitor.hpp:121
nmodl::ast::Verbatim
Represents a C code block.
Definition: verbatim.hpp:38
nmodl::codegen::CodegenCppVisitor::visit_name
void visit_name(const ast::Name &node) override
visit node of type ast::Name
Definition: codegen_cpp_visitor.cpp:643
nmodl::codegen::CodegenCppVisitor::has_parameter_of_name
bool has_parameter_of_name(const T &node, const std::string &name)
Check if function or procedure node has parameter with given name.
Definition: codegen_cpp_visitor.cpp:54
nmodl::codegen::CodegenCppVisitor::int_variables_size
int int_variables_size() const
Number of integer variables in the model.
Definition: codegen_cpp_visitor.cpp:158
nmodl::codegen::CodegenCppVisitor::print_sdlists_init
virtual void print_sdlists_init(bool print_initializers)=0
nmodl::codegen::CodegenCppVisitor::visit_if_statement
void visit_if_statement(const ast::IfStatement &node) override
visit node of type ast::IfStatement
Definition: codegen_cpp_visitor.cpp:696
nmodl::codegen::MemberType::global
@ global
global variables
nmodl::codegen::CodegenCppVisitor::ion_write_statements
std::vector< ShadowUseStatement > ion_write_statements(BlockType type)
For a given output block type, return statements for writing back ion variables.
Definition: codegen_cpp_visitor.cpp:269
nmodl::codegen::CodegenCppVisitor::visit_else_statement
void visit_else_statement(const ast::ElseStatement &node) override
visit node of type ast::ElseStatement
Definition: codegen_cpp_visitor.cpp:717
nmodl::codegen::IndexVariableInfo
Helper to represent information about index/int variables.
Definition: codegen_cpp_visitor.hpp:111
nmodl::codegen::CodegenCppVisitor::breakpoint_exist
bool breakpoint_exist() const noexcept
Check if breakpoint node exist.
Definition: codegen_cpp_visitor.cpp:127
nmodl::visitor::ConstAstVisitor
Concrete constant visitor for all AST classes.
Definition: ast_visitor.hpp:166
nmodl::codegen::CodegenCppVisitor::print_nrn_current
virtual void print_nrn_current(const ast::BreakpointBlock &node)=0
Print the nrn_current kernel.
nmodl::codegen::BlockType::Destructor
@ Destructor
destructor block
nmodl::codegen::naming::DEFAULT_LOCAL_VAR_TYPE
static constexpr char DEFAULT_LOCAL_VAR_TYPE[]
default local variable type
Definition: codegen_naming.hpp:105
nmodl::codegen::IndexVariableInfo::symbol
const std::shared_ptr< symtab::Symbol > symbol
symbol for the variable
Definition: codegen_cpp_visitor.hpp:113
nmodl::codegen::CodegenCppVisitor::info
codegen::CodegenInfo info
All ast information for code generation.
Definition: codegen_cpp_visitor.hpp:284
nmodl::codegen::CodegenCppVisitor::print_atomic_reduction_pragma
virtual void print_atomic_reduction_pragma()=0
Print atomic update pragma for reduction statements.
nmodl::codegen::CodegenCppVisitor::global_struct_instance
std::string global_struct_instance() const
Name of the (host-only) global instance of global_struct
Definition: codegen_cpp_visitor.hpp:393
nmodl::ast::Double
Represents a double variable.
Definition: double.hpp:53
nmodl::ast::FunctionBlock
TODO.
Definition: function_block.hpp:39
nmodl::codegen::CodegenCppVisitor::write_ion_variable_name
static std::pair< std::string, std::string > write_ion_variable_name(const std::string &name)
Return ion variable name and corresponding ion write variable name.
Definition: codegen_cpp_visitor.cpp:396
nmodl::codegen::CodegenCppVisitor::position_of_float_var
virtual int position_of_float_var(const std::string &name) const =0
Determine the position in the data array for a given float variable.
nmodl::codegen::CodegenCppVisitor::operator_for_d
const char * operator_for_d() const noexcept
Operator for diagonal vector update (matrix update)
Definition: codegen_cpp_visitor.hpp:455
nmodl::codegen::CodegenCppVisitor::optimize_ionvar_copies
bool optimize_ionvar_copies
Flag to indicate if visitor should avoid ion variable copies.
Definition: codegen_cpp_visitor.hpp:278
nmodl::codegen::CodegenCppVisitor::net_receive_exist
bool net_receive_exist() const noexcept
Check if net_receive node exist.
Definition: codegen_cpp_visitor.cpp:122
nmodl::codegen::CodegenCppVisitor::SymbolType
std::shared_ptr< symtab::Symbol > SymbolType
Definition: codegen_cpp_visitor.hpp:238
nmodl::codegen::MemberType::thread
@ thread
thread variables
nmodl::codegen::CodegenCppVisitor::optimize_ion_variable_copies
virtual bool optimize_ion_variable_copies() const =0
Check if ion variable copies should be avoided.
nmodl::codegen::CodegenCppVisitor::nmodl_version
std::string nmodl_version() const noexcept
Return Nmodl language version.
Definition: codegen_cpp_visitor.hpp:356
nmodl::codegen::CodegenCppVisitor::printing_top_verbatim_blocks
bool printing_top_verbatim_blocks
true if currently printing top level verbatim blocks
Definition: codegen_cpp_visitor.hpp:333
nmodl::codegen::CodegenCppVisitor::float_variables_size
int float_variables_size() const
Number of float variables in the model.
Definition: codegen_cpp_visitor.cpp:153
nmodl::codegen::IndexVariableInfo::is_constant
bool is_constant
if the variable is qualified as constant (this is property of IndexVariable)
Definition: codegen_cpp_visitor.hpp:128
nmodl::codegen::CodegenCppVisitor::visit_from_statement
void visit_from_statement(const ast::FromStatement &node) override
visit node of type ast::FromStatement
Definition: codegen_cpp_visitor.cpp:731
nmodl::codegen::CodegenCppVisitor::print_global_var_struct_assertions
virtual void print_global_var_struct_assertions() const
Print static assertions about the global variable struct.
Definition: codegen_cpp_visitor.cpp:407
nmodl::codegen::CodegenCppVisitor::printing_net_init
bool printing_net_init
true if currently initial block of net_receive being printed
Definition: codegen_cpp_visitor.hpp:327
nmodl::codegen::CodegenCppVisitor::print_mechanism_info
void print_mechanism_info()
Print backend code for byte array that has mechanism information (to be registered with NEURON/CoreNE...
Definition: codegen_cpp_visitor.cpp:488
nmodl::codegen::CodegenCppVisitor::print_global_function_common_code
virtual void print_global_function_common_code(BlockType type, const std::string &function_name="")=0
Print common code for global functions like nrn_init, nrn_cur and nrn_state.
nmodl::codegen::CodegenCppVisitor::print_standard_includes
virtual void print_standard_includes()=0
Print standard C/C++ includes.
nmodl::codegen::CodegenCppVisitor::visit_prime_name
void visit_prime_name(const ast::PrimeName &node) override
visit node of type ast::PrimeName
Definition: codegen_cpp_visitor.cpp:653
nmodl::codegen::CodegenCppVisitor::print_nrn_cur_non_conductance_kernel
virtual void print_nrn_cur_non_conductance_kernel()=0
Print the nrn_cur kernel without NMODL conductance keyword provisions.
nmodl::codegen::CodegenCppVisitor::print_function_procedure_helper
virtual void print_function_procedure_helper(const ast::Block &node)=0
Common helper function to help printing function or procedure blocks.
nmodl::codegen::ShadowUseStatement::lhs
std::string lhs
Definition: codegen_cpp_visitor.hpp:151
nmodl::codegen::ShadowUseStatement::rhs
std::string rhs
Definition: codegen_cpp_visitor.hpp:153
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::codegen::MemberType::index
@ index
index / int variables
nmodl::codegen::CodegenCppVisitor::float_data_type
const std::string & float_data_type() const noexcept
Data type for floating point elements specified on command line.
Definition: codegen_cpp_visitor.hpp:431
nmodl::codegen::CodegenCppVisitor::print_function
virtual void print_function(const ast::FunctionBlock &node)=0
Print NMODL function in target backend code.
symbol_table.hpp
Implement classes for representing symbol table at block and file scope.
nmodl::codegen::CodegenCppVisitor::nrn_thread_arguments
virtual std::string nrn_thread_arguments() const =0
Arguments for "_threadargs_" macro in neuron implementation.
nmodl::codegen::CodegenCppVisitor::range_variable_setup_required
bool range_variable_setup_required() const noexcept
Check if setup_range_variable function is required.
Definition: codegen_cpp_visitor.cpp:141
nmodl::ast::MutexLock
Represent MUTEXLOCK statement in NMODL.
Definition: mutex_lock.hpp:38
nmodl::codegen::CodegenCppVisitor::print_statement_block
void print_statement_block(const ast::StatementBlock &node, bool open_brace=true, bool close_brace=true)
Print any statement block in nmodl with option to (not) print braces.
Definition: codegen_cpp_visitor.cpp:526
nmodl::ast::WhileStatement
TODO.
Definition: while_statement.hpp:38
nmodl::codegen::CodegenCppVisitor::global_variable_name
virtual std::string global_variable_name(const SymbolType &symbol, bool use_instance=true) const =0
Determine the variable name for a global variable given its symbol.
nmodl::codegen::CodegenCppVisitor::visit_binary_expression
void visit_binary_expression(const ast::BinaryExpression &node) override
visit node of type ast::BinaryExpression
Definition: codegen_cpp_visitor.cpp:759
nmodl::ast::VarName
Represents a variable.
Definition: var_name.hpp:43
nmodl::ast::Integer
Represents an integer variable.
Definition: integer.hpp:49
nmodl::codegen::BlockType::BlockTypeEnd
@ BlockTypeEnd
fake ending block type for loops on the enums. Keep it at the end
nmodl::codegen::CodegenCppVisitor::get_float_variables
std::vector< SymbolType > get_float_variables() const
Determine all float variables required during code generation.
Definition: codegen_cpp_visitor.cpp:932
nmodl::ast::ElseIfStatement
TODO.
Definition: else_if_statement.hpp:38
nmodl::codegen::CodegenCppVisitor::print_net_move_call
virtual void print_net_move_call(const ast::FunctionCall &node)=0
Print call to net_move.
nmodl::codegen::CodegenCppVisitor::default_int_data_type
const char * default_int_data_type() const noexcept
Default data type for integer (offset) elements.
Definition: codegen_cpp_visitor.hpp:439
nmodl::codegen::CodegenInfo::mod_suffix
std::string mod_suffix
name of the suffix
Definition: codegen_info.hpp:202
nmodl::SymbolType
parser::NmodlParser::symbol_type SymbolType
Definition: nmodl_utils.hpp:26
nmodl::codegen::CodegenInfo
Represent information collected from AST for code generation.
Definition: codegen_info.hpp:197
nmodl::codegen::CodegenCppVisitor::visit_paren_expression
void visit_paren_expression(const ast::ParenExpression &node) override
visit node of type ast::ParenExpression
Definition: codegen_cpp_visitor.cpp:752
nmodl::codegen::CodegenCppVisitor::default_float_data_type
const char * default_float_data_type() const noexcept
Default data type for floating point elements.
Definition: codegen_cpp_visitor.hpp:423
nmodl::codegen::CodegenCppVisitor::net_receive_buffering_required
bool net_receive_buffering_required() const noexcept
Check if net receive/send buffering kernels required.
Definition: codegen_cpp_visitor.cpp:104
nmodl::codegen::CodegenCppVisitor::update_if_ion_variable_name
std::string update_if_ion_variable_name(const std::string &name) const
Determine the updated name if the ion variable has been optimized.
Definition: codegen_cpp_visitor.cpp:373
nmodl::codegen::CodegenCppVisitor::print_nrn_cur_conductance_kernel
virtual void print_nrn_cur_conductance_kernel(const ast::BreakpointBlock &node)=0
Print the nrn_cur kernel with NMODL conductance keyword provisions.
nmodl::codegen::ShadowUseStatement::op
std::string op
Definition: codegen_cpp_visitor.hpp:152
nmodl::codegen::CodegenCppVisitor::visit_mutex_unlock
void visit_mutex_unlock(const ast::MutexUnlock &node) override
visit node of type ast::MutexUnlock
Definition: codegen_cpp_visitor.cpp:836
nmodl::codegen::IndexVariableInfo::is_integer
bool is_integer
if this is an integer (e.g.
Definition: codegen_cpp_visitor.hpp:125
nmodl::codegen::CodegenCppVisitor::int_variable_name
virtual std::string int_variable_name(const IndexVariableInfo &symbol, const std::string &name, bool use_instance) const =0
Determine the name of an int variable given its symbol.
nmodl::codegen::CodegenCppVisitor::visit_unit
void visit_unit(const ast::Unit &node) override
visit node of type ast::Unit
Definition: codegen_cpp_visitor.cpp:648
nmodl::codegen::CodegenCppVisitor::visit_update_dt
void visit_update_dt(const ast::UpdateDt &node) override
visit node of type ast::UpdateDt
Definition: codegen_cpp_visitor.cpp:816
nmodl::codegen::CodegenCppVisitor::print_vector_elements
void print_vector_elements(const std::vector< T > &elements, const std::string &separator, const std::string &prefix="")
Print the items in a vector as a list.
Definition: codegen_cpp_visitor.hpp:1350
nmodl::codegen::IndexVariableInfo::IndexVariableInfo
IndexVariableInfo(std::shared_ptr< symtab::Symbol > symbol, bool is_vdata=false, bool is_index=false, bool is_integer=false)
Definition: codegen_cpp_visitor.hpp:130
nmodl::codegen::naming::DEFAULT_FLOAT_TYPE
static constexpr char DEFAULT_FLOAT_TYPE[]
default float variable type
Definition: codegen_naming.hpp:102
nmodl::codegen::CodegenCppVisitor::get_int_variables
std::vector< IndexVariableInfo > get_int_variables()
Determine all int variables required during code generation.
Definition: codegen_cpp_visitor.cpp:998
codegen_naming.hpp
nmodl::codegen::CodegenCppVisitor::nrn_thread_internal_arguments
virtual std::string nrn_thread_internal_arguments()=0
Arguments for "_threadargs_" macro in neuron implementation.
nmodl::codegen::CodegenCppVisitor::visit_function_call
void visit_function_call(const ast::FunctionCall &node) override
visit node of type ast::FunctionCall
Definition: codegen_cpp_visitor.cpp:797
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::codegen::CodegenCppVisitor::position_of_int_var
virtual int position_of_int_var(const std::string &name) const =0
Determine the position in the data array for a given int variable.
nmodl::ast::LocalListStatement
TODO.
Definition: local_list_statement.hpp:39
nmodl::codegen::CodegenCppVisitor::program_symtab
symtab::SymbolTable * program_symtab
Symbol table for the program.
Definition: codegen_cpp_visitor.hpp:290
nmodl::codegen::BlockType::Equation
@ Equation
breakpoint block
nmodl::codegen::MemberType
MemberType
Helper to represent various variables types.
Definition: codegen_cpp_visitor.hpp:91
nmodl::codegen::CodegenCppVisitor::is_net_move
bool is_net_move(const std::string &name) const noexcept
Checks if given function name is net_move.
Definition: codegen_cpp_visitor.hpp:583
nmodl::ast::Float
Represents a float variable.
Definition: float.hpp:44
nmodl::codegen::CodegenCppVisitor::print_mechanism_global_var_structure
virtual void print_mechanism_global_var_structure(bool print_initializers)=0
Print the structure that wraps all global variables used in the NMODL.
nmodl::ast::BreakpointBlock
Represents a BREAKPOINT block in NMODL.
Definition: breakpoint_block.hpp:53
nmodl::codegen::CodegenCppVisitor::print_compute_functions
virtual void print_compute_functions()=0
Print all compute functions for every backend.
nmodl::codegen::CodegenCppVisitor::codegen_global_variables
std::vector< SymbolType > codegen_global_variables
All global variables for the model.
Definition: codegen_cpp_visitor.hpp:309
nmodl::ast::IndexedName
Represents specific element of an array variable.
Definition: indexed_name.hpp:48
nmodl::ast::FunctionCall
TODO.
Definition: function_call.hpp:38
nmodl::codegen::CodegenCppVisitor::simulator_name
virtual std::string simulator_name()=0
Name of the simulator the code was generated for.
nmodl::codegen::CodegenCppVisitor::setup
void setup(const ast::Program &node)
Setup the target backend code generator.
Definition: codegen_cpp_visitor.cpp:1123
nmodl::codegen::CodegenCppVisitor::visit_unary_operator
void visit_unary_operator(const ast::UnaryOperator &node) override
visit node of type ast::UnaryOperator
Definition: codegen_cpp_visitor.cpp:782
nmodl::codegen::CodegenCppVisitor::visit_mutex_lock
void visit_mutex_lock(const ast::MutexLock &node) override
visit node of type ast::MutexLock
Definition: codegen_cpp_visitor.cpp:829
nmodl::codegen::CodegenCppVisitor::print_net_event_call
virtual void print_net_event_call(const ast::FunctionCall &node)=0
Print call to net_event.
nmodl::codegen::CodegenCppVisitor::visit_boolean
void visit_boolean(const ast::Boolean &node) override
visit node of type ast::Boolean
Definition: codegen_cpp_visitor.cpp:638
nmodl::codegen::CodegenCppVisitor::nrn_cur_required
bool nrn_cur_required() const noexcept
Check if nrn_cur function is required.
Definition: codegen_cpp_visitor.cpp:117
nmodl::ast::ProtectStatement
TODO.
Definition: protect_statement.hpp:38
nmodl::codegen::CodegenCppVisitor::ion_read_statements_optimized
std::vector< std::string > ion_read_statements_optimized(BlockType type) const
For a given output block type, return minimal statements for all read ion variables.
Definition: codegen_cpp_visitor.cpp:253
nmodl::codegen::CodegenCppVisitor::print_net_send_call
virtual void print_net_send_call(const ast::FunctionCall &node)=0
Print call to net_send.
nmodl::codegen::BlockType::Constructor
@ Constructor
constructor block
nmodl::codegen::CodegenCppVisitor::print_codegen_routines
virtual void print_codegen_routines()=0
Print entry point to code generation.
nmodl::ast::MutexUnlock
Represent MUTEXUNLOCK statement in NMODL.
Definition: mutex_unlock.hpp:38
nmodl::codegen::CodegenCppVisitor::conc_write_statement
virtual std::string conc_write_statement(const std::string &ion_name, const std::string &concentration, int index)=0
Generate Function call statement for nrn_wrote_conc.
code_printer.hpp
Helper class for printing C/C++ code.
nmodl::codegen::CodegenCppVisitor::visit_double
void visit_double(const ast::Double &node) override
visit node of type ast::Double
Definition: codegen_cpp_visitor.cpp:633
nmodl::codegen::CodegenCppVisitor::net_send_buffer_required
bool net_send_buffer_required() const noexcept
Check if net_send_buffer is required.
Definition: codegen_cpp_visitor.cpp:94
nmodl::codegen::naming::NMODL_VERSION
static constexpr char NMODL_VERSION[]
nmodl language version
Definition: codegen_naming.hpp:21
nmodl::codegen::CodegenCppVisitor::codegen_int_variables
std::vector< IndexVariableInfo > codegen_int_variables
All int variables for the model.
Definition: codegen_cpp_visitor.hpp:302
nmodl::codegen::CodegenCppVisitor::visit_float
void visit_float(const ast::Float &node) override
visit node of type ast::Float
Definition: codegen_cpp_visitor.cpp:628
nmodl::codegen::CodegenCppVisitor::visit_string
void visit_string(const ast::String &node) override
visit node of type ast::String
Definition: codegen_cpp_visitor.cpp:613
nmodl::codegen::BlockType::Watch
@ Watch
watch block
nmodl::codegen::BlockType::NetReceive
@ NetReceive
net_receive block
nmodl::codegen::CodegenCppVisitor::visit_solution_expression
void visit_solution_expression(const ast::SolutionExpression &node) override
visit node of type ast::SolutionExpression
Definition: codegen_cpp_visitor.cpp:841
nmodl::codegen::CodegenCppVisitor::local_var_type
const char * local_var_type() const noexcept
Data type for the local variables.
Definition: codegen_cpp_visitor.hpp:407
nmodl::codegen::CodegenCppVisitor::print_backend_info
virtual void print_backend_info()=0
Print top file header printed in generated code.
nmodl::codegen::CodegenCppVisitor::print_global_var_struct_decl
virtual void print_global_var_struct_decl()
Instantiate global var instance.
Definition: codegen_cpp_visitor.cpp:420
nmodl::codegen::CodegenCppVisitor::get_channel_info_var_name
std::string get_channel_info_var_name() const noexcept
Name of channel info variable.
Definition: codegen_cpp_visitor.hpp:463
nmodl::codegen::CodegenCppVisitor::print_namespace_begin
virtual void print_namespace_begin()=0
Print start of namespaces.
nmodl::codegen::CodegenCppVisitor::visit_var_name
void visit_var_name(const ast::VarName &node) override
Definition: codegen_cpp_visitor.cpp:661
nmodl::codegen::CodegenCppVisitor::print_nmodl_constants
void print_nmodl_constants()
Print the nmodl constants used in backend code.
Definition: codegen_cpp_visitor.cpp:593
nmodl::ast::PrimeName
Represents a prime variable (for ODE)
Definition: prime_name.hpp:48
nmodl::codegen::CodegenCppVisitor::read_ion_variable_name
static std::pair< std::string, std::string > read_ion_variable_name(const std::string &name)
Return ion variable name and corresponding ion read variable name.
Definition: codegen_cpp_visitor.cpp:390
nmodl::codegen::CodegenCppVisitor::print_namespace_end
virtual void print_namespace_end()=0
Print end of namespaces.
nmodl::ast::IfStatement
TODO.
Definition: if_statement.hpp:39
codegen_info.hpp
Various types to store code generation specific information.
nmodl::ast::Boolean
Represents a boolean variable.
Definition: boolean.hpp:42
nmodl::codegen::naming::DEFAULT_INTEGER_TYPE
static constexpr char DEFAULT_INTEGER_TYPE[]
default integer variable type
Definition: codegen_naming.hpp:108
nmodl::symtab::SymbolTable
Represent symbol table for a NMODL block.
Definition: symbol_table.hpp:57
nmodl::codegen::CodegenCppVisitor::visit_integer
void visit_integer(const ast::Integer &node) override
visit node of type ast::Integer
Definition: codegen_cpp_visitor.cpp:622
nmodl::codegen::CodegenCppVisitor::printing_net_receive
bool printing_net_receive
true if currently net_receive block being printed
Definition: codegen_cpp_visitor.hpp:321
nmodl::codegen::CodegenCppVisitor::process_verbatim_text
virtual std::string process_verbatim_text(std::string const &text)=0
Process a verbatim block for possible variable renaming.
nmodl::ast::UpdateDt
Statement to indicate a change in timestep in a given block.
Definition: update_dt.hpp:38
nmodl::codegen::CodegenCppVisitor::print_global_variables_for_hoc
virtual void print_global_variables_for_hoc()=0
Print byte arrays that register scalar and vector variables for hoc interface.
nmodl::ast::Statement
TODO.
Definition: statement.hpp:38
nmodl::codegen::CodegenCppVisitor::format_float_string
std::string format_float_string(const std::string &value)
Convert a given float value to its string representation.
Definition: codegen_cpp_visitor.cpp:177
nmodl::codegen::CodegenCppVisitor::get_parameter_str
static std::string get_parameter_str(const ParamVector &params)
Generate the string representing the procedure parameter declaration.
Definition: codegen_cpp_visitor.cpp:34
nmodl::codegen::CodegenCppVisitor::print_nrn_cur
virtual void print_nrn_cur()=0
Print nrn_cur / current update function definition.
nmodl::codegen::CodegenCppVisitor::is_net_send
bool is_net_send(const std::string &name) const noexcept
Checks if given function name is net_send.
Definition: codegen_cpp_visitor.hpp:573
nmodl::ast::StatementBlock
Represents block encapsulating list of statements.
Definition: statement_block.hpp:53
nmodl::codegen::CodegenCppVisitor::print_nrn_cur_kernel
virtual void print_nrn_cur_kernel(const ast::BreakpointBlock &node)=0
Print main body of nrn_cur function.
nmodl::codegen::CodegenCppVisitor::net_receive_required
bool net_receive_required() const noexcept
Check if net_receive function is required.
Definition: codegen_cpp_visitor.cpp:132
nmodl::codegen::CodegenCppVisitor::float_variable_name
virtual std::string float_variable_name(const SymbolType &symbol, bool use_instance) const =0
Determine the name of a float variable given its symbol.
nmodl::codegen::CodegenCppVisitor::internal_method_arguments
virtual std::string internal_method_arguments()=0
Arguments for functions that are defined and used internally.
nmodl::codegen::CodegenCppVisitor::global_struct
std::string global_struct() const
Name of structure that wraps global variables.
Definition: codegen_cpp_visitor.hpp:385
nmodl::codegen::CodegenCppVisitor::external_method_parameters
virtual const char * external_method_parameters(bool table=false) noexcept=0
Parameters for functions in generated code that are called back from external code.
nmodl::ast::ParenExpression
TODO.
Definition: paren_expression.hpp:38
nmodl::codegen::CodegenInfo::electrode_current
bool electrode_current
if electrode current specified
Definition: codegen_info.hpp:224
nmodl::codegen::CodegenCppVisitor::rename_function_arguments
void rename_function_arguments()
Rename function/procedure arguments that conflict with default arguments.
Definition: codegen_cpp_visitor.cpp:565
nmodl::codegen::CodegenCppVisitor::internal_method_parameters
virtual ParamVector internal_method_parameters()=0
Parameters for internally defined functions.
nmodl::codegen::CodegenCppVisitor::print_nrn_destructor
virtual void print_nrn_destructor()=0
Print nrn_destructor function definition.
nmodl::codegen::CodegenCppVisitor::visit_local_list_statement
void visit_local_list_statement(const ast::LocalListStatement &node) override
visit node of type ast::LocalListStatement
Definition: codegen_cpp_visitor.cpp:690
nmodl::codegen::CodegenCppVisitor::visit_protect_statement
void visit_protect_statement(const ast::ProtectStatement &node) override
visit node of type ast::ProtectStatement
Definition: codegen_cpp_visitor.cpp:821
nmodl::codegen::ShadowUseStatement
Represents ion write statement during code generation.
Definition: codegen_cpp_visitor.hpp:150
nmodl::ast::ProcedureBlock
TODO.
Definition: procedure_block.hpp:39
nmodl::codegen::CodegenCppVisitor::CodegenCppVisitor
CodegenCppVisitor(std::string mod_filename, std::ostream &stream, std::string float_type, const bool optimize_ionvar_copies, size_t blame_line=0)
Constructs the C++ code generator visitor.
Definition: codegen_cpp_visitor.hpp:226
nmodl::codegen::CodegenCppVisitor::print_mechanism_range_var_structure
virtual void print_mechanism_range_var_structure(bool print_initializers)=0
Print the structure that wraps all range and int variables required for the NMODL.
nmodl::codegen::CodegenCppVisitor::make_symbol
SymbolType make_symbol(const std::string &name) const
Creates a temporary symbol.
Definition: codegen_cpp_visitor.hpp:930
nmodl::codegen::CodegenCppVisitor::CodegenCppVisitor
CodegenCppVisitor(std::string mod_filename, const std::string &output_dir, std::string float_type, const bool optimize_ionvar_copies, size_t blame_line=0)
Constructs the C++ code generator visitor.
Definition: codegen_cpp_visitor.hpp:198
nmodl::codegen::CodegenCppVisitor::float_type
std::string float_type
Data type of floating point variables.
Definition: codegen_cpp_visitor.hpp:272
nmodl::ast::BinaryOperator
Operator used in ast::BinaryExpression.
Definition: binary_operator.hpp:38
nmodl::codegen::CodegenCppVisitor::defined_method
bool defined_method(const std::string &name) const
Check if given method is defined in this model.
Definition: codegen_cpp_visitor.cpp:147
nmodl::codegen::naming::NET_MOVE_METHOD
static constexpr char NET_MOVE_METHOD[]
net_move function call in nmodl
Definition: codegen_naming.hpp:42
logger.hpp
Implement logger based on spdlog library.
nmodl::codegen::CodegenCppVisitor::node_data_struct
std::string node_data_struct() const
Name of structure that wraps node variables.
Definition: codegen_cpp_visitor.hpp:377
nmodl::codegen::IndexVariableInfo::is_vdata
bool is_vdata
if variable resides in vdata field of NrnThread typically true for bbcore pointer
Definition: codegen_cpp_visitor.hpp:117
nmodl::codegen::CodegenCppVisitor::print_function_call
virtual void print_function_call(const ast::FunctionCall &node)
Print call to internal or external function.
Definition: codegen_cpp_visitor.cpp:425
nmodl::ast::SolutionExpression
Represent solution of a block in the AST.
Definition: solution_expression.hpp:38
nmodl::codegen::CodegenCppVisitor::process_shadow_update_statement
std::string process_shadow_update_statement(const ShadowUseStatement &statement, BlockType type)
Process shadow update statement.
Definition: codegen_cpp_visitor.cpp:327
nmodl::codegen::CodegenCppVisitor::enable_variable_name_lookup
bool enable_variable_name_lookup
Variable name should be converted to instance name (but not for function arguments)
Definition: codegen_cpp_visitor.hpp:315
nmodl::codegen::BlockType
BlockType
Helper to represent various block types.
Definition: codegen_cpp_visitor.hpp:56
nmodl::codegen::CodegenCppVisitor::current_watch_statement
int current_watch_statement
Index of watch statement being printed.
Definition: codegen_cpp_visitor.hpp:345
nmodl::codegen::naming::NET_EVENT_METHOD
static constexpr char NET_EVENT_METHOD[]
net_event function call in nmodl
Definition: codegen_naming.hpp:39
nmodl::codegen::CodegenCppVisitor::print_fast_imem_calculation
virtual void print_fast_imem_calculation()=0
Print fast membrane current calculation code.
nmodl::codegen::CodegenCppVisitor::print_mechanism_register
virtual void print_mechanism_register()=0
Print the mechanism registration function.
nmodl::codegen::CodegenCppVisitor::breakpoint_current
std::string breakpoint_current(std::string current) const
Determine the variable name for the "current" used in breakpoint block taking into account intermedia...
Definition: codegen_cpp_visitor.cpp:350
nmodl::codegen::CodegenCppVisitor::visit_binary_operator
void visit_binary_operator(const ast::BinaryOperator &node) override
visit node of type ast::BinaryOperator
Definition: codegen_cpp_visitor.cpp:777
nmodl::codegen::CodegenCppVisitor::visit_else_if_statement
void visit_else_if_statement(const ast::ElseIfStatement &node) override
visit node of type ast::ElseIfStatement
Definition: codegen_cpp_visitor.cpp:709
nmodl::codegen::CodegenCppVisitor
Visitor for printing C++ code compatible with legacy api of CoreNEURON
Definition: codegen_cpp_visitor.hpp:180
nmodl::codegen::CodegenCppVisitor::print_namespace_start
virtual void print_namespace_start()=0
Prints the start of the simulator namespace.
nmodl::codegen::CodegenCppVisitor::instance_struct
std::string instance_struct() const
Name of structure that wraps range variables.
Definition: codegen_cpp_visitor.hpp:370
nmodl::codegen::CodegenCppVisitor::compute_method_name
std::string compute_method_name(BlockType type) const
Definition: codegen_cpp_visitor.cpp:1144
nmodl::codegen::CodegenCppVisitor::external_method_arguments
virtual const char * external_method_arguments() noexcept=0
Arguments for external functions called from generated code.
nmodl::ast::Name
Represents a name.
Definition: name.hpp:44
nmodl::codegen::CodegenCppVisitor::visit_program
void visit_program(const ast::Program &program) override
Main and only member function to call after creating an instance of this class.
Definition: codegen_cpp_visitor.cpp:1167
nmodl::codegen::CodegenCppVisitor::mod_filename
std::string mod_filename
Name of mod file (without .mod suffix)
Definition: codegen_cpp_visitor.hpp:266
nmodl::codegen::CodegenCppVisitor::get_variable_name
virtual std::string get_variable_name(const std::string &name, bool use_instance=true) const =0
Determine variable name in the structure of mechanism properties.
nmodl::ast::Program
Represents top level AST node for whole NMODL input.
Definition: program.hpp:39
nmodl::codegen::CodegenCppVisitor::visit_indexed_name
void visit_indexed_name(const ast::IndexedName &node) override
visit node of type ast::IndexedName
Definition: codegen_cpp_visitor.cpp:680
nmodl::codegen::CodegenCppVisitor::operator_for_rhs
const char * operator_for_rhs() const noexcept
Operator for rhs vector update (matrix update)
Definition: codegen_cpp_visitor.hpp:447
nmodl::codegen::CodegenCppVisitor::print_prcellstate_macros
void print_prcellstate_macros() const
Print declaration of macro NRN_PRCELLSTATE for debugging.
Definition: codegen_cpp_visitor.cpp:481
nmodl::codegen::CodegenCppVisitor::printer
std::unique_ptr< CodePrinter > printer
Code printer object for target (C++)
Definition: codegen_cpp_visitor.hpp:260
nmodl::codegen::CodegenCppVisitor::print_namespace_stop
virtual void print_namespace_stop()=0
Prints the end of the simulator namespace.
nmodl::codegen::CodegenCppVisitor::nrn_state_required
bool nrn_state_required() const noexcept
Check if nrn_state function is required.
Definition: codegen_cpp_visitor.cpp:109
nmodl::codegen::BlockType::State
@ State
derivative block
nmodl::codegen::CodegenCppVisitor::add_escape_quote
std::string add_escape_quote(const std::string &text) const
Add quotes to string to be output.
Definition: codegen_cpp_visitor.hpp:910
nmodl::ast::ElseStatement
TODO.
Definition: else_statement.hpp:38
nmodl::codegen::CodegenCppVisitor::internal_method_call_encountered
bool internal_method_call_encountered
true if internal method call was encountered while processing verbatim block
Definition: codegen_cpp_visitor.hpp:339
nmodl::codegen::CodegenCppVisitor::print_v_unused
virtual void print_v_unused() const =0
Set v_unused (voltage) for NRN_PRCELLSTATE feature.
nmodl::codegen::CodegenCppVisitor::method_name
std::string method_name(const std::string &name) const
Constructs the name of a function or procedure.
Definition: codegen_cpp_visitor.hpp:920
nmodl::codegen::CodegenCppVisitor::visit_verbatim
void visit_verbatim(const ast::Verbatim &node) override
visit node of type ast::Verbatim
Definition: codegen_cpp_visitor.cpp:802
nmodl::codegen::CodegenCppVisitor::is_net_event
bool is_net_event(const std::string &name) const noexcept
Checks if given function name is net_event.
Definition: codegen_cpp_visitor.hpp:593
nmodl::ast::BinaryExpression
Represents binary expression in the NMODL.
Definition: binary_expression.hpp:52
nmodl::codegen::CodegenCppVisitor::print_headers_include
virtual void print_headers_include()=0
Print all includes.
nmodl::codegen::CodegenCppVisitor::codegen_float_variables
std::vector< SymbolType > codegen_float_variables
All float variables for the model.
Definition: codegen_cpp_visitor.hpp:296
nmodl::printer::CodePrinter
Helper class for printing C/C++ code.
Definition: code_printer.hpp:42
nmodl::codegen::BlockType::Initial
@ Initial
initial block
nmodl::codegen::CodegenCppVisitor::statement_to_skip
static bool statement_to_skip(const ast::Statement &node)
Check if given statement should be skipped during code generation.
Definition: codegen_cpp_visitor.cpp:70
nmodl::codegen::CodegenCppVisitor::ion_read_statements
std::vector< std::string > ion_read_statements(BlockType type) const
For a given output block type, return statements for all read ion variables.
Definition: codegen_cpp_visitor.cpp:223
nmodl::codegen::CodegenCppVisitor::print_procedure
virtual void print_procedure(const ast::ProcedureBlock &node)=0
Print NMODL procedure in target backend code.
nmodl::codegen::BlockType::BeforeAfter
@ BeforeAfter
before / after block
nmodl::codegen::CodegenCppVisitor::print_data_structures
virtual void print_data_structures(bool print_initializers)=0
Print all classes.
nmodl::codegen::CodegenCppVisitor::format_double_string
std::string format_double_string(const std::string &value)
Convert a given double value to its string representation.
Definition: codegen_cpp_visitor.cpp:172
nmodl::codegen::CodegenCppVisitor::print_function_or_procedure
virtual void print_function_or_procedure(const ast::Block &node, const std::string &name)=0
Print nmodl function or procedure (common code)
nmodl::ModToken
Represent token returned by scanner.
Definition: modtoken.hpp:50
nmodl::ast::String
Represents a string.
Definition: string.hpp:52
nmodl::codegen::CodegenCppVisitor::print_nrn_state
virtual void print_nrn_state()=0
Print nrn_state / state update function definition.
nmodl::codegen::CodegenCppVisitor::backend_name
virtual std::string backend_name() const =0
Name of the code generation backend.
nmodl::ast::FromStatement
TODO.
Definition: from_statement.hpp:38
nmodl::codegen::CodegenCppVisitor::print_function_prototypes
virtual void print_function_prototypes()=0
Print function and procedures prototype declaration.
nmodl::codegen::naming::NET_SEND_METHOD
static constexpr char NET_SEND_METHOD[]
net_send function call in nmodl
Definition: codegen_naming.hpp:45
nmodl::codegen::CodegenCppVisitor::print_nrn_alloc
virtual void print_nrn_alloc()=0
Print nrn_alloc function definition.
nmodl::codegen::CodegenCppVisitor::visit_while_statement
void visit_while_statement(const ast::WhileStatement &node) override
visit node of type ast::WhileStatement
Definition: codegen_cpp_visitor.cpp:723
nmodl::codegen::MemberType::range
@ range
range / double variables
nmodl::codegen::CodegenCppVisitor::ParamVector
std::vector< std::tuple< std::string, std::string, std::string, std::string > > ParamVector
A vector of parameters represented by a 4-tuple of strings:
Definition: codegen_cpp_visitor.hpp:250
nmodl::codegen::CodegenCppVisitor::visit_statement_block
void visit_statement_block(const ast::StatementBlock &node) override
Definition: codegen_cpp_visitor.cpp:792
ast_visitor.hpp
Concrete visitor for all AST classes.