Example #1
0
static int
get_punctuator (struct macro_buffer *tok, char *p, char *end)
{
  /* Here, speed is much less important than correctness and clarity.  */

  /* ISO/IEC 9899:1999 (E)  Section 6.4.6  Paragraph 1.
     Note that this table is ordered in a special way.  A punctuator
     which is a prefix of another punctuator must appear after its
     "extension".  Otherwise, the wrong token will be returned.  */
  static const char * const punctuators[] = {
    "[", "]", "(", ")", "{", "}", "?", ";", ",", "~",
    "...", ".",
    "->", "--", "-=", "-",
    "++", "+=", "+",
    "*=", "*",
    "!=", "!",
    "&&", "&=", "&",
    "/=", "/",
    "%>", "%:%:", "%:", "%=", "%",
    "^=", "^",
    "##", "#",
    ":>", ":",
    "||", "|=", "|",
    "<<=", "<<", "<=", "<:", "<%", "<",
    ">>=", ">>", ">=", ">",
    "==", "=",
    0
  };

  int i;

  if (p + 1 <= end)
    {
      for (i = 0; punctuators[i]; i++)
        {
          const char *punctuator = punctuators[i];

          if (p[0] == punctuator[0])
            {
              int len = strlen (punctuator);

              if (p + len <= end
                  && ! memcmp (p, punctuator, len))
                {
                  set_token (tok, p, p + len);
                  return 1;
                }
            }
        }
    }

  return 0;
}
Example #2
0
File: macroexp.c Project: 5kg/gdb
static int
get_comment (struct macro_buffer *tok, char *p, char *end)
{
  if (p + 2 > end)
    return 0;
  else if (p[0] == '/'
           && p[1] == '*')
    {
      char *tok_start = p;

      p += 2;

      for (; p < end; p++)
        if (p + 2 <= end
            && p[0] == '*'
            && p[1] == '/')
          {
            p += 2;
            set_token (tok, tok_start, p);
            return 1;
          }

      error (_("Unterminated comment in macro expansion."));
    }
  else if (p[0] == '/'
           && p[1] == '/')
    {
      char *tok_start = p;

      p += 2;
      for (; p < end; p++)
        if (*p == '\n')
          break;

      set_token (tok, tok_start, p);
      return 1;
    }
  else
    return 0;
}
Example #3
0
File: macroexp.c Project: 5kg/gdb
/* If the text starting at P going up to (but not including) END
   starts with a character constant, set *TOK to point to that
   character constant, and return 1.  Otherwise, return zero.
   Signal an error if it contains a malformed or incomplete character
   constant.  */
static int
get_character_constant (struct macro_buffer *tok, char *p, char *end)
{
  /* ISO/IEC 9899:1999 (E)  Section 6.4.4.4  paragraph 1 
     But of course, what really matters is that we handle it the same
     way GDB's C/C++ lexer does.  So we call parse_escape in utils.c
     to handle escape sequences.  */
  if ((p + 1 <= end && *p == '\'')
      || (p + 2 <= end
	  && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
	  && p[1] == '\''))
    {
      char *tok_start = p;
      int char_count = 0;

      if (*p == '\'')
        p++;
      else if (*p == 'L' || *p == 'u' || *p == 'U')
        p += 2;
      else
        gdb_assert_not_reached ("unexpected character constant");

      for (;;)
        {
          if (p >= end)
            error (_("Unmatched single quote."));
          else if (*p == '\'')
            {
              if (!char_count)
                error (_("A character constant must contain at least one "
                       "character."));
              p++;
              break;
            }
          else if (*p == '\\')
            {
              p++;
	      char_count += c_parse_escape (&p, NULL);
            }
          else
	    {
	      p++;
	      char_count++;
	    }
        }

      set_token (tok, tok_start, p);
      return 1;
    }
  else
    return 0;
}
Example #4
0
static int step_before_quit(int status) {
	static int remaining = 20;
	remaining--;
	if(remaining == 15 && !is_master()) {
		set_token(getpid());
	}
	if(remaining == 10 && !is_master()) {
		get_token(getpid());
	}
	if(!remaining)
		fiber_quit();
	return 0;
}
Example #5
0
struct token *make_token(
    const token_class_t token_class,
    const char *text,
    const int leng,
    const struct kw_conf *kw_setting,
    const size_t indent)
{
    struct token *tok;
    tok = malloc(sizeof(struct token));
    assert(tok);
    set_token(tok, token_class, text, leng, kw_setting, indent);
    return tok;
}
Example #6
0
/* If the text starting at P going up to (but not including) END
   starts with a string literal, set *TOK to point to that string
   literal, and return 1.  Otherwise, return zero.  Signal an error if
   it contains a malformed or incomplete string literal.  */
static int
get_string_literal (struct macro_buffer *tok, char *p, char *end)
{
  if ((p + 1 <= end
       && *p == '"')
      || (p + 2 <= end
          && (p[0] == 'L' || p[0] == 'u' || p[0] == 'U')
          && p[1] == '"'))
    {
      char *tok_start = p;

      if (*p == '"')
        p++;
      else if (*p == 'L' || *p == 'u' || *p == 'U')
        p += 2;
      else
        gdb_assert_not_reached ("unexpected string literal");

      for (;;)
        {
          if (p >= end)
            error (_("Unterminated string in expression."));
          else if (*p == '"')
            {
              p++;
              break;
            }
          else if (*p == '\n')
            error (_("Newline characters may not appear in string "
                   "constants."));
          else if (*p == '\\')
            {
	      const char *s, *o;

	      s = o = ++p;
	      c_parse_escape (&s, NULL);
	      p += s - o;
            }
          else
            p++;
        }

      set_token (tok, tok_start, p);
      return 1;
    }
  else
    return 0;
}
Example #7
0
/* If the text starting at P going up to (but not including) END
   starts with a character constant, set *TOK to point to that
   character constant, and return 1.  Otherwise, return zero.
   Signal an error if it contains a malformed or incomplete character
   constant.  */
static int
get_character_constant (struct macro_buffer *tok, char *p, char *end)
{
  /* ISO/IEC 9899:1999 (E)  Section 6.4.4.4  paragraph 1 
     But of course, what really matters is that we handle it the same
     way GDB's C/C++ lexer does.  So we call parse_escape in utils.c
     to handle escape sequences.  */
  if ((p + 1 <= end && *p == '\'')
      || (p + 2 <= end && p[0] == 'L' && p[1] == '\''))
    {
      char *tok_start = p;
      char *body_start;

      if (*p == '\'')
        p++;
      else if (*p == 'L')
        p += 2;
      else
        gdb_assert (0);

      body_start = p;
      for (;;)
        {
          if (p >= end)
            error ("Unmatched single quote.");
          else if (*p == '\'')
            {
              if (p == body_start)
                error ("A character constant must contain at least one "
                       "character.");
              p++;
              break;
            }
          else if (*p == '\\')
            {
              p++;
              parse_escape (&p);
            }
          else
            p++;
        }

      set_token (tok, tok_start, p);
      return 1;
    }
  else
    return 0;
}
Example #8
0
void RseLogin::MergeFrom(const RseLogin& from) {
  GOOGLE_CHECK_NE(&from, this);
  if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
    if (from._has_bit(0)) {
      set_currenttimemillis(from.currenttimemillis());
    }
    if (from._has_bit(1)) {
      set_id(from.id());
    }
    if (from._has_bit(2)) {
      set_levelbasedonscore(from.levelbasedonscore());
    }
    if (from._has_bit(3)) {
      set_myaccountislocked(from.myaccountislocked());
    }
    if (from._has_bit(4)) {
      set_pop(from.pop());
    }
    if (from._has_bit(5)) {
      set_rqid(from.rqid());
    }
    if (from._has_bit(6)) {
      set_sync(from.sync());
    }
    if (from._has_bit(7)) {
      set_timefromlastlogin(from.timefromlastlogin());
    }
  }
  if (from._has_bits_[8 / 32] & (0xffu << (8 % 32))) {
    if (from._has_bit(8)) {
      set_timefromlastupdate(from.timefromlastupdate());
    }
    if (from._has_bit(9)) {
      set_token(from.token());
    }
    if (from._has_bit(10)) {
      set_userid(from.userid());
    }
    if (from._has_bit(11)) {
      set_version(from.version());
    }
    if (from._has_bit(12)) {
      set_vip(from.vip());
    }
  }
  mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
Example #9
0
/* If the text starting at P going up to (but not including) END
   starts with a string literal, set *TOK to point to that string
   literal, and return 1.  Otherwise, return zero.  Signal an error if
   it contains a malformed or incomplete string literal.  */
static int
get_string_literal (struct macro_buffer *tok, char *p, char *end)
{
  if ((p + 1 <= end
       && *p == '\"')
      || (p + 2 <= end
          && p[0] == 'L'
          && p[1] == '\"'))
    {
      char *tok_start = p;

      if (*p == '\"')
        p++;
      else if (*p == 'L')
        p += 2;
      else
        gdb_assert (0);

      for (;;)
        {
          if (p >= end)
            error ("Unterminated string in expression.");
          else if (*p == '\"')
            {
              p++;
              break;
            }
          else if (*p == '\n')
            error ("Newline characters may not appear in string "
                   "constants.");
          else if (*p == '\\')
            {
              p++;
              parse_escape (&p);
            }
          else
            p++;
        }

      set_token (tok, tok_start, p);
      return 1;
    }
  else
    return 0;
}
Example #10
0
static int
get_punctuator (struct macro_buffer *tok, char *p, char *end)
{
  /* Here, speed is much less important than correctness and clarity.  */

  /* ISO/IEC 9899:1999 (E)  Section 6.4.6  Paragraph 1  */
  static const char * const punctuators[] = {
    "[", "]", "(", ")", "{", "}", ".", "->", 
    "++", "--", "&", "*", "+", "-", "~", "!",
    "/", "%", "<<", ">>", "<", ">", "<=", ">=", "==", "!=", 
    "^", "|", "&&", "||",
    "?", ":", ";", "...",
    "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=",
    ",", "#", "##",
    "<:", ":>", "<%", "%>", "%:", "%:%:",
    0
  };

  int i;

  if (p + 1 <= end)
    {
      for (i = 0; punctuators[i]; i++)
        {
          const char *punctuator = punctuators[i];

          if (p[0] == punctuator[0])
            {
              int len = strlen (punctuator);

              if (p + len <= end
                  && ! memcmp (p, punctuator, len))
                {
                  set_token (tok, p, p + len);
                  return 1;
                }
            }
        }
    }

  return 0;
}
Example #11
0
File: macroexp.c Project: 5kg/gdb
static int
get_identifier (struct macro_buffer *tok, char *p, char *end)
{
  if (p < end
      && macro_is_identifier_nondigit (*p))
    {
      char *tok_start = p;

      while (p < end
             && (macro_is_identifier_nondigit (*p)
                 || macro_is_digit (*p)))
        p++;

      set_token (tok, tok_start, p);
      tok->is_identifier = 1;
      return 1;
    }
  else
    return 0;
}
void step_3_join_clusters(struct Parameters *pParam)
{
  char logStr[MAXLOGMSGLEN];
  char digit[MAXDIGITBIT];
  
  log_msg("Joining clusters...", LOG_NOTICE, pParam);
  
  set_token(pParam);
  
  join_cluster(pParam);
  
  str_format_int_grouped(digit, pParam->joinedClusterInputNum);
  sprintf(logStr, "%s clusters contain frequent words under word weight"
      "threshold.", digit);
  log_msg(logStr, LOG_INFO, pParam);
  
  str_format_int_grouped(digit, pParam->joinedClusterOutputNum);
  sprintf(logStr, "Those clusters were joined into %s clusters.", digit);
  log_msg(logStr, LOG_INFO, pParam);
}
Example #13
0
/**
* Do all tests according to the testing sequence
* @param test Test details
* @testpath Base path of tests
* @return TRUE when all tests were verified ok
*/
gboolean tests_conduct_tests(testcase* test, gchar* testpath) {

	if(!test || !testpath) return FALSE;

	gboolean rval = TRUE;

	// Go through the test sequence
	for(gint testidx = 0; testidx < g_slist_length(test_sequence); testidx++) {

		// Get the item in test sequence
		gchar* searchparam = g_slist_nth_data(test_sequence,testidx);
		
#ifdef G_MESSAGES_DEBUG
		g_print("Press enter to continue with test \"%s\" file id=\"%s\"",test->name,searchparam);
		gchar c = '0';
		while(c != '\n') c = getc(stdin);
#endif
		// Get the data with the searchparameter from hash table
		testfile* tfile = (testfile*)g_hash_table_find(test->files,
			(GHRFunc)find_from_hash_table, 
			searchparam);
		
		// Read any other file except Empty.json	
		if(g_strcmp0(tfile->file,"Empty.json") != 0) {
			// Create path for the file to be read
			gchar* filepath = g_strjoin("/",testpath,tfile->file,NULL);
		
			JsonParser *parser = json_parser_new();
		
			// Read json detailed by this data (stucture)
			if(!load_json_from_file(parser, filepath)) return FALSE;
			
			// Do this only for files that are sent
			if(tests_file_sending_method(tfile->method))
				tests_check_fields_from_loaded_testfile(parser, tfile, testpath);
		
			// Establish a generator to get the character representation
			JsonGenerator *generator = json_generator_new();
			json_generator_set_root(generator, json_parser_get_root(parser));
	
			// Create new jsonreply and set it to contain json as string data
			tfile->send = jsonreply_initialize();
			tfile->send->data = json_generator_to_data(generator,&(tfile->send->length));
		
			g_object_unref(generator);
			g_object_unref(parser);
		}
		
		// If path contains {id} it needs to be replaced with case id
		if(g_strrstr(tfile->path,"{id}")) {
		
			// Get case file
			testfile* temp = (testfile*)g_hash_table_find(test->files,
				(GHRFunc)find_from_hash_table, 
				"0");
			
			// Get case id
			gchar* caseid = get_value_of_member(temp->recv,"guid",NULL);
			
			if(caseid) {
				
				// Tokenize path
				gchar** split_path = g_strsplit(tfile->path,"/",5);
				
				// Go through the tokens and replace {id} with case id
				for(gint splitidx = 0; split_path[splitidx] ; splitidx++) {
					if(g_strcmp0(split_path[splitidx],"{id}") == 0) {
						g_free(split_path[splitidx]);
						split_path[splitidx] = caseid;
					}
				}
				
				// Replace the path with new
				g_free(tfile->path);
				tfile->path = g_strjoinv("/",split_path);
				g_strfreev(split_path);
			}
		}
		
		// Create url
		gchar* url = g_strjoin("/",test->URL,tfile->path,NULL);
		
#ifdef G_MESSAGES_DEBUG
		g_print("Conducting test id \"%s\"\n",test->name);
#endif
				
		// First is login, it is always first in the list
		if(testidx == 0) {
			tfile->recv = http_post(url,tfile->send,tfile->method);
			if(tfile->recv) {
				gchar* token = get_value_of_member(tfile->recv,"token",NULL);
				set_token(token);
				g_free(token);
			}
			else rval = FALSE;
		}
		
		// Case creation is second
		else if(testidx == 1) {
			tfile->recv = http_post(url,tfile->send,tfile->method);
			if(tfile->recv && verify_server_response(tfile->send,tfile->recv)) {
				g_print ("Case added correctly\n\n\n");
			}
			else rval = FALSE;
		}
		
		// From third start the tests, here the required fields are checked and replaced
		else {
			gint index = 0;
			// Go through all fields having {parent} as value
			
			// Do this only for files that are sent
			if(tests_file_sending_method(tfile->method)) {
				for(index = 0; index < g_slist_length(tfile->required); index++) {
					//replace_required_member(test->files,tfile,index);
				
					// Use new function just to add member-new value pairs to hash table
					add_required_member_value_to_list(test->files,tfile,index);
				}
			
				// Go through the list of items requiring more info
				for(gint index = 0; index < g_slist_length(tfile->moreinfo); index++) {
					//replace_getinfo_member(tfile,index,test->URL);
				
					// Use new function just to add member-new value pairs to hash table
					add_getinfo_member_value_to_list(tfile,index,test->URL);
				}
				
				// Replace all values in the jsonreply_t data using the member-value
				// pairs in the replace hash table
				set_values_of_all_members(tfile->send, tfile->replace);		
			}

			tfile->recv = http_post(url,tfile->send,tfile->method);
			
			// If there is something to verify
			if(tfile->send) {
				g_print("Verifying test id \"%s\" (file: %s):\n",tfile->id,tfile->file);
				if(verify_server_response(tfile->send,tfile->recv)) {
					g_print ("Test id \"%s\" was added correctly\n",tfile->id);
				}
				else {
					g_print("Test id \"%s\" was not added correctly\n", tfile->id);
					rval = FALSE;
				}
				g_print("\n\n");
			}
		}

		g_free(url);	
	}
	return rval;
}
Example #14
0
File: macroexp.c Project: 5kg/gdb
static struct macro_buffer *
gather_arguments (const char *name, struct macro_buffer *src,
		  int nargs, int *argc_p)
{
  struct macro_buffer tok;
  int args_len, args_size;
  struct macro_buffer *args = NULL;
  struct cleanup *back_to = make_cleanup (free_current_contents, &args);

  /* Does SRC start with an opening paren token?  Read from a copy of
     SRC, so SRC itself is unaffected if we don't find an opening
     paren.  */
  {
    struct macro_buffer temp;

    init_shared_buffer (&temp, src->text, src->len);

    if (! get_token (&tok, &temp)
        || tok.len != 1
        || tok.text[0] != '(')
      {
        discard_cleanups (back_to);
        return 0;
      }
  }

  /* Consume SRC's opening paren.  */
  get_token (&tok, src);

  args_len = 0;
  args_size = 6;
  args = (struct macro_buffer *) xmalloc (sizeof (*args) * args_size);

  for (;;)
    {
      struct macro_buffer *arg;
      int depth;

      /* Make sure we have room for the next argument.  */
      if (args_len >= args_size)
        {
          args_size *= 2;
          args = xrealloc (args, sizeof (*args) * args_size);
        }

      /* Initialize the next argument.  */
      arg = &args[args_len++];
      set_token (arg, src->text, src->text);

      /* Gather the argument's tokens.  */
      depth = 0;
      for (;;)
        {
          if (! get_token (&tok, src))
            error (_("Malformed argument list for macro `%s'."), name);
      
          /* Is tok an opening paren?  */
          if (tok.len == 1 && tok.text[0] == '(')
            depth++;

          /* Is tok is a closing paren?  */
          else if (tok.len == 1 && tok.text[0] == ')')
            {
              /* If it's a closing paren at the top level, then that's
                 the end of the argument list.  */
              if (depth == 0)
                {
		  /* In the varargs case, the last argument may be
		     missing.  Add an empty argument in this case.  */
		  if (nargs != -1 && args_len == nargs - 1)
		    {
		      /* Make sure we have room for the argument.  */
		      if (args_len >= args_size)
			{
			  args_size++;
			  args = xrealloc (args, sizeof (*args) * args_size);
			}
		      arg = &args[args_len++];
		      set_token (arg, src->text, src->text);
		    }

                  discard_cleanups (back_to);
                  *argc_p = args_len;
                  return args;
                }

              depth--;
            }

          /* If tok is a comma at top level, then that's the end of
             the current argument.  However, if we are handling a
             variadic macro and we are computing the last argument, we
             want to include the comma and remaining tokens.  */
          else if (tok.len == 1 && tok.text[0] == ',' && depth == 0
		   && (nargs == -1 || args_len < nargs))
            break;

          /* Extend the current argument to enclose this token.  If
             this is the current argument's first token, leave out any
             leading whitespace, just for aesthetics.  */
          if (arg->len == 0)
            {
              arg->text = tok.text;
              arg->len = tok.len;
              arg->last_token = 0;
            }
          else
            {
              arg->len = (tok.text + tok.len) - arg->text;
              arg->last_token = tok.text - arg->text;
            }
        }
    }
}
Example #15
0
File: macroexp.c Project: 5kg/gdb
/* Peel the next preprocessor token off of SRC, and put it in TOK.
   Mutate TOK to refer to the first token in SRC, and mutate SRC to
   refer to the text after that token.  SRC must be a shared buffer;
   the resulting TOK will be shared, pointing into the same string SRC
   does.  Initialize TOK's last_token field.  Return non-zero if we
   succeed, or 0 if we didn't find any more tokens in SRC.  */
