Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ endmacro ()
if (OSL_BUILD_TESTS)
# List all the individual testsuite tests here, except those that need
# special installed tests.
TESTSUITE ( aastep allowconnect-err and-or-not-synonyms
arithmetic array array-derivs array-range
TESTSUITE ( aastep allowconnect-err and-or-not-synonyms arithmetic
array array-derivs array-range array-aassign
blackbody blendmath breakcont
bug-array-heapoffsets
bug-locallifetime bug-outputinit bug-param-duplicate bug-peep
Expand All @@ -256,7 +256,7 @@ TESTSUITE ( aastep allowconnect-err and-or-not-synonyms
getsymbol-nonheap gettextureinfo
group-outputs groupstring
hash hashnoise hex hyperb
ieee_fp if incdec initops intbits isconnected isconstant
ieee_fp if incdec initlist initops intbits isconnected isconstant
layers layers-Ciassign layers-entry layers-lazy
layers-nonlazycopy layers-repeatedoutputs
linearstep
Expand All @@ -272,6 +272,7 @@ TESTSUITE ( aastep allowconnect-err and-or-not-synonyms
oslc-err-arrayindex oslc-err-closuremul oslc-err-field
oslc-err-format oslc-err-funcoverload
oslc-err-intoverflow oslc-err-noreturn oslc-err-notfunc
oslc-err-initlist-args oslc-err-initlist-return
oslc-err-outputparamvararray oslc-err-paramdefault
oslc-err-struct-array-init oslc-err-struct-ctr
oslc-err-struct-dup oslc-err-struct-print
Expand Down
11 changes: 9 additions & 2 deletions src/liboslcomp/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ ASTvariable_declaration::ASTvariable_declaration (OSLCompilerImpl *comp,
m_isparam(isparam), m_isoutput(isoutput), m_ismetadata(ismeta),
m_initlist(initlist)
{
if (m_initlist && init) {
// Typecheck the init list early.
ASSERT (init->nodetype() == compound_initializer_node);
static_cast<ASTcompound_initializer*>(init)->typecheck(type);
}

m_typespec = type;
Symbol *f = comp->symtab().clash (name);
if (f && ! m_ismetadata) {
Expand Down Expand Up @@ -868,7 +874,8 @@ ASTreturn_statement::childname (size_t i) const

ASTcompound_initializer::ASTcompound_initializer (OSLCompilerImpl *comp,
ASTNode *exprlist)
: ASTNode (compound_initializer_node, comp, Nothing, exprlist)
: ASTtype_constructor (compound_initializer_node, comp, TypeSpec(), exprlist),
m_ctor(false)
{
}

Expand All @@ -877,7 +884,7 @@ ASTcompound_initializer::ASTcompound_initializer (OSLCompilerImpl *comp,
const char *
ASTcompound_initializer::childname (size_t i) const
{
return "expression_list";
return canconstruct() ? "args" : "expression_list";
}


Expand Down
88 changes: 55 additions & 33 deletions src/liboslcomp/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ class ASTNode : public OIIO::RefCnt {
/// Type check a list (whose head is given by 'arg' against the list
/// of expected types given in encoded form by 'formals'.
bool check_arglist (const char *funcname, ref arg,
const char *formals, bool coerce=false);
const char *formals, bool coerce=false,
bool bind = true);

/// Follow a list of nodes, generating code for each in turn, and return
/// the Symbol* for the last thing generated.
Expand Down Expand Up @@ -346,25 +347,23 @@ class ASTNode : public OIIO::RefCnt {
bool copywholearrays, int intindex,
bool paraminit);

// Helper: type check an initializer list -- either a single item to
// a scalar, or a list to an array.
void typecheck_initlist (ref init, TypeSpec type, string_view name);

// Helper: generate code for an initializer list -- either a single
// item to a scalar, or a list to an array.
void codegen_initlist (ref init, TypeSpec type, Symbol *sym);

// Special type checking for structure member initializers.
// It's in the ASTNode base class because it's used from mutiple
// subclasses.
TypeSpec typecheck_struct_initializers (ref init, TypeSpec type,
string_view name);

// Special code generation for structure initializers.
// It's in the ASTNode base class because it's used from mutiple
// subclasses.
Symbol *codegen_struct_initializers (ref init, Symbol *sym,
bool is_constructor=false);
bool is_constructor=false,
Symbol *arrayindex = nullptr);

// Codegen an array assignemnt: lval[index] = src
// If no index is provided the constant i is used.
// Will return either src or a temporary that was codegened.
Symbol*
codegen_aassign (TypeSpec elemtype, Symbol *src, Symbol *lval,
Symbol* index, int i = 0);

// Helper for param_default_literals: generate the string that gives
// the initialization of the literal value (and/or the default, if
Expand Down Expand Up @@ -707,15 +706,58 @@ class ASTreturn_statement : public ASTNode



class ASTcompound_initializer : public ASTNode
class ASTtype_constructor : public ASTNode
{
protected:
ASTtype_constructor (NodeType n, OSLCompilerImpl *c, TypeSpec t, ASTNode *a)
: ASTNode (n, c, Nothing, a) { m_typespec = t; }

public:
ASTtype_constructor (OSLCompilerImpl *comp, TypeSpec typespec,
ASTNode *args)
: ASTtype_constructor (type_constructor_node, comp, typespec, args) {}

const char *nodetypename () const { return "type_constructor"; }
const char *childname (size_t i) const;
Symbol *codegen (Symbol *dest = NULL);

ref args () const { return child (0); }

// Typecheck construction of expected against args()
// Optionally ignoring errors and binding any init-list arguments to the
// required type.
TypeSpec typecheck (TypeSpec expected, bool error, bool bind = true);

// Typecheck construction of m_typespec against args()
TypeSpec typecheck (TypeSpec expected) {
return typecheck (m_typespec, true, true);
}
};


class ASTcompound_initializer : public ASTtype_constructor
{
bool m_ctor;

TypeSpec typecheck (TypeSpec expected, unsigned mode);

public:
ASTcompound_initializer (OSLCompilerImpl *comp, ASTNode *exprlist);
const char *nodetypename () const { return "compound_initializer"; }
const char *childname (size_t i) const;
Symbol *codegen (Symbol *dest = NULL);

ref initlist () const { return child (0); }

bool canconstruct() const { return m_ctor; }
void canconstruct(bool b) { m_ctor = b; }

TypeSpec typecheck (TypeSpec expected) {
return typecheck(expected, 0);
}

// Helper for typechecking an initlist or structure.
class TypeAdjuster;
};


Expand Down Expand Up @@ -840,26 +882,6 @@ class ASTtypecast_expression : public ASTNode



class ASTtype_constructor : public ASTNode
{
public:
ASTtype_constructor (OSLCompilerImpl *comp, TypeSpec typespec,
ASTNode *args)
: ASTNode (type_constructor_node, comp, 0, args)
{
m_typespec = typespec;
}

const char *nodetypename () const { return "type_constructor"; }
const char *childname (size_t i) const;
TypeSpec typecheck (TypeSpec expected);
Symbol *codegen (Symbol *dest = NULL);

ref args () const { return child (0); }
};



class ASTfunction_call : public ASTNode
{
public:
Expand Down
Loading