Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Reviewers: jerzy.kleszcz, michal.zielinski

Reviewed By: michal.zielinski

Subscribers: jerzy.kleszcz, michal.zielinski

Differential Revision: https://phabricator.polidea.com/D2903
  • Loading branch information
siejkowski committed Apr 3, 2018
1 parent 60367da commit f365543
Show file tree
Hide file tree
Showing 57 changed files with 3,506 additions and 2,934 deletions.
32 changes: 32 additions & 0 deletions swift/include/swift/Obfuscation/Collector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef Collector_h
#define Collector_h

#include "swift/Obfuscation/DataStructures.h"
#include "swift/Obfuscation/Includer.h"
#include "swift/Obfuscation/SymbolGenerator.h"

#include <vector>

namespace swift {
namespace obfuscation {

class Collector {

private:
std::unique_ptr<class Includer> Includer;
std::unique_ptr<class SymbolGenerator> SymbolGenerator;

public:

Collector(std::unique_ptr<class Includer>,
std::unique_ptr<class SymbolGenerator>);

std::vector<DeclWithSymbolWithRange> collectFrom(DeclWithRange &);
std::vector<DeclWithSymbolWithRange> collectFrom(DeclWithRange &&);

};

} //namespace obfuscation
} //namespace swift

#endif /* Collector_h */
20 changes: 11 additions & 9 deletions swift/include/swift/Obfuscation/CompilerInfrastructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ namespace obfuscation {
///
/// Typical usage:
/// \code
/// auto FilesJsonOrError = parseJson<FilesJson>(PathToJson);
/// if (auto Error = setupCompilerInstance(CI, FilesJson, MainExecutablePath)) {
/// auto CompilerInstanceOrError =
/// createCompilerInstance(FilesJson, MainExecutablePath);
/// if (auto Error = CompilerInstanceOrError) {
/// return std::move(Error);
/// }
/// auto CompilerInstance = CompilerInstanceOrError.get();
/// \endcode
///
/// \param CompilerInstance - compiler instance to setup.
/// \param FilesJson - FilesJson structure containing data required
/// for compilation.
///
/// \param MainExecutablePath - string containing path to main executable used
/// during compiler isntance
///
/// \returns llvm::Error::success when setup finished correctly or
/// error object describing cause of fail.
llvm::Error
setupCompilerInstance(CompilerInstance &CompilerInstance,
const FilesJson &FilesJson,
std::string MainExecutablePath,
llvm::raw_ostream &LogStream);

llvm::Expected<std::unique_ptr<CompilerInstance>>
createCompilerInstance(const FilesJson &FilesJson,
std::string MainExecutablePath,
llvm::raw_ostream &LogStream);

} //namespace obfuscation
} //namespace swift

Expand Down
39 changes: 0 additions & 39 deletions swift/include/swift/Obfuscation/ConfigurationExcluder.h

This file was deleted.

81 changes: 69 additions & 12 deletions swift/include/swift/Obfuscation/DataStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ struct SymbolRenaming {
const std::string &ObfuscatedName,
const std::string &Module,
SymbolType Type);


bool operator< (const SymbolRenaming &Right) const;
bool operator== (const SymbolRenaming &Right) const;
};

Expand Down Expand Up @@ -169,7 +170,7 @@ struct ObfuscationConfiguration {
ObfuscationConfiguration& operator=(const ObfuscationConfiguration &) = delete;
ObfuscationConfiguration& operator=(ObfuscationConfiguration &&) = default;
};

/// SymbolWithRange - struct for linking the symbol identified in the Swift
/// source code with the range in which it was encountered.
struct SymbolWithRange {
Expand All @@ -187,35 +188,91 @@ struct SymbolWithRange {
bool operator== (const SymbolWithRange &Right) const;
};

struct IndexedSymbolWithRange {
enum DeclarationProcessingContext {
NoContext,

FunctionCallAttribute
};

struct DeclWithRange {
Decl *Declaration;
CharSourceRange Range;
DeclarationProcessingContext Context;

/// @brief Trivial memberwise-like constructor
DeclWithRange(Decl* Declaration, const CharSourceRange &Range);

bool operator< (const DeclWithRange &Right) const;

bool operator== (const DeclWithRange &Right) const;
};

struct DeclWithSymbolWithRange {
Decl *Declaration;
Symbol Symbol;
CharSourceRange Range;

/// @brief Trivial memberwise-like constructor
DeclWithSymbolWithRange(Decl* Declaration,
const SymbolWithRange &SymbolAndRange);

DeclWithSymbolWithRange(const DeclWithRange &DeclAndRange,
const struct Symbol &Symbol);

DeclWithSymbolWithRange(Decl *Declaration,
const struct Symbol &Symbol,
CharSourceRange Range);

bool operator< (const DeclWithSymbolWithRange &Right) const;

bool operator== (const DeclWithSymbolWithRange &Right) const;
};

template<typename T>
using VectorOfExpected = std::vector<llvm::Expected<T>>;

using DeclsWithRangesOrErrors = VectorOfExpected<DeclWithRange>;

using DeclsWithSymbolsWithRangesOrErrors =
VectorOfExpected<DeclWithSymbolWithRange>;

template<typename T>
VectorOfExpected<T> wrapInVector(T &);
template<typename T>
VectorOfExpected<T> wrapInVector(T &&);
template<typename T>
VectorOfExpected<T> wrapInVector(llvm::Error &&);

struct IndexedDeclWithSymbolWithRange {
int Index;
SymbolWithRange SymbolWithRange;
Decl *Declaration;
Symbol Symbol;
CharSourceRange Range;

/// @brief Trivial memberwise-like constructor
IndexedSymbolWithRange(const int Index,
const struct SymbolWithRange &SymbolWithRange);
IndexedDeclWithSymbolWithRange(const int Index,
const DeclWithSymbolWithRange &DeclAndSymbolAndRange);

/// @brief Comparison required for containing IndexedSymbolWithRange in sets.
/// It's taking only symbol into consideration, not range nor index.
struct SymbolCompare {
bool operator() (const IndexedSymbolWithRange& Left,
const IndexedSymbolWithRange& Right) const;
bool operator() (const IndexedDeclWithSymbolWithRange& Left,
const IndexedDeclWithSymbolWithRange& Right) const;
};

/// @brief Comparison required for containing IndexedSymbolWithRange in sets.
/// It's taking only symbol with range into consideration, not index.
struct SymbolWithRangeCompare {
bool operator() (const IndexedSymbolWithRange& Left,
const IndexedSymbolWithRange& Right) const;
bool operator() (const IndexedDeclWithSymbolWithRange& Left,
const IndexedDeclWithSymbolWithRange& Right) const;
};
};

using SingleSymbolOrError = llvm::Expected<Symbol>;

using SymbolsOrError = llvm::Expected<std::vector<SymbolWithRange>>;

using GlobalCollectedSymbols = std::set<IndexedSymbolWithRange,
IndexedSymbolWithRange::SymbolWithRangeCompare>;
using GlobalCollectedSymbols = std::set<IndexedDeclWithSymbolWithRange, IndexedDeclWithSymbolWithRange::SymbolWithRangeCompare>;
} //namespace obfuscation
} //namespace swift

Expand Down
42 changes: 0 additions & 42 deletions swift/include/swift/Obfuscation/DeclarationParser.h

This file was deleted.

83 changes: 0 additions & 83 deletions swift/include/swift/Obfuscation/DeclarationParsingUtils.h

This file was deleted.

Loading

0 comments on commit f365543

Please sign in to comment.