/* Given a string with the contents of a line directly after the "def" keyword, * extract all relevant information and create a tag. */ static void makeFunctionTag (vString *const function, vString *const parent, int is_class_parent, const char *arglist) { tagEntryInfo tag; initTagEntry (&tag, vStringValue (function)); tag.kindName = PythonKinds[K_FUNCTION].name; tag.kind = PythonKinds[K_FUNCTION].letter; tag.extensionFields.arglist = arglist; /* add argument list of __init__() methods to the class tag */ if (strcmp (vStringValue (function), "__init__") == 0 && parent != NULL) { const char *parent_tag_name = get_class_name_from_parent (vStringValue (parent)); if (parent_tag_name != NULL) setTagArglistByName (parent_tag_name, arglist); } if (vStringLength (parent) > 0) { if (is_class_parent) { tag.kindName = PythonKinds[K_METHOD].name; tag.kind = PythonKinds[K_METHOD].letter; tag.extensionFields.scope [0] = "class"; tag.extensionFields.scope [1] = vStringValue (parent); } else { tag.extensionFields.scope [0] = "function"; tag.extensionFields.scope [1] = vStringValue (parent); } } /* If a function starts with __, we mark it as file scope. * FIXME: What is the proper way to signal such attributes? * TODO: What does functions/classes starting with _ and __ mean in python? */ if (strncmp (vStringValue (function), "__", 2) == 0 && strcmp (vStringValue (function), "__init__") != 0) { tag.extensionFields.access = "private"; tag.isFileScope = TRUE; } else { tag.extensionFields.access = "public"; } makeTagEntry (&tag); }
/* Given a string with the contents of a line directly after the "def" keyword, * extract all relevant information and create a tag. */ static void makeFunctionTag (vString *const function, vString *const parent, int is_class_parent, const char *arglist) { pythonAccess access; tagEntryInfo tag; initTagEntry (&tag, vStringValue (function)); tag.kindName = PythonKinds[K_FUNCTION].name; tag.kind = PythonKinds[K_FUNCTION].letter; tag.extensionFields.arglist = arglist; /* add argument list of __init__() methods to the class tag */ if (strcmp (vStringValue (function), "__init__") == 0 && parent != NULL) { const char *parent_tag_name = get_class_name_from_parent (vStringValue (parent)); if (parent_tag_name != NULL) setTagArglistByName (parent_tag_name, arglist); } if (vStringLength (parent) > 0) { if (is_class_parent) { tag.kindName = PythonKinds[K_METHOD].name; tag.kind = PythonKinds[K_METHOD].letter; tag.extensionFields.scope [0] = PythonKinds[K_CLASS].name; tag.extensionFields.scope [1] = vStringValue (parent); } else { tag.extensionFields.scope [0] = PythonKinds[K_FUNCTION].name; tag.extensionFields.scope [1] = vStringValue (parent); } } access = accessFromIdentifier (function); tag.extensionFields.access = PythonAccesses [access]; /* FIXME: should we really set isFileScope in addition to access? */ if (access == A_PRIVATE) tag.isFileScope = TRUE; makeTagEntry (&tag); }
/* Given a string with the contents of a line directly after the "def" keyword, * extract all relevant information and create a tag. */ static void makeFunctionTag (vString *const function, vString *const parent, int is_class_parent, const char *arglist) { tagEntryInfo tag; initTagEntry (&tag, vStringValue (function)); tag.kindName = PythonKinds[K_FUNCTION].name; tag.kind = PythonKinds[K_FUNCTION].letter; tag.extensionFields.arglist = arglist; /* add argument list of __init__() methods to the class tag */ if (strcmp (vStringValue (function), "__init__") == 0 && parent != NULL) { const char *parent_tag_name = get_class_name_from_parent (vStringValue (parent)); if (parent_tag_name != NULL) setTagArglistByName (parent_tag_name, arglist); } if (vStringLength (parent) > 0) { if (is_class_parent) { tag.kindName = PythonKinds[K_METHOD].name; tag.kind = PythonKinds[K_METHOD].letter; tag.extensionFields.scope [0] = PythonKinds[K_CLASS].name; tag.extensionFields.scope [1] = vStringValue (parent); } else { tag.extensionFields.scope [0] = PythonKinds[K_FUNCTION].name; tag.extensionFields.scope [1] = vStringValue (parent); } } addAccessFields (&tag, function, is_class_parent ? K_METHOD : K_FUNCTION, vStringLength (parent) > 0, is_class_parent); makeTagEntry (&tag); }