mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C++, code cleanup.
This commit is contained in:
parent
89c3dd81c3
commit
45a8169184
@ -565,7 +565,7 @@ class ASTTemplateKeyParamPackIdDefault(ASTBase):
|
|||||||
if self.parameterPack:
|
if self.parameterPack:
|
||||||
res.append('Dp')
|
res.append('Dp')
|
||||||
else:
|
else:
|
||||||
res.append('0') # we need to put something
|
res.append('0') # we need to put something
|
||||||
return ''.join(res)
|
return ''.join(res)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
@ -871,6 +871,7 @@ class ASTTemplateArgs(ASTBase):
|
|||||||
a.describe_signature(signode, 'markType', env, symbol=symbol)
|
a.describe_signature(signode, 'markType', env, symbol=symbol)
|
||||||
signode += nodes.Text('>')
|
signode += nodes.Text('>')
|
||||||
|
|
||||||
|
|
||||||
class ASTNestedNameElement(ASTBase):
|
class ASTNestedNameElement(ASTBase):
|
||||||
def __init__(self, identifier, templateArgs):
|
def __init__(self, identifier, templateArgs):
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
@ -986,6 +987,7 @@ class ASTNestedName(ASTBase):
|
|||||||
else:
|
else:
|
||||||
raise Exception('Unknown description mode: %s' % mode)
|
raise Exception('Unknown description mode: %s' % mode)
|
||||||
|
|
||||||
|
|
||||||
class ASTTrailingTypeSpecFundamental(ASTBase):
|
class ASTTrailingTypeSpecFundamental(ASTBase):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -1785,7 +1787,7 @@ class ASTTypeWithInit(ASTBase):
|
|||||||
def get_id_v1(self, objectType=None, symbol=None):
|
def get_id_v1(self, objectType=None, symbol=None):
|
||||||
if objectType == 'member':
|
if objectType == 'member':
|
||||||
return symbol.get_full_nested_name().get_id_v1() + u'__' \
|
return symbol.get_full_nested_name().get_id_v1() + u'__' \
|
||||||
+ self.type.get_id_v1()
|
+ self.type.get_id_v1()
|
||||||
else:
|
else:
|
||||||
return self.type.get_id_v1(objectType)
|
return self.type.get_id_v1(objectType)
|
||||||
|
|
||||||
@ -1963,7 +1965,7 @@ class ASTDeclaration(ASTBase):
|
|||||||
self.declaration = declaration
|
self.declaration = declaration
|
||||||
|
|
||||||
self.symbol = None
|
self.symbol = None
|
||||||
self.declarationScope = None # set by Symbol.add_declaration
|
self.declarationScope = None # set by Symbol.add_declaration
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -2052,8 +2054,8 @@ class Symbol(object):
|
|||||||
assert declaration
|
assert declaration
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.templateParams = templateParams # template<templateParams>
|
self.templateParams = templateParams # template<templateParams>
|
||||||
self.templateArgs = templateArgs # identifier<templateArgs>
|
self.templateArgs = templateArgs # identifier<templateArgs>
|
||||||
self.declaration = declaration
|
self.declaration = declaration
|
||||||
|
|
||||||
self.children = []
|
self.children = []
|
||||||
@ -2105,7 +2107,7 @@ class Symbol(object):
|
|||||||
|
|
||||||
def get_full_nested_name(self):
|
def get_full_nested_name(self):
|
||||||
names = []
|
names = []
|
||||||
for nne, _ in self.get_lookup_key():
|
for nne, templateParams in self.get_lookup_key():
|
||||||
names.append(nne)
|
names.append(nne)
|
||||||
return ASTNestedName(names, rooted=False)
|
return ASTNestedName(names, rooted=False)
|
||||||
|
|
||||||
@ -2195,15 +2197,15 @@ class Symbol(object):
|
|||||||
# TODO: it could be a duplicate but let's just insert anyway
|
# TODO: it could be a duplicate but let's just insert anyway
|
||||||
# the id generation will warn about it
|
# the id generation will warn about it
|
||||||
symbol = Symbol(parent=parentSymbol, identifier=identifier,
|
symbol = Symbol(parent=parentSymbol, identifier=identifier,
|
||||||
templateParams=templateParams,
|
templateParams=templateParams,
|
||||||
templateArgs=templateArgs,
|
templateArgs=templateArgs,
|
||||||
declaration=declaration)
|
declaration=declaration)
|
||||||
declaration.declarationScope = declarationScope
|
declaration.declarationScope = declarationScope
|
||||||
else:
|
else:
|
||||||
symbol = Symbol(parent=parentSymbol, identifier=identifier,
|
symbol = Symbol(parent=parentSymbol, identifier=identifier,
|
||||||
templateParams=templateParams,
|
templateParams=templateParams,
|
||||||
templateArgs=templateArgs,
|
templateArgs=templateArgs,
|
||||||
declaration=declaration)
|
declaration=declaration)
|
||||||
if declaration:
|
if declaration:
|
||||||
declaration.declarationScope = declarationScope
|
declaration.declarationScope = declarationScope
|
||||||
return symbol
|
return symbol
|
||||||
@ -2224,10 +2226,10 @@ class Symbol(object):
|
|||||||
operator=None)
|
operator=None)
|
||||||
if symbol is None:
|
if symbol is None:
|
||||||
symbol = Symbol(parent=parentSymbol, identifier=identifier,
|
symbol = Symbol(parent=parentSymbol, identifier=identifier,
|
||||||
templateParams=templateParams,
|
templateParams=templateParams,
|
||||||
templateArgs=templateArgs, declaration=None)
|
templateArgs=templateArgs, declaration=None)
|
||||||
parentSymbol = symbol
|
parentSymbol = symbol
|
||||||
assert False # should have returned in the loop
|
assert False # should have returned in the loop
|
||||||
|
|
||||||
def add_name(self, nestedName, templatePrefix=None):
|
def add_name(self, nestedName, templatePrefix=None):
|
||||||
if templatePrefix:
|
if templatePrefix:
|
||||||
@ -2335,7 +2337,7 @@ class Symbol(object):
|
|||||||
# TODO: maybe search without template args
|
# TODO: maybe search without template args
|
||||||
return None
|
return None
|
||||||
parentSymbol = symbol
|
parentSymbol = symbol
|
||||||
assert False # should have returned in the loop
|
assert False # should have returned in the loop
|
||||||
|
|
||||||
def dump(self, indent):
|
def dump(self, indent):
|
||||||
res = ['\t'*indent]
|
res = ['\t'*indent]
|
||||||
@ -2993,7 +2995,7 @@ class DefinitionParser(object):
|
|||||||
return ASTClass(name, bases)
|
return ASTClass(name, bases)
|
||||||
|
|
||||||
def _parse_enum(self):
|
def _parse_enum(self):
|
||||||
scoped = None # is set by CPPEnumObject
|
scoped = None # is set by CPPEnumObject
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
name = self._parse_nested_name()
|
name = self._parse_nested_name()
|
||||||
self.skip_ws()
|
self.skip_ws()
|
||||||
@ -3220,7 +3222,7 @@ class CPPObject(ObjectDescription):
|
|||||||
if parentSymbol.parent is None:
|
if parentSymbol.parent is None:
|
||||||
# TODO: we could warn, but it is somewhat equivalent to unscoped
|
# TODO: we could warn, but it is somewhat equivalent to unscoped
|
||||||
# enums, without the enum
|
# enums, without the enum
|
||||||
return # no parent
|
return # no parent
|
||||||
parentDecl = parentSymbol.declaration
|
parentDecl = parentSymbol.declaration
|
||||||
if parentDecl is None:
|
if parentDecl is None:
|
||||||
# the parent is not explicitly declared
|
# the parent is not explicitly declared
|
||||||
@ -3239,9 +3241,9 @@ class CPPObject(ObjectDescription):
|
|||||||
if s is not None:
|
if s is not None:
|
||||||
# something is already declared with that name
|
# something is already declared with that name
|
||||||
return
|
return
|
||||||
_ = Symbol(parent=targetSymbol, identifier=symbol.identifier,
|
Symbol(parent=targetSymbol, identifier=symbol.identifier,
|
||||||
templateParams=None, templateArgs=None,
|
templateParams=None, templateArgs=None,
|
||||||
declaration=symbol.declaration.clone())
|
declaration=symbol.declaration.clone())
|
||||||
|
|
||||||
def add_target_and_index(self, ast, sig, signode):
|
def add_target_and_index(self, ast, sig, signode):
|
||||||
# general note: name must be lstrip(':')'ed, to remove "::"
|
# general note: name must be lstrip(':')'ed, to remove "::"
|
||||||
@ -3254,7 +3256,7 @@ class CPPObject(ObjectDescription):
|
|||||||
ids = [id_v2, id_v1]
|
ids = [id_v2, id_v1]
|
||||||
|
|
||||||
newestId = ids[0]
|
newestId = ids[0]
|
||||||
assert newestId # shouldn't be None
|
assert newestId # shouldn't be None
|
||||||
if not re.compile(r'^[a-zA-Z0-9_]*$').match(newestId):
|
if not re.compile(r'^[a-zA-Z0-9_]*$').match(newestId):
|
||||||
self.warn('Index id generation for C++ object "%s" failed, please '
|
self.warn('Index id generation for C++ object "%s" failed, please '
|
||||||
'report as bug (id=%s).' % (text_type(ast), newestId))
|
'report as bug (id=%s).' % (text_type(ast), newestId))
|
||||||
@ -3275,7 +3277,7 @@ class CPPObject(ObjectDescription):
|
|||||||
for id in ids:
|
for id in ids:
|
||||||
if id: # is None when the element didn't exist in that version
|
if id: # is None when the element didn't exist in that version
|
||||||
signode['ids'].append(id)
|
signode['ids'].append(id)
|
||||||
signode['first'] = (not self.names) # hmm, what is this abound?
|
signode['first'] = (not self.names) # hmm, what is this abound?
|
||||||
self.state.document.note_explicit_target(signode)
|
self.state.document.note_explicit_target(signode)
|
||||||
|
|
||||||
def parse_definition(self, parser):
|
def parse_definition(self, parser):
|
||||||
@ -3496,8 +3498,8 @@ class CPPDomain(Domain):
|
|||||||
'enumerator': CPPXRefRole()
|
'enumerator': CPPXRefRole()
|
||||||
}
|
}
|
||||||
initial_data = {
|
initial_data = {
|
||||||
'rootSymbol' : Symbol(None, None, None, None, None),
|
'rootSymbol': Symbol(None, None, None, None, None),
|
||||||
'names': {} # full name for indexing -> docname
|
'names': {} # full name for indexing -> docname
|
||||||
}
|
}
|
||||||
|
|
||||||
def clear_doc(self, docname):
|
def clear_doc(self, docname):
|
||||||
@ -3547,7 +3549,7 @@ class CPPDomain(Domain):
|
|||||||
if not parentSymbol:
|
if not parentSymbol:
|
||||||
print("Target: ", target)
|
print("Target: ", target)
|
||||||
print("ParentKey: ", parentKey)
|
print("ParentKey: ", parentKey)
|
||||||
assert parentSymbol # should be there
|
assert parentSymbol # should be there
|
||||||
else:
|
else:
|
||||||
parentSymbol = rootSymbol
|
parentSymbol = rootSymbol
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user