static int
get_token (struct macro_buffer *tok,
           struct macro_buffer *src)
{
  char *p = src->text;
  char *end = p + src->len;

  gdb_assert (src->shared);

  /* From the ISO C standard, ISO/IEC 9899:1999 (E), section 6.4:

     preprocessing-token: 
         header-name
         identifier
         pp-number
         character-constant
         string-literal
         punctuator
         each non-white-space character that cannot be one of the above

     We don't have to deal with header-name tokens, since those can
     only occur after a #include, which we will never see.  */

  while (p < end)
    if (macro_is_whitespace (*p))
      p++;
    else if (get_comment (tok, p, end))
      p += tok->len;
    else if (get_pp_number (tok, p, end)
             || get_character_constant (tok, p, end)
             || get_string_literal (tok, p, end)
             /* Note: the grammar in the standard seems to be
                ambiguous: L'x' can be either a wide character
                constant, or an identifier followed by a normal
                character constant.  By trying `get_identifier' after
                we try get_character_constant and get_string_literal,
                we give the wide character syntax precedence.  Now,
                since GDB doesn't handle wide character constants
                anyway, is this the right thing to do?  */
             || get_identifier (tok, p, end)
             || get_punctuator (tok, p, end))
      {
        /* How many characters did we consume, including whitespace?  */
        int consumed = p - src->text + tok->len;

        src->text += consumed;
        src->len -= consumed;
        return 1;
      }
    else 
      {
        /* We have found a "non-whitespace character that cannot be
           one of the above."  Make a token out of it.  */
        int consumed;

        set_token (tok, p, p + 1);
        consumed = p - src->text + tok->len;
        src->text += consumed;
        src->len -= consumed;
        return 1;
      }

  return 0;
}