Skip to content

Instantly share code, notes, and snippets.

@vadz
Last active April 14, 2016 16:41
Show Gist options
  • Select an option

  • Save vadz/4ee306c1fbd54fd7a17e436c5389c3a1 to your computer and use it in GitHub Desktop.

Select an option

Save vadz/4ee306c1fbd54fd7a17e436c5389c3a1 to your computer and use it in GitHub Desktop.

Random Notes About SWIG Objects Attributes

Random Notes About SWIG Objects Attributes

Overview

SWIG parses all declarations in its input in an object tree. Each node of this tree is a DOHHash and developer documentation explains how to navigate this tree.

One thing to notice is that the tree is constructed in two stages: first, the input is just parsed and then pseudo-language TypePass is used to update some of the objects attributes and add new synthetic ones.

Names

There are several different object attributes related to its name:

  • name is always present for any names declaration (e.g. function, class or an enum -- but not if it's an anonymous one for the latter). It is based on the name used in SWIG input sources but, confusingly, this is neither the lead name nor the full name of the C++ identifier: it does include containing class name for a nested declaration but does not include the namespace, if any. Also, this is not a C++ identifier but rather a SWIG type string for the class names, e.g. it could be std::vector<(int)> (notice the extra parentheses), and so can't be used directly in the generated code, use SwigType_str() to obtain a C String representing it.
  • sym:name is the name which will be used in SWIG output.
  • classtype, enumtype, ... is the full C++ name without namespace, if any.

For example, for this code:

enum {
  E0
};

enum E {
  E1 = 1,
  E2
};

class C {
public:
  enum EInC { E3 };
};

namespace N {
enum EInN {
  E4
};

class CInN {
  enum EInCInN { E5 };
};
}

The following values will be used for the listed attributes:

Object name sym:name xxxtype
Anon enum enum
Global enum E E enum E
Global class C C C
Nested enum C::EInC EInC C::EInC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment