MCPcopy Create free account
hub / github.com/boostorg/build / var_parse_var_compile

Function var_parse_var_compile

src/engine/function.c:1776–1859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1774 compiler * c );
1775
1776static void var_parse_var_compile( VAR_PARSE_VAR const * parse, compiler * c )
1777{
1778 int expand_name = 0;
1779 int is_get_grist = 0;
1780 int has_modifiers = 0;
1781 /* Special case common modifiers */
1782 if ( parse->modifiers->size == 1 )
1783 {
1784 VAR_PARSE_GROUP * mod = dynamic_array_at( VAR_PARSE_GROUP *, parse->modifiers, 0 );
1785 if ( mod->elems->size == 1 )
1786 {
1787 VAR_PARSE * mod1 = dynamic_array_at( VAR_PARSE *, mod->elems, 0 );
1788 if ( mod1->type == VAR_PARSE_TYPE_STRING )
1789 {
1790 OBJECT * s = ( (VAR_PARSE_STRING *)mod1 )->s;
1791 if ( ! strcmp ( object_str( s ), "G" ) )
1792 {
1793 is_get_grist = 1;
1794 }
1795 }
1796 }
1797 }
1798 /* If there are modifiers, emit them in reverse order. */
1799 if ( parse->modifiers->size > 0 && !is_get_grist )
1800 {
1801 int i;
1802 has_modifiers = 1;
1803 for ( i = 0; i < parse->modifiers->size; ++i )
1804 var_parse_group_compile( dynamic_array_at( VAR_PARSE_GROUP *,
1805 parse->modifiers, parse->modifiers->size - i - 1 ), c );
1806 }
1807
1808 /* If there is a subscript, emit it. */
1809 if ( parse->subscript )
1810 var_parse_group_compile( parse->subscript, c );
1811
1812 /* If the variable name is empty, look it up. */
1813 if ( parse->name->elems->size == 0 )
1814 compile_emit( c, INSTR_PUSH_VAR, compile_emit_constant( c,
1815 constant_empty ) );
1816 /* If the variable name does not need to be expanded, look it up. */
1817 else if ( parse->name->elems->size == 1 && dynamic_array_at( VAR_PARSE *,
1818 parse->name->elems, 0 )->type == VAR_PARSE_TYPE_STRING )
1819 {
1820 OBJECT * const name = ( (VAR_PARSE_STRING *)dynamic_array_at(
1821 VAR_PARSE *, parse->name->elems, 0 ) )->s;
1822 int const idx = get_argument_index( object_str( name ) );
1823 if ( idx != -1 )
1824 compile_emit( c, INSTR_PUSH_ARG, idx );
1825 else
1826 compile_emit( c, INSTR_PUSH_VAR, compile_emit_constant( c, name ) );
1827 }
1828 /* Otherwise, push the var names and use the group instruction. */
1829 else
1830 {
1831 var_parse_group_compile( parse->name, c );
1832 expand_name = 1;
1833 }

Callers 2

var_parse_compileFunction · 0.85
compile_parseFunction · 0.85

Calls 5

object_strFunction · 0.85
var_parse_group_compileFunction · 0.85
compile_emitFunction · 0.85
compile_emit_constantFunction · 0.85
get_argument_indexFunction · 0.85

Tested by

no test coverage detected