当前位置: 首页>>代码示例>>C++>>正文


C++ Lex::ClearDynamic方法代码示例

本文整理汇总了C++中Lex::ClearDynamic方法的典型用法代码示例。如果您正苦于以下问题:C++ Lex::ClearDynamic方法的具体用法?C++ Lex::ClearDynamic怎么用?C++ Lex::ClearDynamic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lex的用法示例。


在下文中一共展示了Lex::ClearDynamic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse_class

void parse_class(Lex& lex, FILE *h, FILE *cpp)
{
	int		t, l, brackets;
	const char	*s, *e;

	do {
		t = lex.GetToken();
		lex.Write(h);
	} while(isspace(t) || t == '\n');
	if(t != Lex::IDENTIFIER) {
		// is it possible that we don't have an identifier after the keyword class?!
		fprintf(stderr, "%s:%ld: error: expected an identifier after the 'class' keyword\n", lex.Filename(), lex.Line());
		g_errcnt++;
		return;
	}
	// we got the class name!
	s = lex.GetStart();
	e = lex.GetEnd();
	l = static_cast<int>(e - s);
	char* class_name = new char[l + 1];
	str_keeper sk(class_name);
	memcpy(class_name, s, l);
	class_name[l] = '\0';

	brackets = 0;
	for(;;) {
		t = lex.GetToken();
		if(t == '\0') {
			// that's a big problem in the source file!
			return;
		}
		if(t == ';') {
			if(brackets == 0) {
				// in this special case, we don't have a full declaration
				// i.e.:   class Stuff;
				lex.Write(h);
				return;
			}
		}
		else if(t == '{') {
			brackets++;
		}
		else if(t == '}') {
			if(brackets == 0) {
				fprintf(stderr, "%s:%ld: error: could not find { in a class definition\n", lex.Filename(), lex.Line());
				g_errcnt++;
			}
			else {
				brackets--;
			}
			if(brackets == 0) {
				break;
			}
		}
		else if(t == Lex::IDENTIFIER) {
			s = lex.GetStart();
			e = lex.GetEnd();
			if(e - s == 5 && memcmp(s, "class", 5) == 0) {
				// warning: this is a recursive call...
				lex.Write(h);
				parse_class(lex, h, cpp);
			}
			else if(e - s == 5 && memcmp(s, "async", 5) == 0) {
				// we found an asynchroneous function
				convert_async(lex, class_name, h, cpp);
				continue;
			}
		}
		lex.Write(h);
	}
	// once a class is being closed, we need to put the dynamic
	// functions if any were defined
	Dynamic *d = lex.GetDynamic();
	if(d != 0) {
		fprintf(h, "public:\n");
		while(d != 0) {
			d->Output(lex, h, cpp, class_name);
			d = d->Next();
		}
	}
	lex.ClearDynamic();
	// we don't expect the lexical input to be messed up by
	// the Dynamic::Output() calls...
	lex.Write(h);
}
开发者ID:m2osw,项目名称:turnwatcher,代码行数:85,代码来源:async_functions.cpp


注:本文中的Lex::ClearDynamic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。