-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Documentation For Auto-Generated Constructors & Initializer Lists #4988
Add Documentation For Auto-Generated Constructors & Initializer Lists #4988
Conversation
fixes: shader-slang#4903 Add documentation for auto-generated constructors & Initializer Lists, the logic behind this PR is on shader-slang#4854
int a; | ||
int b = 5; | ||
|
||
__init() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment here:
// because the user has explicitly defined a constructor,
// slang will not synthesize more constructors.
int a; | ||
int b = 5; | ||
|
||
// Implicitly generate: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Slang will automatically generate an implicit constructor:
|
||
2. Auto-generate a 'member-wise constructor' if a conflicting `__init(...)` does not exist, **All members and inherited members have equal visibility** | ||
```c# | ||
struct DontGenerateCtor_Inner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dontgenerate types here aren't necessary.
}; | ||
``` | ||
|
||
2. Auto-generate a 'member-wise constructor' if a conflicting `__init(...)` does not exist, **All members and inherited members have equal visibility** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if such a constructor isn't explicilty defined by the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..., when all members and inherited..
// } | ||
}; | ||
``` | ||
3. Auto-generate a 'member-wise constructor' if a conflicting `__init(...)` does not exist, **not all members and inherited members have equal visibility** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..., when not all
---------- | ||
Initializer List's are an expression of the form `{...}`. | ||
|
||
This form is **different** from declaring a new scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary.
* User does not define any non-default constructor | ||
* User only auto-generates 1 member-wise constructor following rules of [Auto-Generated Constructors](###auto-generated-constructors---struct). | ||
> #### What is a C-Style-Struct - Simplified | ||
> * Never defines a custom `__init(...)`, custom `__init()` are allowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this sentence.
|
||
### Initializer Lists - Struct | ||
|
||
Slang has 2 seperate calling style for an Initializer List with `struct`'s: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" In most scenarios, using an initializer list to create a struct typed value is equivalent to calling the struct's constructor using the elements in the initilaizer list as arguments". For example:
...
"
GenerateCtor1 val[2] = {{ 3 }, { 2 }}; | ||
``` | ||
|
||
2. C-Style-Initializer-List |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"In addition, slang allows provides compatbility support for legacy C-style structs. When the struct type qualifies as a "C-Style" struct, it is allowed to provide less arguments than struct members in an initilaizer list.
A struct is considered a C-style struct if:
- condition1
- condition2
- condition3
For example,
code
".
Fixes: #4903
Add documentation for auto-generated constructors & initializer lists.
The logic behind this PR is on PR #4854.