Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
32ad30e8
Commit
32ad30e8
authored
Jul 10, 2002
by
Ken Martin
Browse files
better error handling with if statements
parent
9f6ebe4e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Source/cmElseCommand.cxx
View file @
32ad30e8
...
...
@@ -28,22 +28,18 @@ bool cmElseCommand::InitialPass(std::vector<std::string> const& args)
return
false
;
}
// first remove any function blockers for the IF
m_Makefile
->
RemoveFunctionBlocker
(
"ELSE"
,
args
);
// if is true create a blocker for the else
if
(
isTrue
)
{
cmIfFunctionBlocker
*
f
=
new
cmIfFunctionBlocker
();
for
(
std
::
vector
<
std
::
string
>::
const_iterator
j
=
args
.
begin
();
j
!=
args
.
end
();
++
j
)
{
f
->
m_Args
.
push_back
(
*
j
);
}
m_Makefile
->
AddFunctionBlocker
(
f
);
}
else
{
// remove any function blockers for this define
m_Makefile
->
RemoveFunctionBlocker
(
"ENDIF"
,
args
);
cmIfFunctionBlocker
*
f
=
new
cmIfFunctionBlocker
();
f
->
m_IsBlocking
=
isTrue
;
for
(
std
::
vector
<
std
::
string
>::
const_iterator
j
=
args
.
begin
();
j
!=
args
.
end
();
++
j
)
{
f
->
m_Args
.
push_back
(
*
j
);
}
m_Makefile
->
AddFunctionBlocker
(
f
);
return
true
;
}
...
...
Source/cmIfCommand.cxx
View file @
32ad30e8
...
...
@@ -44,14 +44,21 @@ IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
cmSystemTools
::
Error
(
err
.
c_str
());
}
}
return
true
;
return
m_IsBlocking
;
}
bool
cmIfFunctionBlocker
::
ShouldRemove
(
const
char
*
name
,
const
std
::
vector
<
std
::
string
>
&
args
,
cmMakefile
&
mf
)
{
return
!
this
->
IsFunctionBlocked
(
name
,
args
,
mf
);
if
(
!
strcmp
(
name
,
"ELSE"
)
||
!
strcmp
(
name
,
"ENDIF"
))
{
if
(
args
==
m_Args
)
{
return
true
;
}
}
return
false
;
}
void
cmIfFunctionBlocker
::
...
...
@@ -80,17 +87,15 @@ bool cmIfCommand::InitialPass(std::vector<std::string> const& args)
return
false
;
}
// if is isn't true create a blocker
if
(
!
isTrue
)
{
cmIfFunctionBlocker
*
f
=
new
cmIfFunctionBlocker
();
for
(
std
::
vector
<
std
::
string
>::
const_iterator
j
=
args
.
begin
();
j
!=
args
.
end
();
++
j
)
{
f
->
m_Args
.
push_back
(
*
j
);
}
m_Makefile
->
AddFunctionBlocker
(
f
);
cmIfFunctionBlocker
*
f
=
new
cmIfFunctionBlocker
();
// if is isn't true block the commands
f
->
m_IsBlocking
=
!
isTrue
;
for
(
std
::
vector
<
std
::
string
>::
const_iterator
j
=
args
.
begin
();
j
!=
args
.
end
();
++
j
)
{
f
->
m_Args
.
push_back
(
*
j
);
}
m_Makefile
->
AddFunctionBlocker
(
f
);
return
true
;
}
...
...
Source/cmIfCommand.h
View file @
32ad30e8
...
...
@@ -40,6 +40,7 @@ public:
virtual
void
ScopeEnded
(
cmMakefile
&
mf
);
std
::
vector
<
std
::
string
>
m_Args
;
bool
m_IsBlocking
;
};
/** \class cmIfCommand
...
...
Source/cmMakefile.cxx
View file @
32ad30e8
...
...
@@ -126,12 +126,12 @@ cmMakefile::~cmMakefile()
delete
d
->
second
;
}
}
std
::
s
e
t
<
cmFunctionBlocker
*>::
const_iterator
pos
;
std
::
li
st
<
cmFunctionBlocker
*>::
const_iterator
pos
;
for
(
pos
=
m_FunctionBlockers
.
begin
();
pos
!=
m_FunctionBlockers
.
end
();
pos
=
m_FunctionBlockers
.
begin
())
{
cmFunctionBlocker
*
b
=
*
pos
;
m_FunctionBlockers
.
eras
e
(
*
pos
);
m_FunctionBlockers
.
remov
e
(
*
pos
);
delete
b
;
}
delete
m_MakefileGenerator
;
...
...
@@ -263,15 +263,26 @@ void cmMakefile::ExecuteCommand(std::string &name,
// is "filename" and not "external".
bool
cmMakefile
::
ReadListFile
(
const
char
*
filename
,
const
char
*
external
)
{
// keep track of the current file being read
// used to watch for blockers going out of scope
// e.g. mismatched IF statement
std
::
set
<
cmFunctionBlocker
*>
originalBlockers
;
// keep track of the current file being read
if
(
filename
)
{
if
(
m_cmCurrentListFile
!=
filename
)
{
m_cmCurrentListFile
=
filename
;
}
// loop over current function blockers and record them
std
::
list
<
cmFunctionBlocker
*>::
const_iterator
pos
;
for
(
pos
=
m_FunctionBlockers
.
begin
();
pos
!=
m_FunctionBlockers
.
end
();
++
pos
)
{
originalBlockers
.
insert
(
*
pos
);
}
}
// if this is not a remote makefile
// (if it were, this would be called from the "filename" call,
// rather than the "external" call)
...
...
@@ -343,11 +354,16 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
if
(
filename
)
{
// loop over all function blockers to see if any block this command
std
::
s
e
t
<
cmFunctionBlocker
*>::
const_iterator
pos
;
std
::
li
st
<
cmFunctionBlocker
*>::
const_iterator
pos
;
for
(
pos
=
m_FunctionBlockers
.
begin
();
pos
!=
m_FunctionBlockers
.
end
();
++
pos
)
{
(
*
pos
)
->
ScopeEnded
(
*
this
);
// if this blocker was not in the original then send a
// scope ended message
if
(
originalBlockers
.
find
(
*
pos
)
==
originalBlockers
.
end
())
{
(
*
pos
)
->
ScopeEnded
(
*
this
);
}
}
}
...
...
@@ -1216,7 +1232,7 @@ bool cmMakefile::IsFunctionBlocked(const char *name,
}
// loop over all function blockers to see if any block this command
std
::
s
e
t
<
cmFunctionBlocker
*>::
const_iterator
pos
;
std
::
li
st
<
cmFunctionBlocker
*>::
const_iterator
pos
;
std
::
vector
<
std
::
string
>
expandedArguments
=
args
;
for
(
std
::
vector
<
std
::
string
>::
iterator
i
=
expandedArguments
.
begin
();
i
!=
expandedArguments
.
end
();
++
i
)
...
...
@@ -1249,14 +1265,14 @@ void cmMakefile::RemoveFunctionBlocker(const char *name,
const
std
::
vector
<
std
::
string
>
&
args
)
{
// loop over all function blockers to see if any block this command
std
::
s
e
t
<
cmFunctionBlocker
*>::
const
_iterator
pos
;
for
(
pos
=
m_FunctionBlockers
.
begin
();
pos
!=
m_FunctionBlockers
.
end
();
++
pos
)
std
::
li
st
<
cmFunctionBlocker
*>::
reverse
_iterator
pos
;
for
(
pos
=
m_FunctionBlockers
.
r
begin
();
pos
!=
m_FunctionBlockers
.
r
end
();
++
pos
)
{
if
((
*
pos
)
->
ShouldRemove
(
name
,
args
,
*
this
))
{
cmFunctionBlocker
*
b
=
*
pos
;
m_FunctionBlockers
.
eras
e
(
*
pos
);
m_FunctionBlockers
.
remov
e
(
*
pos
);
delete
b
;
return
;
}
...
...
Source/cmMakefile.h
View file @
32ad30e8
...
...
@@ -79,9 +79,9 @@ public:
* Add a function blocker to this makefile
*/
void
AddFunctionBlocker
(
cmFunctionBlocker
*
fb
)
{
m_FunctionBlockers
.
insert
(
fb
);}
{
m_FunctionBlockers
.
push_back
(
fb
);}
void
RemoveFunctionBlocker
(
cmFunctionBlocker
*
fb
)
{
m_FunctionBlockers
.
eras
e
(
fb
);}
{
m_FunctionBlockers
.
remov
e
(
fb
);}
void
RemoveFunctionBlocker
(
const
char
*
name
,
const
std
::
vector
<
std
::
string
>
&
args
);
/**
...
...
@@ -571,7 +571,7 @@ private:
void
PrintStringVector
(
const
char
*
s
,
const
std
::
vector
<
std
::
string
>&
v
)
const
;
void
AddDefaultCommands
();
void
AddDefaultDefinitions
();
std
::
s
e
t
<
cmFunctionBlocker
*>
m_FunctionBlockers
;
std
::
li
st
<
cmFunctionBlocker
*>
m_FunctionBlockers
;
typedef
std
::
map
<
cmStdString
,
cmData
*>
DataMap
;
DataMap
m_DataMap
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment