예제 #1
0
파일: main.c 프로젝트: atommed/OP_repo
int main(int argc, char *argv[]) {
  String *str = new_String(5);
  set_String(str, "ololo");
  for (int i = 0; i < 5; i++)
    printf("%c", str->str[i]);
  free_String(str);
}
예제 #2
0
char *
demangle(char *c)
{
	volatile int i = 0;
	extern jmp_buf jbuf;
	static mutex_t	mlock = DEFAULTMUTEX;

	NOTE(MUTEX_PROTECTS_DATA(mlock, String))
	(void) mutex_lock(&mlock);

	if (setjmp(jbuf)) {
		(void) mutex_unlock(&mlock);
		return (0);
	}

	hold = c;
	s = mk_String(s);
	s = set_String(s, MSG_ORIG(MSG_STR_EMPTY));

	if (c == 0 || *c == 0) {
		c = hold;
		(void) mutex_unlock(&mlock);
		return (c);
	}

	if (strncmp(c, MSG_ORIG(MSG_STR_DBLUNDBAR), 2) != 0) {
		/*
		 * If a name does not begin with a __
		 * but it does contain one, it is either
		 * a member or an overloaded function.
		 */
		while (c[i] && strncmp(c+i, MSG_ORIG(MSG_STR_DBLUNDBAR), 2))
			i++;
		if (c[i]) {
			/* Advance to first non-underscore */
			while (c[i+2] == '_')
				i++;
		}
		if (strncmp(c+i, MSG_ORIG(MSG_STR_DBLUNDBAR), 2) == 0) {
			/* Copy the simple name */
			s = napp_String(s, c, i);
			/* Process the signature */
			c = second(c+i);
			(void) mutex_unlock(&mlock);
			return (c);
		} else {
			c = hold;
			(void) mutex_unlock(&mlock);
			return (c);
		}
	} else {
		const char	*x;
		int		oplen;

		c += 2;

		/*
		 * For automatic variables, or internal static
		 * variables, a __(number) is prepended to the
		 * name.  If this is encountered, strip this off
		 * and return.
		 */
		if (isdigit(*c)) {
			while (isdigit(*c))
				c++;
			(void) mutex_unlock(&mlock);
			return (c);
		}

		/*
		 * Handle operator functions -- this
		 * automatically calls second, since
		 * all operator functions are overloaded.
		 */
		if (x = findop(c, &oplen)) {
			s = app_String(s, MSG_ORIG(MSG_STR_OPERATOR_1));
			s = app_String(s, x);
			c += oplen;
			c = second(c);
			(void) mutex_unlock(&mlock);
			return (c);
		}

		/*
		 * Operator cast does not fit the mould
		 * of the other operators.  Its type name
		 * is encoded.  The cast function must
		 * take a void as an argument.
		 */
		if (strncmp(c, MSG_ORIG(MSG_STR_OP), 2) == 0) {
			int r;
			s = app_String(s, MSG_ORIG(MSG_STR_OPERATOR_2));
			c += 2;
			r = demangle_doarg(&s, c);
			if (r < 0) {
				c = hold;
				(void) mutex_unlock(&mlock);
				return (c);
			}
			c += r;
			c = second(c);
			(void) mutex_unlock(&mlock);
			return (c);
		}

		/*
		 * Constructors and Destructors are also
		 * a special case of operator name.  Note
		 * that the destructor, while overloaded,
		 * must always take the same arguments --
		 * none.
		 */
		if ((*c == 'c' || *c == 'd') &&
		    strncmp(c+1, MSG_ORIG(MSG_STR_TDBLUNDBAR), 3) == 0) {
			int n;
			char *c2 = c+2;
			char cx = c[0];
			c += 4;
			n = getint(&c);
			if (n == 0) {
				c = hold;
				(void) mutex_unlock(&mlock);
				return (c);
			}
			s = napp_String(s, c, n);
			if (cx == 'd')
				s = prep_String(MSG_ORIG(MSG_STR_TILDE), s);
			c = second(c2);
			(void) mutex_unlock(&mlock);
			return (c);
		}
		c = hold;
		(void) mutex_unlock(&mlock);
		return (c);
	}
}