예제 #1
0
static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,
                                                    StringRef JSONDatabase,
                                                    std::string &ErrorMessage) {
  llvm::OwningPtr<CompilationDatabase> Database(
      JSONCompilationDatabase::loadFromBuffer(JSONDatabase, ErrorMessage));
  if (!Database)
    return CompileCommand();
  std::vector<CompileCommand> Commands = Database->getCompileCommands(FileName);
  EXPECT_LE(Commands.size(), 1u);
  if (Commands.empty())
    return CompileCommand();
  return Commands[0];
}
FixedCompilationDatabase::
FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) {
  std::vector<std::string> ToolCommandLine(1, "clang-tool");
  ToolCommandLine.insert(ToolCommandLine.end(),
                         CommandLine.begin(), CommandLine.end());
  CompileCommands.push_back(CompileCommand(Directory, ToolCommandLine));
}
예제 #3
0
std::vector<CompileCommand>
JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const {
  llvm::SmallString<128> NativeFilePath;
  llvm::sys::path::native(FilePath, NativeFilePath);
  std::vector<StringRef> PossibleMatches;
  std::string Error;
  llvm::raw_string_ostream ES(Error);
  StringRef Match = MatchTrie.findEquivalent(NativeFilePath.str(), ES);
  if (Match.empty()) {
    if (Error.empty())
      Error = "No match found.";
    llvm::outs() << Error << "\n";
    return std::vector<CompileCommand>();
  }
  llvm::StringMap< std::vector<CompileCommandRef> >::const_iterator
    CommandsRefI = IndexByFile.find(Match);
  if (CommandsRefI == IndexByFile.end())
    return std::vector<CompileCommand>();
  const std::vector<CompileCommandRef> &CommandsRef = CommandsRefI->getValue();
  std::vector<CompileCommand> Commands;
  for (int I = 0, E = CommandsRef.size(); I != E; ++I) {
    llvm::SmallString<8> DirectoryStorage;
    llvm::SmallString<1024> CommandStorage;
    Commands.push_back(CompileCommand(
      // FIXME: Escape correctly:
      CommandsRef[I].first->getValue(DirectoryStorage),
      unescapeCommandLine(CommandsRef[I].second->getValue(CommandStorage))));
  }
  return Commands;
}
예제 #4
0
void FeedFilter::Rule::Compile(char* szRule)
{
	debug("Compiling rule: %s", szRule);

	m_bIsValid = true;

	char* szFilter3 = Util::Trim(szRule);

	char* szTerm = CompileCommand(szFilter3);
	if (!szTerm)
	{
		m_bIsValid = false;
		return;
	}
	if (m_eCommand == frComment)
	{
		return;
	}

	szTerm = Util::Trim(szTerm);

	for (char* p = szTerm; *p && m_bIsValid; p++)
	{
		char ch = *p;
		if (ch == ' ')
		{
			*p = '\0';
			m_bIsValid = CompileTerm(szTerm);
			szTerm = p + 1;
			while (*szTerm == ' ') szTerm++;
			p = szTerm;
		}
	}

	m_bIsValid = m_bIsValid && CompileTerm(szTerm);

	if (m_bIsValid && m_bPatCategory)
	{
		m_szPatCategory = m_szCategory;
		m_szCategory = NULL;
	}
	if (m_bIsValid && m_bPatDupeKey)
	{
		m_szPatDupeKey = m_szDupeKey;
		m_szDupeKey = NULL;
	}
	if (m_bIsValid && m_bPatAddDupeKey)
	{
		m_szPatAddDupeKey = m_szAddDupeKey;
		m_szAddDupeKey = NULL;
	}
}
std::vector<CompileCommand>
JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const {
  llvm::SmallString<128> NativeFilePath;
  llvm::sys::path::native(FilePath, NativeFilePath);
  llvm::StringMap< std::vector<CompileCommandRef> >::const_iterator
    CommandsRefI = IndexByFile.find(NativeFilePath);
  if (CommandsRefI == IndexByFile.end())
    return std::vector<CompileCommand>();
  const std::vector<CompileCommandRef> &CommandsRef = CommandsRefI->getValue();
  std::vector<CompileCommand> Commands;
  for (int I = 0, E = CommandsRef.size(); I != E; ++I) {
    llvm::SmallString<8> DirectoryStorage;
    llvm::SmallString<1024> CommandStorage;
    Commands.push_back(CompileCommand(
      // FIXME: Escape correctly:
      CommandsRef[I].first->getValue(DirectoryStorage),
      unescapeCommandLine(CommandsRef[I].second->getValue(CommandStorage))));
  }
  return Commands;
}
예제 #6
0
T_void CompileFile(T_byte8 *p_filename)
{
    FILE *fp ;
    T_byte8 buffer[300] ;
    T_word16 place ;
    T_byte8 firstWord[80] ;

    printf("Compiling %s:\n", p_filename) ;

    fp = fopen(p_filename, "r") ;
    if (fp == NULL)  {
        printf("Cannot open file %s\n", p_filename) ;
        exit(2) ;
    }

    fgets(buffer, 300, fp) ;
    while (!feof(fp))  {
        StripComment(buffer) ;
printf("[%s]\n", buffer) ;
        if (buffer[0])  {
            if (isspace(buffer[0]))  {
                  /* Command. */
                  CompileCommand(buffer) ;
            } else if (isdigit(buffer[0])) {
                  /* place. */
                  place = atoi(buffer) ;
printf("place: %d\n", place) ;
                  if (place >= MAX_PLACES)  {
                      printf("Error!  Place %d too big on line %d\n",
                          place,
                          G_line) ;
                      G_errors++ ;
                  } else {
                      if (G_places[place] == 0xFFFF)  {
                          G_places[place] = G_place ;
                      } else {
                          printf("Error!  Place %d already taken (line %d)\n",
                              place,
                              G_line) ;
                          G_errors++ ;
                      }
                  }
            } else {
                  /* event or directive. */
                  firstWord[0] = '\0' ;
                  sscanf(buffer, "%s", firstWord) ;
                  if (strcmp(firstWord, "defvar")==0)  {
                      CompileDefvar(buffer) ;
                  } else if (strcmp(firstWord, "defnum") == 0)  {
                      CompileDefnum(buffer) ;
                  } else if (strcmp(firstWord, "include") == 0)  {
                      CompileInclude(buffer) ;
                  } else {
                      if (firstWord[strlen(firstWord)-1] == ':')  {
                          CompileEvent(firstWord) ;
                      } else {
                          printf("Error!  Unknown directive, line %d\n", G_line) ;
                          G_errors++ ;
                      }
                  }
            }
        }
        fgets(buffer, 300, fp) ;
        G_line++ ;
    }

    fclose(fp) ;
}
예제 #7
0
// exec console command (this is the main command dispatcher) -----------------
//
void ExecConsoleCommand( char *command, int echo )
{
	//NOTE:
	// this function may be called recursively from within
	// functions called by CON_EXT::CallExternalCommand()
	// to allow execution of command scripts.

	ASSERT( command != NULL );
	ASSERT( ( echo == FALSE ) || ( echo == TRUE ) );

#ifdef FORCE_CONSOLE_LOGIN

	// check login state and login/logout commands
	if ( !CheckConsoleLogin( command ) ) {
		return;
	}

#endif // FORCE_CONSOLE_LOGIN

	// fetch console line as command
	strncpy( command_line, command, MAX_CONSOLE_LINE_LENGTH );
	command_line[ MAX_CONSOLE_LINE_LENGTH ] = 0;
	command = command_line;

	// eat leading whitespace
	for ( ; *command; command++ ) {
		if ( *command != ' ' ) {
			break;
		}
	}

	// early out for empty lines
	if ( *command == 0 ) {
		if ( echo ) {
			CON_AddLine( ok_prompt );
		}
		return;
	}

	if ( echo ) {
		// add command to history list only if echo is on
		AddLineToHistory( command );
	}

	// temp for extcom id
	int extcom;

	if ( strcmp( command, CMSTR( CM_NOMACROS ) ) == 0 ) {

		// disable calls to CallExternalCommand()
		disable_macros = TRUE;

	} else if ( strcmp( command, CMSTR( CM_ENABLEMACROS ) ) == 0 ) {

		// enable calls to CallExternalCommand()
		disable_macros = FALSE;

	} else if ( strncmp( command, CMSTR( CM_COMPILE ), CMLEN( CM_COMPILE ) ) == 0 ) {

		CompileCommand( command );

	} else if ( strncmp( command, ACMSTR( ACM_SIGNATURE ), ACMLEN( ACM_SIGNATURE ) ) == 0 ) {

		// check/exec commands with "ac." prefix
		ActionCommand( command );

	} else if ( !disable_macros && ( extcom = CheckExternalCommand( command ) ) ) {

		// execute command script
		CallExternalCommand( extcom - 1, echo ? EchoExternalCommands : FALSE );

	} else if ( !compile_script ) {

		// check/exec all other commands
		ExecNonCompilableCommand( command );

	} else {

		// error if compilation in progress and non-compilable command found
		CON_AddLine( cmd_not_compilable );
	}
}