Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06bed39

Browse files
authored
Function lock segregation with Target state (#196)
1 parent9007664 commit06bed39

File tree

18 files changed

+112
-80
lines changed

18 files changed

+112
-80
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2021-2022 Niket Naidu. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef TARGET_COMMON_FUNCTION_LOCK_H_
18+
#defineTARGET_COMMON_FUNCTION_LOCK_H_
19+
20+
#include<string_view>
21+
22+
#include"fmt/format.h"
23+
24+
#include"env/assert_fatal.h"
25+
26+
namespacebuildcc {
27+
28+
classFunctionLock {
29+
public:
30+
voidLock() { lock_ =true; }
31+
voidUnlock() { lock_ =false; }
32+
boolIsLocked()const {return lock_; }
33+
voidExpectsUnlock(std::string_view tag)const {
34+
env::assert_fatal(!lock_,
35+
fmt::format("Cannot use {} when lock == true", tag));
36+
}
37+
voidExpectsLock(std::string_view tag)const {
38+
env::assert_fatal(lock_,
39+
fmt::format("Cannot use {} when lock == false", tag));
40+
}
41+
42+
private:
43+
bool lock_{false};
44+
};
45+
46+
}// namespace buildcc
47+
48+
#endif

‎buildcc/lib/target/include/target/common/target_state.h‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,24 @@
2121

2222
namespacebuildcc {
2323

24-
// TODO, Seperate TargetState into lock_ and other internal boolean variables
25-
// NOTE, This is because apart from lock_ every other parameter is updated
26-
// during `Target::Build`
27-
// TargetInfo does not have a `Build` method, it is only meant to hold
28-
// information
2924
structTargetState {
30-
voidSetSourceState(FileExt file_extension);
31-
voidSetPch();
32-
voidSetLock();
33-
34-
voidExpectsUnlock()const;
35-
voidExpectsLock()const;
36-
// TODO, IsLocked
25+
voidBuildCompleted();
26+
voidSourceDetected(FileExt file_extension);
27+
voidPchDetected();
3728

29+
boolIsBuilt()const {return build_; }
3830
boolContainsPch()const {return contains_pch_; }
39-
40-
// TODO, Make these private getters
41-
bool contains_asm{false};
42-
bool contains_c{false};
43-
bool contains_cpp{false};
44-
bool build{false};
45-
bool lock{false};
31+
boolContainsAsm()const {return contains_asm_; }
32+
boolContainsC()const {return contains_c_; }
33+
boolContainsCpp()const {return contains_cpp_; }
4634

4735
private:
36+
bool build_{false};
37+
4838
bool contains_pch_{false};
39+
bool contains_asm_{false};
40+
bool contains_c_{false};
41+
bool contains_cpp_{false};
4942
};
5043

5144
}// namespace buildcc

‎buildcc/lib/target/include/target/target.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ class Target : public internal::BuilderInterface,
7575
env.GetTargetBuildDir() / toolchain.GetName() / name),
7676
config),
7777
name_(name), type_(type),
78-
// toolchain_(toolchain),
79-
// loader_(name, env_.GetTargetBuildDir()),
8078
serialization_(env_.GetTargetBuildDir() / fmt::format("{}.bin", name)),
8179
compile_pch_(*this), compile_object_(*this), link_target_(*this) {
8280
Initialize();
@@ -141,7 +139,6 @@ class Target : public internal::BuilderInterface,
141139
private:
142140
std::string name_;
143141
TargetType type_;
144-
// const Toolchain &toolchain_;
145142
internal::TargetSerialization serialization_;
146143

147144
// Friend classes

‎buildcc/lib/target/include/target/target_info.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include"toolchain/toolchain.h"
2323

24+
#include"target/common/function_lock.h"
2425
#include"target/common/target_config.h"
2526
#include"target/common/target_env.h"
2627
#include"target/common/target_state.h"
@@ -88,6 +89,7 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
8889

8990
UserTargetSchema user_;
9091

92+
FunctionLock lock_;
9193
TargetState state_;
9294
};
9395

‎buildcc/lib/target/src/api/deps_api.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ template <typename T>
2424
void DepsApi<T>::AddCompileDependencyAbsolute(const fs::path &absolute_path) {
2525
T &t =static_cast<T &>(*this);
2626

27-
t.state_.ExpectsUnlock();
27+
t.lock_.ExpectsUnlock(__FUNCTION__);
2828
t.user_.compile_dependencies.insert(absolute_path);
2929
}
3030
template<typename T>
3131
void DepsApi<T>::AddLinkDependencyAbsolute(const fs::path &absolute_path) {
3232
T &t =static_cast<T &>(*this);
3333

34-
t.state_.ExpectsUnlock();
34+
t.lock_.ExpectsUnlock(__FUNCTION__);
3535
t.user_.link_dependencies.insert(absolute_path);
3636
}
3737

‎buildcc/lib/target/src/api/flag_api.cpp‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,55 @@ template <typename T>
2424
void FlagApi<T>::AddPreprocessorFlag(const std::string &flag) {
2525
T &t =static_cast<T &>(*this);
2626

27-
t.state_.ExpectsUnlock();
27+
t.lock_.ExpectsUnlock(__FUNCTION__);
2828
t.user_.preprocessor_flags.insert(flag);
2929
}
3030
template<typename T>
3131
void FlagApi<T>::AddCommonCompileFlag(const std::string &flag) {
3232
T &t =static_cast<T &>(*this);
3333

34-
t.state_.ExpectsUnlock();
34+
t.lock_.ExpectsUnlock(__FUNCTION__);
3535
t.user_.common_compile_flags.insert(flag);
3636
}
3737
template<typename T>
3838
void FlagApi<T>::AddPchCompileFlag(const std::string &flag) {
3939
T &t =static_cast<T &>(*this);
4040

41-
t.state_.ExpectsUnlock();
41+
t.lock_.ExpectsUnlock(__FUNCTION__);
4242
t.user_.pch_compile_flags.insert(flag);
4343
}
4444
template<typename T>
4545
void FlagApi<T>::AddPchObjectFlag(const std::string &flag) {
4646
T &t =static_cast<T &>(*this);
4747

48-
t.state_.ExpectsUnlock();
48+
t.lock_.ExpectsUnlock(__FUNCTION__);
4949
t.user_.pch_object_flags.insert(flag);
5050
}
5151
template<typename T>
5252
void FlagApi<T>::AddAsmCompileFlag(const std::string &flag) {
5353
T &t =static_cast<T &>(*this);
5454

55-
t.state_.ExpectsUnlock();
55+
t.lock_.ExpectsUnlock(__FUNCTION__);
5656
t.user_.asm_compile_flags.insert(flag);
5757
}
5858
template<typename T>
5959
void FlagApi<T>::AddCCompileFlag(const std::string &flag) {
6060
T &t =static_cast<T &>(*this);
6161

62-
t.state_.ExpectsUnlock();
62+
t.lock_.ExpectsUnlock(__FUNCTION__);
6363
t.user_.c_compile_flags.insert(flag);
6464
}
6565
template<typename T>
6666
void FlagApi<T>::AddCppCompileFlag(const std::string &flag) {
6767
T &t =static_cast<T &>(*this);
6868

69-
t.state_.ExpectsUnlock();
69+
t.lock_.ExpectsUnlock(__FUNCTION__);
7070
t.user_.cpp_compile_flags.insert(flag);
7171
}
7272
template<typename T>void FlagApi<T>::AddLinkFlag(const std::string &flag) {
7373
T &t =static_cast<T &>(*this);
7474

75-
t.state_.ExpectsUnlock();
75+
t.lock_.ExpectsUnlock(__FUNCTION__);
7676
t.user_.link_flags.insert(flag);
7777
}
7878

‎buildcc/lib/target/src/api/include_api.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <typename T>
2424
void IncludeApi<T>::AddHeaderAbsolute(const fs::path &absolute_filepath) {
2525
T &t =static_cast<T &>(*this);
2626

27-
t.state_.ExpectsUnlock();
27+
t.lock_.ExpectsUnlock(__FUNCTION__);
2828
t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath);
2929
t.user_.headers.insert(absolute_filepath);
3030
}
@@ -74,7 +74,7 @@ void IncludeApi<T>::AddIncludeDirAbsolute(const fs::path &absolute_include_dir,
7474
bool glob_headers) {
7575
T &t =static_cast<T &>(*this);
7676

77-
t.state_.ExpectsUnlock();
77+
t.lock_.ExpectsUnlock(__FUNCTION__);
7878
t.user_.include_dirs.insert(absolute_include_dir);
7979

8080
if (glob_headers) {

‎buildcc/lib/target/src/api/lib_api.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template <typename T>
2525
void LibApi<T>::AddLibDirAbsolute(const fs::path &absolute_lib_dir) {
2626
T &t =static_cast<T &>(*this);
2727

28-
t.state_.ExpectsUnlock();
28+
t.lock_.ExpectsUnlock(__FUNCTION__);
2929
t.user_.lib_dirs.insert(absolute_lib_dir);
3030
}
3131

@@ -40,14 +40,14 @@ void LibApi<T>::AddLibDir(const fs::path &relative_lib_dir) {
4040
template<typename T>void LibApi<T>::AddLibDep(const BaseTarget &lib_dep) {
4141
T &t =static_cast<T &>(*this);
4242

43-
t.state_.ExpectsUnlock();
43+
t.lock_.ExpectsUnlock(__FUNCTION__);
4444
t.user_.libs.push_back(lib_dep.GetTargetPath());
4545
}
4646

4747
template<typename T>void LibApi<T>::AddLibDep(const std::string &lib_dep) {
4848
T &t =static_cast<T &>(*this);
4949

50-
t.state_.ExpectsUnlock();
50+
t.lock_.ExpectsUnlock(__FUNCTION__);
5151
t.user_.external_libs.push_back(lib_dep);
5252
}
5353

‎buildcc/lib/target/src/api/pch_api.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <typename T>
2424
void PchApi<T>::AddPchAbsolute(const fs::path &absolute_filepath) {
2525
T &t =static_cast<T &>(*this);
2626

27-
t.state_.ExpectsUnlock();
27+
t.lock_.ExpectsUnlock(__FUNCTION__);
2828
t.toolchain_.GetConfig().ExpectsValidHeader(absolute_filepath);
2929

3030
const fs::path absolute_pch =fs::path(absolute_filepath).make_preferred();

‎buildcc/lib/target/src/api/source_api.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ template <typename T>
2424
void SourceApi<T>::AddSourceAbsolute(const fs::path &absolute_source) {
2525
T &t =static_cast<T &>(*this);
2626

27-
t.state_.ExpectsUnlock();
27+
t.lock_.ExpectsUnlock(__FUNCTION__);
2828
t.toolchain_.GetConfig().ExpectsValidSource(absolute_source);
2929
t.user_.sources.emplace(fs::path(absolute_source).make_preferred());
3030
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp