Commit 5326aee8 authored by Xavier Thompson's avatar Xavier Thompson

Introduce 'mutable' specifier from C++

parent c5c45ac3
......@@ -1628,6 +1628,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("%s;" % dunder_activate_entry.type.declaration_code(dunder_activate_entry.cname))
for attr in scope.var_entries:
cname = attr.cname
if attr.is_mutable:
code.put("mutable ")
if attr.type.is_cfunction and attr.type.is_static_method:
code.put("static ")
elif attr.name == "<init>":
......
......@@ -1423,6 +1423,8 @@ class CVarDefNode(StatNode):
cfunc_declarator.args = []
cfunc_declarator.skipped_self = None
if 'mutable' in self.modifiers:
error(self.pos, "Functions cannot be 'mutable'")
self.entry = dest_scope.declare_cfunction(
name, type, declarator.pos,
cname=cname, visibility=self.visibility, in_pxd=self.in_pxd,
......@@ -1447,6 +1449,10 @@ class CVarDefNode(StatNode):
api=self.api, is_cdef=1)
if Options.docstrings:
self.entry.doc = embed_position(self.pos, self.doc)
if 'mutable' in self.modifiers:
if not dest_scope.is_cpp_class_scope:
error(self.pos, "Specifier 'mutable' can only apply to cppclass variable members")
self.entry.is_mutable = 1
class CStructOrUnionDefNode(StatNode):
......@@ -2689,6 +2695,8 @@ class CFuncDefNode(FuncDefNode):
typ.is_static_method = self.is_static_method
typ.is_cyp_class_method = self.is_cyp_class_method
if 'mutable' in self.modifiers:
error(self.pos, "Functions cannot be 'mutable'")
self.entry = env.declare_cfunction(
name, typ, self.pos,
cname=cname, visibility=self.visibility, api=self.api,
......
......@@ -3332,7 +3332,7 @@ def p_visibility(s, prev_visibility):
return visibility
def p_c_modifiers(s):
if s.sy == 'IDENT' and s.systring in ('inline',):
if s.sy == 'IDENT' and s.systring in ('inline', 'mutable'):
modifier = s.systring
s.next()
return [modifier] + p_c_modifiers(s)
......
......@@ -105,6 +105,7 @@ class Entry(object):
# is_cclass boolean Is an extension class
# is_cpp_class boolean Is a C++ class
# is_const boolean Is a constant
# is_mutable boolean Is a mutable attribute
# is_property boolean Is a property of an extension type:
# doc_cname string or None C const holding the docstring
# getter_cname string C func for getting property
......@@ -201,6 +202,7 @@ class Entry(object):
is_cclass = 0
is_cpp_class = 0
is_const = 0
is_mutable = 0
is_property = 0
is_cproperty = 0
doc_cname = None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment