mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
importing fix for redeclaring variables
This commit is contained in:
parent
76bf845ec8
commit
2efa5cd075
1 changed files with 22 additions and 0 deletions
22
src/Var.cc
22
src/Var.cc
|
@ -348,6 +348,28 @@ extern ExprPtr add_and_assign_local(IDPtr id, ExprPtr init, ValPtr val) {
|
|||
}
|
||||
|
||||
void add_type(ID* id, TypePtr t, std::unique_ptr<std::vector<AttrPtr>> attr) {
|
||||
if ( const auto& old_t = id->GetType() ) {
|
||||
// The identifier already has a type associated with it. This can
|
||||
// be okay if (1) it's already been marked as a Type identifier,
|
||||
// (2) the previous type is a stub.
|
||||
if ( ! id->IsType() ) {
|
||||
reporter->Error("Identifier %s has already been declared and is not a type", id->Name());
|
||||
return;
|
||||
}
|
||||
|
||||
if ( old_t->Tag() == t->Tag() &&
|
||||
((old_t->Tag() == TYPE_RECORD && old_t->AsRecordType()->NumFields() == 0) || t->Tag() == TYPE_ENUM) )
|
||||
// It has a consistent tag and is either redeclaring a stub
|
||||
// record (used in init-bare.zeek) or an enum (which can
|
||||
// appear due to specifiers in BiFs, for example).
|
||||
;
|
||||
|
||||
else {
|
||||
reporter->Error("Type %s has already been declared", id->Name());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::string new_type_name = id->Name();
|
||||
std::string old_type_name = t->GetName();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue