提交 17535d85 编写于 作者: 朔-望's avatar 朔-望

fix code style to llvm, namespace donot indent

上级 5d7a4caa
......@@ -3,5 +3,4 @@ Language: Cpp
BasedOnStyle: LLVM
Standard: Cpp11
IndentWidth: 4
NamespaceIndentation: All
...
......@@ -20,15 +20,15 @@ repos:
- id: trailing-whitespace
files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$
- repo: local
hooks:
- id: clang-format-with-version-check
name: clang-format
description: Format files with ClangFormat.
entry: bash ./tools/pre-commit.hooks/.clang_format.hook -i
language: system
files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$
#- repo: local
# hooks:
# - id: clang-format-with-version-check
# name: clang-format
# description: Format files with ClangFormat.
# entry: bash ./tools/pre-commit.hooks/.clang_format.hook -i
# language: system
# files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$
#
#- repo: local
# hooks:
# - id: copyright_checker
......
......@@ -6,24 +6,45 @@ dist: trusty
os:
- linux
env:
- JOB=check_style
global:
# CMake
- CMAKE_URL=https://cmake.org/files/v3.11/cmake-3.11.1-Linux-x86_64.tar.gz
addons:
apt:
sources:
- llvm-toolchain-trusty-6.0
- ubuntu-toolchain-r-test
packages:
- git
- python
- python-pip
- python2.7-dev
- clang-format-3.8
- clang-6.0
- libc6-i386
- curl
compiler:
- clang
before_install:
- sudo pip install -U virtualenv pre-commit pip
# Download and install recent cmake
- |
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
CMAKE_URL=${CMAKE_URL}
mkdir -p ${DEPS_DIR}/cmake
travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C ${DEPS_DIR}/cmake
export PATH=${DEPS_DIR}/cmake/bin:${PATH}
fi
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi
- if [ "$CXX" = "clang++" ]; then export CXX="clang++-6.0" CC="clang-6.0"; fi
script:
- if [[ "$JOB" == "check_style" ]]; then sudo ln -s /usr/bin/clang-format-3.8 /usr/bin/clang-format; fi
- |
function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
echo "==============="
- |
timeout 600 .travis/${JOB}.sh # 10min timeout
RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true; else exit 1; fi;
......
#!/bin/bash
function abort(){
echo "Your change doesn't follow PaddlePaddle's code style" 1>&2
echo "Your change doesn't follow Paddle-Moible's code style" 1>&2
echo "Please use pre-commit to auto-format your code." 1>&2
exit 1
}
......@@ -11,7 +11,7 @@ cd `dirname $0`
cd ..
export PATH=/usr/bin:$PATH
pre-commit install
clang-format --version
#clang-format --version
if ! pre-commit run -a ; then
ls -lh
......
......@@ -19,32 +19,32 @@ SOFTWARE.
#include "block_desc.h"
namespace paddle_mobile {
namespace framework {
namespace framework {
std::vector<std::shared_ptr<VarDesc>> BlockDesc::Vars() const {
std::vector<std::shared_ptr<VarDesc>> res;
for (const auto &p : vars_) {
res.push_back(p.second);
}
return res;
}
std::vector<std::shared_ptr<VarDesc>> BlockDesc::Vars() const {
std::vector<std::shared_ptr<VarDesc>> res;
for (const auto &p : vars_) {
res.push_back(p.second);
}
return res;
}
std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const {
std::vector<std::shared_ptr<OpDesc>> res;
for (const auto &op : ops_) {
res.push_back(op);
}
return res;
}
std::vector<std::shared_ptr<OpDesc>> BlockDesc::Ops() const {
std::vector<std::shared_ptr<OpDesc>> res;
for (const auto &op : ops_) {
res.push_back(op);
}
return res;
}
BlockDesc::BlockDesc(const proto::BlockDesc &desc) : desc_(desc) {
for (const proto::VarDesc &var_desc : desc_.vars()) {
vars_[var_desc.name()].reset(new VarDesc(var_desc));
}
for (const proto::OpDesc &op_desc : desc_.ops()) {
ops_.emplace_back(new framework::OpDesc(op_desc));
}
}
BlockDesc::BlockDesc(const proto::BlockDesc &desc) : desc_(desc) {
for (const proto::VarDesc &var_desc : desc_.vars()) {
vars_[var_desc.name()].reset(new VarDesc(var_desc));
}
for (const proto::OpDesc &op_desc : desc_.ops()) {
ops_.emplace_back(new framework::OpDesc(op_desc));
}
}
} // namespace framework
} // namespace framework
} // namespace paddle_mobile
......@@ -19,107 +19,107 @@ limitations under the License. */
#include <typeindex>
namespace paddle_mobile {
namespace framework {
namespace framework {
inline proto::VarType::Type ToDataType(std::type_index type) {
/*if (typeid(platform::float16).hash_code() == type.hash_code()) {
return proto::VarType::FP16;
} else */
if (typeid(const float).hash_code() == type.hash_code()) {
// CPPLint complains Using C-style cast. Use
// static_cast<float>() instead
// One fix to this is to replace float with const float because
// typeid(T) == typeid(const T)
// http://en.cppreference.com/w/cpp/language/typeid
return proto::VarType::FP32;
} else if (typeid(const double).hash_code() == type.hash_code()) {
return proto::VarType::FP64;
} else if (typeid(const int).hash_code() == type.hash_code()) {
return proto::VarType::INT32;
} else if (typeid(const int64_t).hash_code() == type.hash_code()) {
return proto::VarType::INT64;
} else if (typeid(const bool).hash_code() == type.hash_code()) {
return proto::VarType::BOOL;
} else {
// PADDLE_THROW("Not supported");
// std::cout << "Not supported";
}
}
inline proto::VarType::Type ToDataType(std::type_index type) {
/*if (typeid(platform::float16).hash_code() == type.hash_code()) {
return proto::VarType::FP16;
} else */
if (typeid(const float).hash_code() == type.hash_code()) {
// CPPLint complains Using C-style cast. Use
// static_cast<float>() instead
// One fix to this is to replace float with const float because
// typeid(T) == typeid(const T)
// http://en.cppreference.com/w/cpp/language/typeid
return proto::VarType::FP32;
} else if (typeid(const double).hash_code() == type.hash_code()) {
return proto::VarType::FP64;
} else if (typeid(const int).hash_code() == type.hash_code()) {
return proto::VarType::INT32;
} else if (typeid(const int64_t).hash_code() == type.hash_code()) {
return proto::VarType::INT64;
} else if (typeid(const bool).hash_code() == type.hash_code()) {
return proto::VarType::BOOL;
} else {
// PADDLE_THROW("Not supported");
// std::cout << "Not supported";
}
}
inline std::type_index ToTypeIndex(proto::VarType::Type type) {
switch (type) {
// case proto::VarType::FP16:
// return typeid(platform::float16);
case proto::VarType::FP32:
return typeid(float);
case proto::VarType::FP64:
return typeid(double);
case proto::VarType::INT32:
return typeid(int);
case proto::VarType::INT64:
return typeid(int64_t);
case proto::VarType::BOOL:
return typeid(bool);
default:
// PADDLE_THROW("Not support type %d", type);
printf("Not support type %d", type);
}
}
inline std::type_index ToTypeIndex(proto::VarType::Type type) {
switch (type) {
// case proto::VarType::FP16:
// return typeid(platform::float16);
case proto::VarType::FP32:
return typeid(float);
case proto::VarType::FP64:
return typeid(double);
case proto::VarType::INT32:
return typeid(int);
case proto::VarType::INT64:
return typeid(int64_t);
case proto::VarType::BOOL:
return typeid(bool);
default:
// PADDLE_THROW("Not support type %d", type);
printf("Not support type %d", type);
}
}
template <typename Visitor>
inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
switch (type) {
// case proto::VarType::FP16:
// visitor.template operator()<platform::float16>();
// break;
case proto::VarType::FP32:
visitor.template operator()<float>();
break;
case proto::VarType::FP64:
visitor.template operator()<double>();
break;
case proto::VarType::INT32:
visitor.template operator()<int>();
break;
case proto::VarType::INT64:
visitor.template operator()<int64_t>();
break;
case proto::VarType::BOOL:
visitor.template operator()<bool>();
break;
default:
// PADDLE_THROW("Not supported");
printf("Not supported");
}
}
template <typename Visitor>
inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
switch (type) {
// case proto::VarType::FP16:
// visitor.template operator()<platform::float16>();
// break;
case proto::VarType::FP32:
visitor.template operator()<float>();
break;
case proto::VarType::FP64:
visitor.template operator()<double>();
break;
case proto::VarType::INT32:
visitor.template operator()<int>();
break;
case proto::VarType::INT64:
visitor.template operator()<int64_t>();
break;
case proto::VarType::BOOL:
visitor.template operator()<bool>();
break;
default:
// PADDLE_THROW("Not supported");
printf("Not supported");
}
}
inline std::string DataTypeToString(const proto::VarType::Type type) {
switch (type) {
case proto::VarType::FP16:
return "float16";
case proto::VarType::FP32:
return "float32";
case proto::VarType::FP64:
return "float64";
case proto::VarType::INT16:
return "int16";
case proto::VarType::INT32:
return "int32";
case proto::VarType::INT64:
return "int64";
case proto::VarType::BOOL:
return "bool";
default:
// PADDLE_THROW("Not support type %d", type);
printf("Not support type %d", type);
}
}
inline std::string DataTypeToString(const proto::VarType::Type type) {
switch (type) {
case proto::VarType::FP16:
return "float16";
case proto::VarType::FP32:
return "float32";
case proto::VarType::FP64:
return "float64";
case proto::VarType::INT16:
return "int16";
case proto::VarType::INT32:
return "int32";
case proto::VarType::INT64:
return "int64";
case proto::VarType::BOOL:
return "bool";
default:
// PADDLE_THROW("Not support type %d", type);
printf("Not support type %d", type);
}
}
inline std::ostream &operator<<(std::ostream &out,
const proto::VarType::Type &type) {
out << DataTypeToString(type);
return out;
}
inline std::ostream &operator<<(std::ostream &out,
const proto::VarType::Type &type) {
out << DataTypeToString(type);
return out;
}
} // namespace framework
} // namespace framework
} // namespace paddle_mobile
#!/bin/bash
set -e
readonly VERSION="version 3."
version=$(clang-format -version)
if ! [[ $version == *"$VERSION"* ]]; then
echo "clang-format version check failed."
echo "a version contains '$VERSION' is needed, but get '$version'"
echo "you can install the right version, and make an soft-link to '\$PATH' env"
exit -1
fi
clang-format $@
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册