Incremental fixes for Packages/Import/Use etc.

This commit is contained in:
rogerl%netscape.com 2002-01-16 23:55:19 +00:00
Родитель 18d34111dd
Коммит 036d2c9f30
3 изменённых файлов: 65 добавлений и 35 удалений

Просмотреть файл

@ -368,6 +368,7 @@ ByteCodeData gByteCodeData[OpCodeCount] = {
{ -1, "Juxtapose", },
{ -1, "NamedArgument", },
{ -1, "Use", },
{ 0, "UseOnceOp", },
};
@ -1389,13 +1390,30 @@ bool ByteCodeGen::genCodeForStatement(StmtNode *p, ByteCodeGen *static_cg, uint3
}
break;
case StmtNode::Package:
case StmtNode::Import:
case StmtNode::Namespace:
{
// do anything at bytecodegen?
}
break;
case StmtNode::Package:
{
PackageStmtNode *ps = checked_cast<PackageStmtNode *>(p);
mScopeChain->addScope(ps->scope);
genCodeForStatement(ps->body, static_cg, finallyLabel);
mScopeChain->popScope();
}
break;
case StmtNode::Import:
{
ImportStmtNode *i = checked_cast<ImportStmtNode *>(p);
ExprList *namespaces = i->namespaces;
while (namespaces) {
genExpr(namespaces->expr);
addOp(UseOp);
namespaces = namespaces->next;
}
}
break;
default:
NOT_REACHED("Not Implemented Yet");
}
@ -2063,6 +2081,7 @@ BinaryOpEquals:
delete ref;
return Object_Type;
}
case ExprNode::qualify:
case ExprNode::identifier:
{
Reference *ref = genReference(p, Read);

Просмотреть файл

@ -157,7 +157,7 @@ typedef enum {
JuxtaposeOp, // <attribute> <attribute> --> <attribute>
NamedArgOp, // <object> <string> --> <named arg object>
UseOp, // <object> -->
UseOnceOp, // <object> -->
UseOnceOp, // <pool ref>
OpCodeCount

Просмотреть файл

@ -1246,33 +1246,44 @@ void ScopeChain::collectNames(StmtNode *p)
break;
case StmtNode::Import:
{
// if loaded already - just skip.
ImportStmtNode *i = checked_cast<ImportStmtNode *>(p);
String packagePath;
if (i->packageIdList) {
packagePath = getPackageName(i->packageIdList);
if (!m_cx->checkForPackage(packagePath)) {
m_cx->loadPackage(packagePath, packagePath + ".js");
String packageName;
if (i->packageIdList)
packageName = getPackageName(i->packageIdList);
else
packageName = *i->packageString;
JSValue packageValue = getCompileTimeValue(packagePath, NULL);
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
Package *package = checked_cast<Package *>(packageValue.object);
if (!m_cx->checkForPackage(packageName))
m_cx->loadPackage(packageName, packageName + ".js");
for (PropertyIterator it = package->mProperties.begin(), end = package->mProperties.end();
(it != end); it++) {
JSValue packageValue = getCompileTimeValue(packageName, NULL);
ASSERT(packageValue.isObject() && (packageValue.object->mType == Package_Type));
Package *package = checked_cast<Package *>(packageValue.object);
ASSERT(PROPERTY_KIND(it) == ValuePointer);
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(it));
if (i->varName)
defineVariable(m_cx, *i->varName, NULL, Package_Type, JSValue(package));
for (PropertyIterator it = package->mProperties.begin(), end = package->mProperties.end();
(it != end); it++)
{
ASSERT(PROPERTY_KIND(it) == ValuePointer);
bool makeAlias = true;
if (i->includeExclude) {
makeAlias = !i->exclude;
IdentifierList *idList = i->includeExclude;
while (idList) {
if (idList->name.compare(PROPERTY_NAME(it)) == 0) {
makeAlias = !makeAlias;
break;
}
idList = idList->next;
}
}
}
else {
packagePath = *i->packageString + ".js";
if (!m_cx->checkForPackage(*i->packageString)) {
m_cx->loadPackage(*i->packageString, packagePath);
}
if (makeAlias)
defineAlias(m_cx, PROPERTY_NAME(it), PROPERTY_NAMESPACELIST(it), PROPERTY_ATTR(it), PROPERTY_TYPE(it), PROPERTY_VALUEPOINTER(it));
}
}
break;
case StmtNode::Namespace:
@ -1289,7 +1300,7 @@ void ScopeChain::collectNames(StmtNode *p)
String packageName = getPackageName(ps->packageIdList);
Package *package = new Package(packageName);
ps->scope = package;
m_cx->getGlobalObject()->defineVariable(m_cx, packageName, (NamespaceList *)(NULL), Property::NoAttribute, Package_Type, JSValue(package));
defineVariable(m_cx, packageName, NULL, Package_Type, JSValue(package));
m_cx->mPackages.push_back(package);
addScope(ps->scope);