Example #1
0
CppItem& Parser::Item(const String& nameing, const String& nesting, const String& item)
{
	CppItem& im = base->GetAdd(nameing).GetAdd(nesting).GetAdd(TrimRight(Purify(item)));
	im.pname.Clear();
	im.param.Clear();
	im.package = package;
	im.file = filename;
	im.line = line + 1;
	im.name.Clear();
	return im;
}
Example #2
0
String Parser::ReadOper() {
	const char *p = lex.Pos();
	const char *p1 = p;
	Key(tk_operator);
	int level = 0;
	if(Key('('))
		level++;
	for(;;) {
		p1 = lex.Pos();
		if(lex == t_eof) break;
		if(level <= 0 && lex == '(') break;
		if(Key('(') || Key('[')) level++;
		else
		if(Key(')')  || Key(']')) level--;
		else
			++lex;
	}
	return TrimRight(Purify(String(p, p1)));
}
Example #3
0
    performance curvy_step(const Matrix &F, Matrix &D){
        performance data={0,0,0};

        Matrix FD = F * D; data.multiplies++;
        Matrix Eanti = FD - FD.transpose(); data.adds++;
        Matrix Esymm = FD + FD.transpose(); data.adds++;

        Matrix X = Eigen::MatrixXd::Zero(F.cols(), F.rows());
        conjugategradient(F,X,D,Esymm,Eanti,data);

        double scale = 0.001/X.lpNorm<Eigen::Infinity>();
        X = scale * X;

        std::size_t rotation_order = 2;
        BCH_rotate(D, X, rotation_order, data);

        Purify(D, data);

        return data;
    }
Example #4
0
void Parser::Do()
{
	while(lex != t_eof && lex != '}') {
		Line();
		if(Key(tk_using)) {
			while(!Key(';'))
				++lex;
		}
		else
		if(Key(tk_extern) && lex == t_string) {
			++lex;
			++lex;
			if(Key('{')) {
				Do();
				Key('}');
			}
			Key(';');
		}
		else
		if(Key(tk_template)) {
			if(lex.IsId() || lex == tk_class && lex.IsId(1)) {
				Key(tk_class);
				for(;;) {
					if(lex.IsId())
						lex.GetId();
					else
					if(!Key(t_dblcolon))
						break;
				}
				TemplateParams();
				Key(';');
			}
			else {
				String tnames;
				String tparam = TemplateParams(tnames);
				if(!Nest(tparam, tnames)) {
					Array<Decl> r = Declaration(true, true);
					for(int i = 0; i < r.GetCount(); i++) {
						Decl& d = r[i];
						d.natural = "template" + tparam + ' ' + d.natural;
						if(context.access != PRIVATE && !d.isfriend && d.function) {
							CppItem& im = Item(context.nameing, context.nesting, d.natural);
							im.name = d.name;
							im.access = context.access;
							im.header = Purify(d.header);
							im.ender = Purify(d.ender);
							im.kind = context.nesting.IsEmpty() ? FUNCTIONTEMPLATE :
									  d.s_static ? CLASSFUNCTIONTEMPLATE
												 : INSTANCEFUNCTIONTEMPLATE;
							for(int i = 0; i < d.param.GetCount(); i++) {
								ScAdd(im.param, d.param[i].natural);
								ScAdd(im.pname, d.param[i].name);
							}
							im.tname = tnames;
							im.tparam = CleanTp(tparam);
						}
					}
					EatBody();
					Key(';');
				}
			}
		}
		else
		if(lex == tk_enum && (lex[1] == '{' || lex[2] == '{')) {
			++lex;
			String name;
			if(lex.IsId())
				name = lex.GetId();
			String param;
			String pname;
			String n = "enum " + name + " { ";
			Key('{');
			for(;;) {
				String val;
				Check(lex.IsId(), "Expected identifier");
				String nm = lex.GetId();
				if(Key('='))
					val = Constant();
				if(!param.IsEmpty())
					n << ", ";
				n << nm;
				ScAdd(param, nm + " = " + val);
				ScAdd(pname, nm);
				Key(',');
				if(Key('}')) break;
			}
			n << " }";
			CppItem& im = Item(context.nameing, context.nesting, n);
			im.kind = ENUM;
			im.name = name;
			im.access = context.access;
			im.param = param;
			im.pname = pname;
			if(lex.IsId())
				im.name = lex.GetId();
			CheckKey(';');
		}
		else
		if(Key('#')) {
			String n = lex.GetText();
			CppItem& im = Item(context.nameing, context.nesting, n);
			im.kind = MACRO;
			im.name.Clear();
			const char *s = n;
			while(*s && iscid(*s))
				im.name.Cat(*s++);
			s = strchr(n, '(');
			if(s) {
				s++;
				String p;
				for(;;) {
					if(iscid(*s))
						p.Cat(*s++);
					else {
						ScAdd(im.pname, p);
						p.Clear();
						if(*s == ')' || *s == '\0') break;
						s++;
					}
				}
			}
			im.access = context.access;
		}
		else
		if(!Nest(String(), String())) {
			if(Key(tk_public)) {
				context.access = PUBLIC;
				Key(':');
			}
			else
			if(Key(tk_private)) {
				context.access = PRIVATE;
				Key(':');
			}
			else
			if(Key(tk_protected)) {
				context.access = PROTECTED;
				Key(':');
			}
			else {
				const char *p = lex.Pos();
				Array<Decl> r = Declaration(true, true);
				bool body = EatBody();
				for(int i = 0; i < r.GetCount(); i++) {
					Decl& d = r[i];
					if(context.access != PRIVATE && !d.isfriend || d.isfriend && body) {
						CppItem& im = Item(context.nameing, context.nesting, d.natural);
						im.name = d.name;
						im.header = Purify(d.header);
						im.ender = Purify(d.ender);
						im.access = context.access;
						if(d.function) {
							im.kind = d.istructor ? (d.isdestructor ? DESTRUCTOR : CONSTRUCTOR) :
							          d.isfriend ? INLINEFRIEND :
							          context.nesting.IsEmpty() ? FUNCTION :
							          d.s_static ? CLASSFUNCTION : INSTANCEFUNCTION;
							for(int i = 0; i < d.param.GetCount(); i++) {
								ScAdd(im.param, d.param[i].natural);
								ScAdd(im.pname, d.param[i].name);
							}
						}
						else
							im.kind = d.type_def ? TYPEDEF :
							          context.nesting.IsEmpty() ? VARIABLE :
							          d.s_static ? CLASSVARIABLE : INSTANCEVARIABLE;
					}
				}
				EatBody();
				Key(';');
			}
		}
	}
}