Commit 827fff94 authored by Lisandro Dalcin's avatar Lisandro Dalcin

C++ fixes (parsing and scope lookup), working libcpp pxd's, more tests

parent bcb29869
...@@ -1022,10 +1022,8 @@ class CppClassNode(CStructOrUnionDefNode): ...@@ -1022,10 +1022,8 @@ class CppClassNode(CStructOrUnionDefNode):
def analyse_declarations(self, env): def analyse_declarations(self, env):
scope = None scope = None
if self.attributes: if self.attributes is not None:
scope = CppClassScope(self.name, env) scope = CppClassScope(self.name, env)
else:
self.attributes = None
base_class_types = [] base_class_types = []
for base_class_name in self.base_classes: for base_class_name in self.base_classes:
base_class_entry = env.lookup(base_class_name) base_class_entry = env.lookup(base_class_name)
......
...@@ -2650,6 +2650,7 @@ def p_cpp_class_definition(s, pos, ctx): ...@@ -2650,6 +2650,7 @@ def p_cpp_class_definition(s, pos, ctx):
s.expect_newline("Expected a newline") s.expect_newline("Expected a newline")
s.expect_dedent() s.expect_dedent()
else: else:
attributes = None
s.expect_newline("Syntax error in C++ class definition") s.expect_newline("Syntax error in C++ class definition")
return Nodes.CppClassNode(pos, return Nodes.CppClassNode(pos,
name = class_name, name = class_name,
......
...@@ -408,7 +408,7 @@ class Scope(object): ...@@ -408,7 +408,7 @@ class Scope(object):
error(pos, "C++ classes may only be extern") error(pos, "C++ classes may only be extern")
if cname is None: if cname is None:
cname = name cname = name
entry = self.lookup(name) entry = self.lookup_here(name)
if not entry: if not entry:
type = PyrexTypes.CppClassType( type = PyrexTypes.CppClassType(
name, scope, cname, base_classes, templates = templates) name, scope, cname, base_classes, templates = templates)
...@@ -432,6 +432,7 @@ class Scope(object): ...@@ -432,6 +432,7 @@ class Scope(object):
for base_class in base_classes: for base_class in base_classes:
declare_inherited_attributes(entry, base_class.base_classes) declare_inherited_attributes(entry, base_class.base_classes)
entry.type.scope.declare_inherited_cpp_attributes(base_class.scope) entry.type.scope.declare_inherited_cpp_attributes(base_class.scope)
if entry.type.scope:
declare_inherited_attributes(entry, base_classes) declare_inherited_attributes(entry, base_classes)
if self.is_cpp_class_scope: if self.is_cpp_class_scope:
entry.type.namespace = self.outer_scope.lookup(self.name).type entry.type.namespace = self.outer_scope.lookup(self.name).type
......
...@@ -3,39 +3,44 @@ from pair cimport pair ...@@ -3,39 +3,44 @@ from pair cimport pair
cdef extern from "<deque>" namespace "std": cdef extern from "<deque>" namespace "std":
cdef cppclass deque[T]: cdef cppclass deque[T]:
cppclass iterator: cppclass iterator:
T operator*() T& operator*()
iterator operator++() iterator operator++()
iterator operator--()
bint operator==(iterator) bint operator==(iterator)
bint operator!=(iterator) bint operator!=(iterator)
cppclass const_iterator(iterator): cppclass reverse_iterator:
pass T& operator*()
cppclass reverse_iterator(iterator): iterator operator++()
pass iterator operator--()
cppclass const_reverse_iterator(iterator): bint operator==(iterator)
pass bint operator!=(iterator)
#cppclass const_iterator(iterator):
# pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
deque() deque()
deque(deque&) deque(deque&)
deque(size_t, T& val = T()) deque(size_t)
#deque(input_iterator, input_iterator) deque(size_t, T&)
TYPE& operator[]( size_type index ) #deque[input_iterator](input_iterator, input_iterator)
const TYPE& operator[]( size_type index ) const T& operator[](size_t)
#deque& operator=(deque&) #deque& operator=(deque&)
bool operator==(deque&, deque&) bint operator==(deque&, deque&)
bool operator!=(deque&, deque&) bint operator!=(deque&, deque&)
bool operator<(deque&, deque&) bint operator<(deque&, deque&)
bool operator>(deque&, deque&) bint operator>(deque&, deque&)
bool operator<=(deque&, deque&) bint operator<=(deque&, deque&)
bool operator>=(deque&, deque&) bint operator>=(deque&, deque&)
void assign(size_t, TYPE&) void assign(size_t, T&)
void assign(input_iterator, input_iterator) void assign(input_iterator, input_iterator)
T& at(size_t) T& at(size_t)
T& back() T& back()
iterator begin() iterator begin()
const_iterator begin() #const_iterator begin()
void clear() void clear()
bool empty() bint empty()
iterator end() iterator end()
const_iterator end() #const_iterator end()
iterator erase(iterator) iterator erase(iterator)
iterator erase(iterator, iterator) iterator erase(iterator, iterator)
T& front() T& front()
...@@ -48,9 +53,10 @@ cdef extern from "<deque>" namespace "std": ...@@ -48,9 +53,10 @@ cdef extern from "<deque>" namespace "std":
void push_back(T&) void push_back(T&)
void push_front(T&) void push_front(T&)
reverse_iterator rbegin() reverse_iterator rbegin()
const_reverse_iterator rbegin() #const_reverse_iterator rbegin()
reverse_iterator rend() reverse_iterator rend()
const_reverse_iterator rend() #const_reverse_iterator rend()
void resize(size_t, T val = T()) void resize(size_t)
void resize(size_t, T&)
size_t size() size_t size()
void swap(deque&) void swap(deque&)
from pair cimport pair
cdef extern from "<list>" namespace "std": cdef extern from "<list>" namespace "std":
cdef cppclass list[T]: cdef cppclass list[T]:
cppclass iterator: cppclass iterator:
T operator*() T& operator*()
iterator operator++() iterator operator++()
iterator operator--()
bint operator==(iterator) bint operator==(iterator)
bint operator!=(iterator) bint operator!=(iterator)
cppclass const_iterator(iterator): cppclass reverse_iterator:
pass T& operator*()
cppclass reverse_iterator(iterator): iterator operator++()
pass iterator operator--()
cppclass const_reverse_iterator(iterator): bint operator==(iterator)
pass bint operator!=(iterator)
#cppclass const_iterator(iterator):
# pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
list() list()
list(list&) list(list&)
list(size_t, T&) list(size_t, T&)
#list operator=(list&) #list operator=(list&)
bool operator==(list&, list&) bint operator==(list&, list&)
bool operator!=(list&, list&) bint operator!=(list&, list&)
bool operator<(list&, list&) bint operator<(list&, list&)
bool operator>(list&, list&) bint operator>(list&, list&)
bool operator<=(list&, list&) bint operator<=(list&, list&)
bool operator>=(list&, list&) bint operator>=(list&, list&)
void assign(size_t, T&) void assign(size_t, T&)
T& back() T& back()
iterator begin() iterator begin()
const_iterator begin() #const_iterator begin()
bool empty() bint empty()
iterator end() iterator end()
const_iterator end() #const_iterator end()
iterator erase(iterator) iterator erase(iterator)
iterator erase(iterator, iterator) iterator erase(iterator, iterator)
T& front() T& front()
...@@ -37,17 +40,17 @@ cdef extern from "<list>" namespace "std": ...@@ -37,17 +40,17 @@ cdef extern from "<list>" namespace "std":
void insert(iterator, size_t, T&) void insert(iterator, size_t, T&)
size_t max_size() size_t max_size()
void merge(list&) void merge(list&)
#voide merge(list&, BinPred) #void merge(list&, BinPred)
void pop_back() void pop_back()
void pop_front() void pop_front()
void push_back(T&) void push_back(T&)
void push_front(T&) void push_front(T&)
reverse_iterator rbegin() reverse_iterator rbegin()
const_reverse_iterator rbegin() #const_reverse_iterator rbegin()
void remove(T&) void remove(T&)
#void remove_if(UnPred) #void remove_if(UnPred)
reverse_iterator rend() reverse_iterator rend()
const_reverse_iterator rend() #const_reverse_iterator rend()
void resize(size_t, T&) void resize(size_t, T&)
void reverse() void reverse()
size_t size() size_t size()
......
from pair cimport pair
cdef extern from "<map>" namespace "std":
cdef cppclass map[T, U]:
cppclass iterator:
pair[T,U]& operator*()
iterator operator++()
iterator operator--()
bint operator==(iterator)
bint operator!=(iterator)
cppclass reverse_iterator:
pair[T,U] operator*()
iterator operator++()
iterator operator--()
bint operator==(iterator)
bint operator!=(iterator)
#cppclass const_iterator(iterator):
# pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
map()
map(map&)
#map(key_compare&)
U& operator[](T&)
#map& operator=(map&)
bint operator==(map&, map&)
bint operator!=(map&, map&)
bint operator<(map&, map&)
bint operator>(map&, map&)
bint operator<=(map&, map&)
bint operator>=(map&, map&)
U& at(T&)
iterator begin()
#const_iterator begin()
void clear()
size_t count(T&)
bint empty()
iterator end()
#const_iterator end()
pair[iterator, iterator] equal_range(T&)
#pair[const_iterator, const_iterator] equal_range(key_type&)
void erase(iterator)
void erase(iterator, iterator)
size_t erase(T&)
iterator find(T&)
#const_iterator find(key_type&)
pair[iterator, bint] insert(pair[T,U]) # XXX pair[T,U]&
iterator insert(iterator, pair[T,U]) # XXX pair[T,U]&
#void insert(input_iterator, input_iterator)
#key_compare key_comp()
iterator lower_bound(T&)
#const_iterator lower_bound(key_type&)
size_t max_size()
reverse_iterator rbegin()
#const_reverse_iterator rbegin()
reverse_iterator rend()
#const_reverse_iterator rend()
size_t size()
void swap(map&)
iterator upper_bound(T&)
#const_iterator upper_bound(key_type&)
#value_compare value_comp()
cdef extern from "pair.h": cdef extern from "<utility>" namespace "std":
cdef cppclass pair[T, U]: cdef cppclass pair[T, U]:
T first T first
U second U second
pair() pair()
pair(pair&)
pair(T&, U&) pair(T&, U&)
from pair cimport pair
cdef extern from "<queue>" namespace "std": cdef extern from "<queue>" namespace "std":
cdef cppclass queue[T]: cdef cppclass queue[T]:
queue() queue()
queue(queue&)
#queue(Container&) #queue(Container&)
T& back() T& back()
bool empty() bint empty()
T& front() T& front()
void pop() void pop()
void push(T&) void push(T&)
size_t size() size_t size()
cdef cppclass priority_queue[T]:
priority_queue()
priority_queue(priority_queue&)
#priority_queue(Container&)
bint empty()
void pop()
void push(T&)
size_t size()
T& top()
...@@ -5,51 +5,56 @@ cdef extern from "<set>" namespace "std": ...@@ -5,51 +5,56 @@ cdef extern from "<set>" namespace "std":
cppclass iterator: cppclass iterator:
T operator*() T operator*()
iterator operator++() iterator operator++()
iterator operator--()
bint operator==(iterator) bint operator==(iterator)
bint operator!=(iterator) bint operator!=(iterator)
cppclass const_iterator(iterator): cppclass reverse_iterator:
pass T operator*()
cppclass reverse_iterator(iterator): iterator operator++()
pass iterator operator--()
cppclass const_reverse_iterator(iterator): bint operator==(iterator)
pass bint operator!=(iterator)
#cppclass const_iterator(iterator):
# pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass
set() set()
set(set&) set(set&)
#set set(key_compare&) #set(key_compare&)
#set& operator=(set&) #set& operator=(set&)
bool operator==(set&, set&) bint operator==(set&, set&)
bool operator!=(set&, set&) bint operator!=(set&, set&)
bool operator<(set&, set&) bint operator<(set&, set&)
bool operator>(set&, set&) bint operator>(set&, set&)
bool operator<=(set&, set&) bint operator<=(set&, set&)
bool operator>=(set&, set&) bint operator>=(set&, set&)
iterator begin() iterator begin()
const_iterator begin() #const_iterator begin()
void clear() void clear()
#size_t count(key_type&) size_t count(T&)
bool empty() bint empty()
iterator end() iterator end()
const_iterator end() #const_iterator end()
#pair[iterator, iterator] equal_range(key_type&) pair[iterator, iterator] equal_range(T&)
#pair[const_iterator, const_iterator] equal_range(key_type&) #pair[const_iterator, const_iterator] equal_range(T&)
void erase(iterator) void erase(iterator)
void erase(iterator, iterator) void erase(iterator, iterator)
#size_t erase(key_type&) size_t erase(T&)
#iterator find(key_type&) iterator find(T&)
#const_iterator find(key_type&) #const_iterator find(T&)
#pair[iterator, bool] insert(T&) pair[iterator, bint] insert(T&)
iterator insert(iterator, T&) iterator insert(iterator, T&)
#void insert(input_iterator, input_iterator) #void insert(input_iterator, input_iterator)
#key_compare key_comp() #key_compare key_comp()
#iterator lower_bound(key_type&) iterator lower_bound(T&)
#const_iterator lower_bound(key_type&) #const_iterator lower_bound(T&)
size_t max_size() size_t max_size()
reverse_iterator rbegin() reverse_iterator rbegin()
const_reverse_iterator rbegin() #const_reverse_iterator rbegin()
reverse_iterator rend() reverse_iterator rend()
const_reverse_iterator rend() #const_reverse_iterator rend()
size_t size() size_t size()
void swap(set&) void swap(set&)
#iterator upper_bound(key_type&) iterator upper_bound(T&)
#const_iterator upper_bound(key_type&) #const_iterator upper_bound(T&)
#value_compare value_comp() #value_compare value_comp()
cdef extern from "<stack>" namespace "std":
cdef cppclass stack[T]:
stack()
stack(stack&)
#stack(Container&)
bint empty()
void pop()
void push(T&)
size_t size()
T& top()
from pair cimport pair
cdef extern from "<vector>" namespace "std": cdef extern from "<vector>" namespace "std":
cdef cppclass vector[T]: cdef cppclass vector[T]:
cppclass iterator: cppclass iterator:
T operator*() T& operator*()
iterator operator++() iterator operator++()
iterator operator--()
bint operator==(iterator) bint operator==(iterator)
bint operator!=(iterator) bint operator!=(iterator)
cppclass const_iterator(iterator): cppclass reverse_iterator:
pass T& operator*()
cppclass reverse_iterator(iterator): iterator operator++()
pass iterator operator--()
cppclass const_reverse_iterator(iterator): bint operator==(iterator)
pass bint operator!=(iterator)
#cppclass input_iterator(iterator): #cppclass const_iterator(iterator):
# pass
#cppclass const_reverse_iterator(reverse_iterator):
# pass # pass
vector() vector()
#vector(vector&) vector(vector&)
#vector(size_t, T&) vector(size_t)
vector(size_t, T&)
#vector[input_iterator](input_iterator, input_iterator) #vector[input_iterator](input_iterator, input_iterator)
T& operator[](size_t) T& operator[](size_t)
#vector& operator=(vector&) #vector& operator=(vector&)
bool operator==(vector&, vector&) bint operator==(vector&, vector&)
bool operator!=(vector&, vector&) bint operator!=(vector&, vector&)
bool operator<(vector&, vector&) bint operator<(vector&, vector&)
bool operator>(vector&, vector&) bint operator>(vector&, vector&)
bool operator<=(vector&, vector&) bint operator<=(vector&, vector&)
bool operator>=(vector&, vector&) bint operator>=(vector&, vector&)
void assign(size_t, T&) void assign(size_t, T&)
#void assign(input_iterator, input_iterator) #void assign[input_iterator](input_iterator, input_iterator)
T& at(size_t) T& at(size_t)
T& back() T& back()
iterator begin() iterator begin()
const_iterator begin() #const_iterator begin()
size_t capacity() size_t capacity()
void clear() void clear()
bool empty() bint empty()
iterator end() iterator end()
const_iterator end() #const_iterator end()
iterator erase(iterator) iterator erase(iterator)
iterator erase(iterator, iterator) iterator erase(iterator, iterator)
T& front() T& front()
...@@ -48,10 +50,11 @@ cdef extern from "<vector>" namespace "std": ...@@ -48,10 +50,11 @@ cdef extern from "<vector>" namespace "std":
void pop_back() void pop_back()
void push_back(T&) void push_back(T&)
reverse_iterator rbegin() reverse_iterator rbegin()
const_reverse_iterator rbegin() #const_reverse_iterator rbegin()
reverse_iterator rend() reverse_iterator rend()
const_reverse_iterator rend() #const_reverse_iterator rend()
void reserve(size_t) void reserve(size_t)
void resize(size_t, T) void resize(size_t)
void resize(size_t, T&)
size_t size() size_t size()
void swap(vector&) void swap(vector&)
cimport libcpp
cimport libcpp.deque
cimport libcpp.list
cimport libcpp.map
cimport libcpp.pair
cimport libcpp.queue
cimport libcpp.set
cimport libcpp.stack
cimport libcpp.vector
from libcpp.deque cimport *
from libcpp.list cimport *
from libcpp.map cimport *
from libcpp.pair cimport *
from libcpp.queue cimport *
from libcpp.set cimport *
from libcpp.stack cimport *
from libcpp.vector cimport *
cdef libcpp.deque.deque[int] d1 = deque[int]()
cdef libcpp.list.list[int] l1 = list[int]()
cdef libcpp.map.map[int,int] m1 = map[int,int]()
cdef libcpp.pair.pair[int,int] p1 = pair[int,int](1,2)
cdef libcpp.queue.queue[int] q1 = queue[int]()
cdef libcpp.set.set[int] s1 = set[int]()
cdef libcpp.stack.stack[int] t1 = stack[int]()
cdef libcpp.vector.vector[int] v1 = vector[int]()
cdef deque[int].iterator id1 = d1.begin()
cdef deque[int].iterator id2 = d1.end()
cdef deque[int].reverse_iterator rid1 = d1.rbegin()
cdef deque[int].reverse_iterator rid2 = d1.rend()
cdef list[int].iterator il1 = l1.begin()
cdef list[int].iterator il2 = l1.end()
cdef list[int].reverse_iterator ril1 = l1.rbegin()
cdef list[int].reverse_iterator ril2 = l1.rend()
cdef map[int,int].iterator im1 = m1.begin()
cdef map[int,int].iterator im2 = m1.end()
cdef map[int,int].reverse_iterator rim1 = m1.rbegin()
cdef map[int,int].reverse_iterator rim2 = m1.rend()
cdef pair[map[int,int].iterator, bint] pimb = m1.insert(p1)
cdef set[int].iterator is1 = s1.begin()
cdef set[int].iterator is2 = s1.end()
cdef set[int].reverse_iterator ris1 = s1.rbegin()
cdef set[int].reverse_iterator ris2 = s1.rend()
cdef pair[set[int].iterator, bint] pisb = s1.insert(4)
cdef vector[int].iterator iv1 = v1.begin()
cdef vector[int].iterator iv2 = v1.end()
cdef vector[int].reverse_iterator riv1 = v1.rbegin()
cdef vector[int].reverse_iterator riv2 = v1.rend()
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