Typedef in chisel - hdl

Do we have something similar to typedef in the chisel?
e.g (hypothetical syntax):
typedef UInt(8.W) SHORT;
typedef UInt(64.W) LONG;
Thanks

Related

What is proper way to forward declare NS_OPTIONS in Objective-C\C++

I'm generating bridges from cpp to swift using cpp-objcpp-objc chain and I need to generate NS_OPTIONS.
In ObjC I have it as follows:
#import <Foundation/Foundation.h>
typedef NS_OPTIONS(NSInteger, PhonebookPhoneOptions)
{
PhonebookPhoneOptionsOpt1 = 1 << 0,
PhonebookPhoneOptionsOpt2 = 1 << 1,
PhonebookPhoneOptionsOpt3 = 1 << 2,
PhonebookPhoneOptionsOpt4 = 1 << 3,
};
It is forward-declared in my another header
#import <Foundation/Foundation.h>
typedef NS_OPTIONS(NSInteger, PhonebookPhoneOptions);
//typedef NS_ENUM(NSInteger, PhonebookPhoneOptions);
#protocol PhonebookDataRefreshedCallback
- (void)onEvent:(PhonebookPhoneOptions)param;
When I use NS_OPTIONS forward declaration I'm getting following error:
With NS_ENUM forward it is as folows:
subprojects/controller/service-sbis-phonebook/phonebook/djinni/objc/phonebook/PhonebookDataRefreshedCallback.h:5:53:
error: unnamed enumeration must be a definition typedef
NS_OPTIONS(NSInteger, PhonebookPhoneOptions);
subprojects/controller/service-sbis-phonebook/phonebook/djinni/objc/phonebook/PhonebookDataRefreshedCallback.h:5:9:
error: declaration does not declare anything
[-Werror,-Wmissing-declarations] typedef NS_OPTIONS(NSInteger,
PhonebookPhoneOptions);
With NS_ENUM it is as follows:
subprojects/controller/service-sbis-phonebook/phonebook/djinni/objc/phonebook/PhonebookPhoneOptions.h:6:31:
error: typedef redefinition with different types ('NSInteger' (aka
'long') vs 'enum PhonebookPhoneOptions') typedef NS_OPTIONS(NSInteger,
PhonebookPhoneOptions)
subprojects/controller/service-sbis-phonebook/phonebook/djinni/objc/phonebook/PhonebookDataRefreshedCallback.h:5:28:
note: previous definition is here typedef NS_ENUM(NSInteger,
PhonebookPhoneOptions);
When it was used solely as structure field I got some combination of NS_ENUM\NS_OPTIONS in ObjC\ObjC++ that was working, but when I try to use it as a function argument - it doesn't compile in any of the variants. What is the correct way to do such forward declaration?
I don't think there's a way to forward declare these sensibly. Can't you simply pack the definition into a header file with no other content so it can be #included from just about anywhere? So, have a header file that contains nothing other than your enum, then include/import that from anything that needs it without pulling in any transitive dependencies.
If your problem is that NS_ENUM/NS_OPTIONS isn't available in pure C++, or rather, that #include <Foundation/Foundation.h> does not work there, try CF_ENUM/CF_OPTIONS instead, which are equivalent and defined in <CoreFoundation/CFAvailability.h>, which can be used from any of the C/C++/ObjC/ObjC++.
If that doesn't help you, please update your question to explain in more detail why you are trying to forward declare your enum type. As in, what specific problem arises as a result of not forward declaring the type? (provide minimal repro code)

How to get rid of nullability warning in an objective c typedef?

This code produces a "pointer is missing a nullability type specifier" warning in XCode and I can't guess how to silence the warning.
NS_ASSUME_NONNULL_BEGIN
#interface MyClass : NSObject
typedef id (^MyBlock)(id object);
#end
NS_ASSUME_NONNULL_END
The following don't silence the warning:
typedef __nonnull id (^MyBlock)(__nonnull id object);
typedef nonnull id (^MyBlock)(nonnull id object);
I would appreciate any suggestions.
Thank you.
typedef types don’t usually have an inherent nullability—they can
easily be either nullable or non-nullable depending on the context.
Therefore, typedef types are not assumed to be nonnull, even within
audited regions.[1]
Below syntax is working fine
typedef __nonnull id (^MyBlock)(__nonnull id object);

typedef NS_ENUM vs typedef enum

On the Adopting Modern Objective-C guide, Apple recommends using the NS_ENUM macro instead of enum. I've also read an explanation from NSHipster about NS_ENUM and NS_OPTIONS.
Maybe I've missed something but I don't quite understand what is the difference between the following two snippets and if any why is NS_ENUM the recommended way to go (except maybe, for backwards compatibility with older compilers)
// typedef enum
typedef enum {
SizeWidth,
SizeHeight
}Size;
// typedef NS_ENUM
typedef NS_ENUM(NSInteger, Size) {
SizeWidth,
SizeHeight
};
First, NS_ENUM uses a new feature of the C language where you can specify the underlying type for an enum. In this case, the underlying type for the enum is NSInteger (in plain C it would be whatever the compiler decides, char, short, or even a 24 bit integer if the compiler feels like it).
Second, the compiler specifically recognises the NS_ENUM macro, so it knows that you have an enum with values that shouldn't be combined like flags, the debugger knows what's going on, and the enum can be translated to Swift automatically.
NS_ENUM allows you to define a type. This means that the compiler can check if you're assigning the enum to a different variable like so:
//OK in both cases
NSInteger integer = SizeWidth;
//OK only with typedef
BOOL value = SizeHeight;
NS_ENUM also provides checks in switch statements that you've covered all possible values:
//Will generate warning if using NS_ENUM
switch(sizeVariable) {
case SizeWidth:
//Do something
}

ObjC category on typedef class: "cannot find interface declaration for 'typedefname'"

This code gives me the error Cannot find interface declaration for 'OGWView':
typedef SKNode OGWView;
#interface OGWView (Category)
#end
Why? Shouldn't the category work just as well with a typedef name?
PS: I know I can fix this with a #define (or by using the original class name) but I'm really more interested in understanding why it isn't possible to create a category on a typedef class.
I believe the answer to this question is that you have 2 different kinds of symbol. I believe the typedef is an object and you are trying to use it as a class symbol.
depending on the order of declaration you get different warnings suggesting as much:
typedef NSObject Foo;
#class Foo;
yields:
Redefinition of forward class 'Foo' of a typedef name of an object type is ignored
#class Foo;
typedef NSObject Foo;
yields:
Redefinition of 'Foo' as different kind of symbol
Replace typedef with #compatibility_alias
#compatibility_alias SKNode OGWView;

iOS 4 - Using blocks as a member of a class

I was hoping someone could help me understand the syntax of blocks when used as members of a class. I have some code that's actually working just fine:
#class Structure;
typedef void (^StructureDeleteCallback)(Structure *);
#interface StructureListDelegate : NRFCTableDelegate
{
StructureDeleteCallback _structureDeleteCallback;
}
#property (nonatomic, copy) StructureDeleteCallback structureDeleteCallback;
#end
This works, but I would like to understand the syntax of the typedef statement; and whether or not it's actually required to use typedef.
What I've read says that using typedef in this situation is recommended because it makes the code a lot clearer; but I've been unable to get it to compile at all when trying to do this without typedef. My understanding of typedef was that the syntax was basically:
typedef [actual type] [new name for type];
Such as:
typedef double CLLocationDegrees;
But the syntax of my typedef statement doesn't match this. So my questions are:
How can the syntax of my typedef
statement be so different from other
typedef statements / what does the syntax I'm using actually mean to the compiler?
Is it possible to
have a block as a member of a class
without using typedef?
I myself have asked a question along the lines of yours here: Block references as instance vars in Objective-C
See my answers here and here.