added verification for explicit references (check if the given ID exists)

pull/7/head
Marc Zinnschlag 15 years ago
parent d4ac3b506e
commit c37b007be0

@ -12,5 +12,10 @@ namespace SACompiler
{
return ' ';
}
bool Context::isId (const std::string& name) const
{
return false;
}
}

@ -13,7 +13,10 @@ namespace SACompiler
///< Is the compiler allowed to declare local variables?
virtual char getGlobalType (const std::string& name) const;
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual bool isId (const std::string& name) const;
///< Does \a name match an ID, that can be referenced?
};
}

@ -31,5 +31,30 @@ namespace MWScript
return ' ';
}
bool CompilerContext::isId (const std::string& name) const
{
return
mEnvironment.mWorld->getStore().activators.find (name) ||
mEnvironment.mWorld->getStore().potions.find (name) ||
mEnvironment.mWorld->getStore().appas.find (name) ||
mEnvironment.mWorld->getStore().armors.find (name) ||
mEnvironment.mWorld->getStore().books.find (name) ||
mEnvironment.mWorld->getStore().clothes.find (name) ||
mEnvironment.mWorld->getStore().containers.find (name) ||
mEnvironment.mWorld->getStore().creatures.find (name) ||
mEnvironment.mWorld->getStore().doors.find (name) ||
mEnvironment.mWorld->getStore().ingreds.find (name) ||
mEnvironment.mWorld->getStore().creatureLists.find (name) ||
mEnvironment.mWorld->getStore().itemLists.find (name) ||
mEnvironment.mWorld->getStore().lights.find (name) ||
mEnvironment.mWorld->getStore().lockpicks.find (name) ||
mEnvironment.mWorld->getStore().miscItems.find (name) ||
mEnvironment.mWorld->getStore().npcs.find (name) ||
mEnvironment.mWorld->getStore().probes.find (name) ||
mEnvironment.mWorld->getStore().repairs.find (name) ||
mEnvironment.mWorld->getStore().statics.find (name) ||
mEnvironment.mWorld->getStore().weapons.find (name);
}
}

@ -35,6 +35,9 @@ namespace MWScript
/// 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual char getGlobalType (const std::string& name) const;
virtual bool isId (const std::string& name) const;
///< Does \a name match an ID, that can be referenced?
};
}

@ -31,7 +31,10 @@ namespace Compiler
}
virtual char getGlobalType (const std::string& name) const = 0;
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual bool isId (const std::string& name) const = 0;
///< Does \a name match an ID, that can be referenced?
};
}

@ -275,7 +275,7 @@ namespace Compiler
return true;
}
if (mOperands.empty() && mOperators.empty() && mExplicit.empty())
if (mExplicit.empty() && getContext().isId (name))
{
mExplicit = name;
return true;

@ -129,7 +129,7 @@ namespace Compiler
return false;
}
if (mState==BeginState)
if (mState==BeginState && getContext().isId (name))
{
mState = PotentialExplicitState;
mExplicit = toLower (name);

Loading…
Cancel
Save