# -*- Mode: Python -*- # GObject-Introspection - a framework for introspecting GObject libraries # Copyright (C) 2008 Johan Dahlin # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # # AnnotationParser - parses gtk-doc annotations import sys from .ast import (Array, Bitfield, Callback, Class, Enum, Field, Function, Interface, List, Map, Parameter, Record, Return, Type, Union, Varargs, default_array_types, BASIC_GIR_TYPES, PARAM_DIRECTION_INOUT, PARAM_DIRECTION_IN, PARAM_DIRECTION_OUT, PARAM_TRANSFER_NONE, PARAM_TRANSFER_CONTAINER, PARAM_TRANSFER_FULL, TYPE_ANY, TYPE_NONE) from .odict import odict from .glibast import GLibBoxed # All gtk-doc comments needs to start with this: _COMMENT_HEADER = '*\n ' # Tags - annotations applyed to comment blocks TAG_VFUNC = 'virtual' TAG_SINCE = 'since' TAG_DEPRECATED = 'deprecated' TAG_RETURNS = 'returns' TAG_RETURNS_ALT = 'return value' TAG_ATTRIBUTES = 'attributes' TAG_RENAME_TO = 'rename to' # Options - annotations for parameters and return values OPT_ALLOW_NONE = 'allow-none' OPT_ARRAY = 'array' OPT_ELEMENT_TYPE = 'element-type' OPT_IN = 'in' OPT_INOUT = 'inout' OPT_INOUT_ALT = 'in-out' OPT_OUT = 'out' OPT_SCOPE = 'scope' OPT_TRANSFER = 'transfer' OPT_TYPE = 'type' OPT_CLOSURE = 'closure' OPT_DESTROY = 'destroy' # Specific option values OPT_VAL_BITFIELD = 'bitfield' # Array options - array specific annotations OPT_ARRAY_FIXED_SIZE = 'fixed-size' OPT_ARRAY_LENGTH = 'length' OPT_ARRAY_ZERO_TERMINATED = 'zero-terminated' class InvalidAnnotationError(Exception): pass class DocBlock(object): def __init__(self, name, options): self.name = name self.options = options self.value = None self.tags = odict() self.comment = None def __repr__(self): return '' % (self.name, self.options) def get(self, name): if name == TAG_RETURNS: value = self.tags.get(name) if value is None: return self.tags.get(TAG_RETURNS_ALT) else: return value else: return self.tags.get(name) class DocTag(object): def __init__(self, name): self.name = name self.options = {} self.comment = None def __repr__(self): return '' % (self.name, self.options) class Option(object): def __init__(self, option): self._array = [] self._dict = {} for p in option.split(' '): if '=' in p: name, value = p.split('=', 1) else: name = p value = None self._dict[name] = value if value is None: self._array.append(name) else: self._array.append((name, value)) def __repr__(self): return '