[aspectc-user] where is the mistake ?

MeunS Meunier sylvainmeunier26 at hotmail.com
Wed Aug 3 18:09:08 CEST 2005


Hi, i need help to solve this little problem.

i use this command to weave my aspect : ac++.exe -c main.cc -o 
weaved-main.cc -p . -a contract.ah

When i compile weaved-main.cc with cl (Visual .NET 2003), i obtain this 
error message :

contract.ah(22) : error C2061: erreur de syntaxe : identificateur 
'setAsTree'

thank's in advance

Sylvain Meunier

------------------------------------------------------- FILES 
------------------------------------------------------------

class header :

#ifndef __SETASTREE
#define __SETASTREE

#include <iostream>

class setAsTree
{
public:
	setAsTree(int v);
	setAsTree(const setAsTree& set);

	virtual ~setAsTree();

	setAsTree& operator=(const setAsTree& set);

	void insert(int v);
	setAsTree remove(int v);

	int min() const;
	int max() const;
	bool contains(int v) const;

	int val;
	setAsTree* ltree,* rtree;

	friend std::ostream& operator<<(std::ostream& stream,const setAsTree& set);

private:
	void copy(const setAsTree& set);
	void destroy();
};

std::ostream& operator<<(std::ostream& stream,const setAsTree& set);

#endif

class sources :
#include "./setAsTree.h"

using namespace std;

setAsTree::setAsTree(int v)
{
	ltree = NULL;
	rtree = NULL;
	val = v;
}

setAsTree::setAsTree(const setAsTree& set)
{
	copy(set);
}

setAsTree::~setAsTree()
{
	destroy();
}

setAsTree& setAsTree::operator=(const setAsTree& set)
{
	copy(set);
	return *this;
}

void setAsTree::insert(int v)
{
	if(v > val)
	{
		if(rtree)
			rtree->insert(v);
		else
			rtree = new setAsTree(v);
	}
	else if(v < val)
	{
		if(ltree)
			ltree->insert(v);
		else
			ltree = new setAsTree(v);
	}

}

setAsTree setAsTree::remove(int v)
{
	return *this;
}

int setAsTree::min() const
{
	if(ltree)
		return ltree->max();
	else
		return val;
}

int setAsTree::max() const
{
	if(rtree)
		return rtree->max();
	else
		return val;
}

bool setAsTree::contains(int v) const
{
	if(val == val)
		return true;
	else if(v > val && rtree)
		return rtree->contains(v);
	else if(v < val && ltree)
		return ltree->contains(v);
	else
		return false;
}

void setAsTree::copy(const setAsTree& set)
{
	if(this == &set)
		return;

	destroy();

	if(set.ltree)
		ltree = new setAsTree(*set.ltree);
	else
		ltree = NULL;

	if(set.rtree)
		rtree = new setAsTree(*set.rtree);
	else
		rtree = NULL;

	val = set.val;
}

void setAsTree::destroy()
{
	if(rtree)
	{
		delete rtree;
		rtree = NULL;
	}

	if(ltree)
	{
		delete ltree;
		ltree = NULL;
	}
}

std::ostream& operator<<(std::ostream& stream,const setAsTree& set)
{
	if(set.ltree)
		stream << *set.ltree;

	stream << set.val << " ";

	if(set.rtree)
		stream << *set.rtree;

	return stream;
}

the aspect:

#ifndef __CONTRACT
#define __CONTRACT

#include <iostream>
#include "./setAsTree.h"

aspect contract
{
	pointcut check_invariant(setAsTree& s) =
		(execution("% setAsTree::%(...)") || construction("setAsTree")) && 
that(s);

public:
	advice check_invariant(s) : after(setAsTree& s)
	{

	}

	advice "setAsTree" : bool invariant() const
	{
		return true;
	}
};

#endif

main file:
#include "./setAsTree.h"
#include <iostream>

using namespace std;

int main(int argc,char** argv)
{
	setAsTree set(4);

	set.insert(2);
	set.insert(3);
	set.insert(1);
	set.insert(2);

	cout << set << endl;

	return 0;
}

-------------------------------

_________________________________________________________________
Bénéficiez de 250 Mo de stockage avec MSN Hotmail http://g.msn.fr/FR1001/866




More information about the aspectc-user mailing list