MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenShadingLanguage / codegen_arg

Method codegen_arg

src/liboslcomp/codegen.cpp:1832–1883  ·  view source on GitHub ↗

Generate code for one argument to the function, appending its value symbol to argdest and any indexing arguments to index, index2, index3. If the argument a struct, recurse.

Source from the content-addressed store, hash-verified

1830/// symbol to argdest and any indexing arguments to index, index2,
1831/// index3. If the argument a struct, recurse.
1832void
1833ASTfunction_call::codegen_arg (SymbolPtrVec &argdest, SymbolPtrVec &index1,
1834 SymbolPtrVec &index2, SymbolPtrVec &index3,
1835 int argnum, ASTNode *arg,
1836 ASTNode *form, const TypeSpec &formaltype,
1837 bool writearg,
1838 bool &indexed_output_params)
1839{
1840 Symbol *thisarg = NULL;
1841 Symbol *ind1 = NULL, *ind2 = NULL, *ind3 = NULL; // array/component indices
1842
1843 bool is_struct = arg->typespec().is_structure();
1844 if (is_struct) {
1845 // Structure arguments
1846 thisarg = arg->codegen ();
1847 } else if (arg && arg->nodetype() == index_node && writearg) {
1848 // Special case for individual array elements or vec/col/matrix
1849 // components being passed as output params of the function --
1850 // these aren't really lvalues, so we need to restore their
1851 // values. We save the indices we genearate code for here...
1852 ASTindex *indexnode = static_cast<ASTindex *> (arg);
1853 thisarg = indexnode->codegen (NULL, ind1, ind2, ind3);
1854 indexed_output_params = true;
1855 } else {
1856 // Anything else
1857 thisarg = arg->codegen ();
1858 }
1859 // Handle type coercion of the argument
1860 if (!is_struct && formaltype.simpletype() != TypeDesc(TypeDesc::UNKNOWN) &&
1861 formaltype.simpletype() != TypeDesc(TypeDesc::UNKNOWN, -1)) {
1862 Symbol *origarg = thisarg;
1863 thisarg = coerce (thisarg, formaltype);
1864 // Error to type-coerce an output -- where would the result go?
1865 if (thisarg != origarg && form &&
1866 ! equivalent (origarg->typespec(), form->typespec()) &&
1867 form->nodetype() == variable_declaration_node &&
1868 ((ASTvariable_declaration *)form)->is_output()) {
1869 error ("Cannot pass '%s %s' as argument %d to %s\n\t"
1870 "because it is an output parameter that must be a %s",
1871 origarg->typespec().c_str(), origarg->name().c_str(),
1872 argnum+1, user_function()->func()->name().c_str(),
1873 form->typespec().c_str());
1874 }
1875 }
1876 if (thisarg) {
1877 argdest.push_back (thisarg);
1878 index1.push_back (ind1);
1879 index2.push_back (ind2);
1880 index3.push_back (ind3);
1881 } else
1882 arg->error("Invalid argument to function");
1883}
1884
1885
1886

Callers

nothing calls this directly

Calls 10

nodetypeMethod · 0.80
is_outputMethod · 0.80
c_strMethod · 0.80
equivalentFunction · 0.50
errorFunction · 0.50
is_structureMethod · 0.45
codegenMethod · 0.45
nameMethod · 0.45
funcMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected