Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroperfox committed Aug 3, 2024
1 parent 0824042 commit f8ecc6e
Showing 1 changed file with 66 additions and 15 deletions.
81 changes: 66 additions & 15 deletions src/as3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export abstract class Ns
{
abstract toString(): string;

ispublicns(): boolean
{
return this instanceof Systemns && this.kind == Systemns.PUBLIC;
}

ispublicorinternalns(): boolean
{
return this instanceof Systemns && (this.kind == Systemns.PUBLIC || this.kind == Systemns.INTERNAL);
Expand Down Expand Up @@ -176,10 +181,35 @@ export class Names
return result;
}

hasnsname(ns: Ns, name: string): any
hasnsname(ns: Ns, name: string): boolean
{
return this.m_dict.get(ns)?.has(name) ?? false;
}

hasnssetname(nsset: Ns[], name: string): boolean
{
for (const ns of nsset)
{
const result = ns.ispublicns() ? this.haspublicname(name) : this.hasnsname(ns, name);
if (result)
{
return result;
}
}
return false;
}

haspublicname(name: string): boolean
{
for (const [ns, names] of this.m_dict)
{
if (ns instanceof Systemns && ns.kind == Systemns.PUBLIC)
{
return names.has(name) ?? false;
}
}
return false;
}

getnsname(ns: Ns, name: string): any
{
Expand All @@ -190,7 +220,7 @@ export class Names
{
for (const ns of nsset)
{
const result = this.getnsname(ns, name);
const result = ns.ispublicns() ? this.getpublicname(name) : this.getnsname(ns, name);
if (result !== null)
{
return result;
Expand All @@ -215,7 +245,7 @@ export class Names
return null;
}

set(ns: Ns, name: string, trait: any): void
setnsname(ns: Ns, name: string, trait: any): void
{
let names = this.m_dict.get(ns) ?? null;
if (names === null)
Expand Down Expand Up @@ -322,11 +352,11 @@ export function defineclass(name: Name, options: ClassOptions, items: [Name, any
assert(item instanceof PossiblyStatic);
if (item.static)
{
class1.staticnames.set(itemname.ns, itemname.name, item);
class1.staticnames.setnsname(itemname.ns, itemname.name, item);
}
else
{
class1.prototypenames.set(itemname.ns, itemname.name, item);
class1.prototypenames.setnsname(itemname.ns, itemname.name, item);
if (item instanceof Variable)
{
thesevars.push(item);
Expand Down Expand Up @@ -498,26 +528,47 @@ const globalvarvals = new Map<Variable, any>();

const boundmethods = new Map<Array<any>, Map<Method, Function>>();

export function hasname(base1: any, name: Name): boolean
export function hasname(base1: any, nsset: Ns[], name: string): boolean
{
if (!(base1 instanceof Array))
{
return false;
}
const base = base1 as Array<any>;
const class1 = base[0] as Class;
if (class1.dynamic && name.ns.ispublicorinternalns())
{
return (base[1] as Map<string, any>).has(name.name);
}
let classb = class1;
while (classb !== null)
for (const ns of nsset)
{
if (classb.prototypenames.hasnsname(name.ns, name.name))
if (class1.dynamic && ns.ispublicorinternalns())
{
return true;
const result = (base[1] as Map<string, any>).has(name);
if (result)
{
return true;
}
}
let classb = class1;
if (ns.ispublicns())
{
while (classb !== null)
{
if (classb.prototypenames.haspublicname(name))
{
return true;
}
classb = classb.baseclass;
}
}
else
{
while (classb !== null)
{
if (classb.prototypenames.hasnsname(ns, name))
{
return true;
}
classb = classb.baseclass;
}
}
classb = classb.baseclass;
}
return false;
}
Expand Down

0 comments on commit f8ecc6e

Please sign in to comment.