source: src/initialization.txt @ 9cb8e88d

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglergc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 9cb8e88d was 9cb8e88d, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

validate constructors and destructors - ensure they return nothing, have at least one parameter, and take a pointer as the first parameter

  • Property mode set to 100644
File size: 2.9 KB
Line 
1From the refrat (5.5) we have our specification:
2
3    \section{Initialization} An expression that is used as an
4    \nonterm{initializer} is treated as being cast to the type of the
5    object being initialized.  An expression used in an
6    \nonterm{initializer-list} is treated as being cast to the type of
7    the aggregate member that it initializes.  In either case the cast
8    must have a single unambiguous
9    interpretation\index{interpretations}.
10
11Steps:
12
13- add a member function "void Resolver::visit( SynTree::DeclStmt
14*declStmt )"; for each DeclStmt:
15
16- do what you need to do to establish correspondences between
17expressions in the initializer and pieces of the object to be
18initialized
19
20- for each initializer expression, construct a cast expression that
21casts the value of the expression to the type of the corresponding
22sub-object
23
24- invoke the resolver recursively on each cast expression; it's an invariant
25of the resolver that attempting to resolve a cast expression results either
26in a single resolved expression (corresponding to the unambiguous interpretation
27referred to above) or a thrown SemanticError.
28
29- construct a new initializer from the resolved expressions
30
31You'll undoubtedly have to play with the CodeGen stuff a bit; I
32hacked it to spit out unresolved initializers for file-scope
33declarations so that real programs would compile.  You'll want to make
34sure that resolved initializers for all declarations are being
35generated.
36
37
38------
39
40More recent email: (I am quoted; Richard is the responder)
41> As far as I'm aware, the only way that I could currently get the correct
42> results from the unification engine is by feeding it an expression that
43> looks like "?=?( ((struct Y)x.y).a, 10 )", then picking out the pieces that
44> I need (namely the correct choice for a). Does this seem like a reasonable
45> approach to solve this problem?
46
47No, unfortunately. Initialization isn't being rewritten as assignment,
48so you shouldn't allow the particular selection of assignment
49operators that happen to be in scope (and which may include
50user-defined operators) to guide the type resolution.
51
52I don't think there is any way to rewrite an initializer as a single
53expression and have the resolver just do the right thing. I see the
54algorithm as:
55
56For each alternative interpretation of the designator:
57  Construct an expression that casts the initializer to the type of
58    the designator
59  Construct an AlternativeFinder and use it to find the lowest cost
60    interpretation of the expression
61  Add this interpretation to a list of possibilities
62Go through the list of possibilities and pick the lowest cost
63
64As with many things in the resolver, it's conceptually simple but the
65implementation may be a bit of a pain. It fits in with functions like
66findSingleExpression, findIntegralExpression in Resolver.cc, although
67it will be significantly more complicated than any of the existing
68ones.
69
70
71
Note: See TracBrowser for help on using the repository browser.