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


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

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


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

示例1: convert_async

void convert_async(Lex& lex, const char *class_name, FILE *h, FILE *cpp)
{
	int		t, l;
	const char	*s, *e;
	Param		*params, *last, *next;
	bool		keep_params, timed_async, dynamic_event;

	keep_params = false;
	timed_async = false;
	dynamic_event = false;

	// we can have multiple dynamic as long as each have a different
	// function name; also, we need to mark them as being timed if
	// the timed flag is also specified
	lex.StartDynamic();

// first we parse the function
	// skip spaces
	do {
		t = lex.GetToken();
	} while(isspace(t) || t == '\n');
	if(t == '\0') {
eof:
		fprintf(stderr, "%s:%ld: error: EOF reached within an async declaration\n", lex.Filename(), lex.Line());
		g_errcnt++;
		return;
	}

	if(t != Lex::IDENTIFIER) {
		fprintf(stderr, "%s:%ld: error: async not followed by an identifier\n", lex.Filename(), lex.Line());
		g_errcnt++;
		return;
	}

	// we expect the name of the function
	s = lex.GetStart();
	e = lex.GetEnd();
	l = static_cast<int>(e - s);
	char* name = new char[l + 1];
	str_keeper sk(name);
	memcpy(name, s, l);
	name[l] = '\0';

	do {
		t = lex.GetToken();
	} while(isspace(t) || t == '\n');
	if(t == '\0') {
		goto eof;
	}

	if(t != '(') {
		fprintf(stderr, "%s:%ld: error: async function name not followed by (\n", lex.Filename(), lex.Line());
		g_errcnt++;
		return;
	}

	// now we read the parameters
	last = params = 0;
	do {
		t = get_param(lex, next);
		if(next != 0) {
			if(last != 0) {
				last->f_next = next;
			}
			if(params == 0) {
				params = next;
			}
			last = next;
		}
	} while(t != ')' && t != '\0');
	if(t == '\0') {
		goto eof;
	}

	// right after the ')' we can have a dynamic attribute!
	// the syntax is:
	//	__attribute__ ((dynamic[([<identifier>])]))
	do {
		 t = lex.GetToken();
	} while(isspace(t) || t == '\n');
	if(t != Lex::IDENTIFIER) {
		goto no_attribute;
	}
	s = lex.GetStart();
	e = lex.GetEnd();
	l = static_cast<int>(e - s);
	if(l != 13 || memcmp(s, "__attribute__", l) != 0) {
		fprintf(stderr, "%s:%ld: error: the keyword __attribute__ or = 0 was expected\n", lex.Filename(), lex.Line());
		g_errcnt++;
		goto skip_attr;
	}
	do {
		 t = lex.GetToken();
	} while(isspace(t) || t == '\n');
	if(t != '(') {
		fprintf(stderr, "%s:%ld: error: the keyword __attribute__ is expected to be followed by two '('\n", lex.Filename(), lex.Line());
		g_errcnt++;
		goto skip_attr;
	}
	do {
//.........这里部分代码省略.........
开发者ID:m2osw,项目名称:turnwatcher,代码行数:101,代码来源:async_functions.cpp

示例2: 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

示例3: get_param

int get_param(Lex& lex, Param *& p)
{
	const char *s, *e;
	int t, paren;
	p = 0;
	for(;;) {
		do {
			t = lex.GetToken();
		} while(isspace(t) || t == '\n');
		if(t == '\0') {
			return t;
		}
		if(t == ',' || t == ')') {
			if(p == 0) {
				if(t == ',') {
					fprintf(stderr, "%s:%ld: error: , not expected here\n", lex.Filename(), lex.Line());
					g_errcnt++;
				}
				return t;
			}
			break;
		}
		if(p == 0) {
			p = new Param;
		}

		if(t == '=') {
			break;
		}
		s = lex.GetStart();
		if(t == '(') {
			p->f_function = true;
			paren = 1;
			do {
				t = lex.GetToken();
				if(t == '(') {
					paren++;
				}
				else if(t == ')') {
					paren--;
				}
			} while(paren != 0 && t != '\0');
		}
		e = lex.GetEnd();

		p->AppendType(s, static_cast<int>(e - s));
	}

// if the type is just 'void' and t is ')' then we don't want it
	if(strcmp(p->f_type, "void") == 0) {
		if(t != ')') {
			fprintf(stderr, "%s:%ld: error: invalid usage of type void\n", lex.Filename(), lex.Line());
			g_errcnt++;
			return t;
		}
		delete p;
		p = 0;
		return t;
	}

// compute the name of the parameter
	p->DefineName();

// special case of default values
	if(t == '=') {
		do {
			t = lex.GetToken();
		} while(isspace(t) || t == '\n');
		if(t == '\0') {
			return t;
		}
		if(t == ',') {
			fprintf(stderr, "%s:%ld: error: default value missing for parameter %s\n", lex.Filename(), lex.Line(), p->f_type);
			g_errcnt++;
			return t;
		}
		s = lex.GetStart();
		do {
			e = lex.GetEnd();
			t = lex.GetToken();
		} while(t != ',' && t != ')' && t != '\0');
		if(t == '\0') {
			return t;
		}
		p->SetDefaultValue(s, static_cast<long>(e - s));
	}

	return t;
}
开发者ID:m2osw,项目名称:turnwatcher,代码行数:89,代码来源:async_functions.cpp


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