Example #1
0
void C4AulScript::UnLink() {
  // unlink children
  for (C4AulScript *s = Child0; s; s = s->Next) s->UnLink();

  // do not unlink temporary (e.g., DirectExec-script in ReloadDef)
  if (Temporary) return;

  // check if byte code needs to be freed
  if (Code) {
    delete[] Code;
    Code = NULL;
  }

  // delete included/appended functions
  C4AulFunc *pFunc = Func0;
  while (pFunc) {
    C4AulFunc *pNextFunc = pFunc->Next;

    // clear stuff that's set in AfterLink
    pFunc->UnLink();

    if (pFunc->SFunc())
      if (pFunc->Owner != pFunc->SFunc()->pOrgScript)
        if (!pFunc->LinkedTo ||
            pFunc->LinkedTo->SFunc())  // do not kill global links; those will
                                       // be deleted if corresponding sfunc in
                                       // script is deleted
          delete pFunc;

    pFunc = pNextFunc;
  }
  // includes will have to be re-resolved now
  IncludesResolved = false;

  if (State > ASS_PREPARSED) State = ASS_PREPARSED;
}
Example #2
0
void C4AulScript::AppendTo(C4AulScript &Scr, bool bHighPrio) {
  // definition appends
  if (Def && Scr.Def) Scr.Def->IncludeDefinition(Def);
  // append all funcs
  // (in reverse order if inserted at begin of list)
  C4AulScriptFunc *sf;
  for (C4AulFunc *f = bHighPrio ? Func0 : FuncL; f;
       f = bHighPrio ? f->Next : f->Prev)
    // script funcs only
    if (sf = f->SFunc())
      // no need to append global funcs
      if (sf->Access != AA_GLOBAL) {
        // append: create copy
        // (if high priority, insert at end, otherwise at the beginning)
        C4AulScriptFunc *sfc = new C4AulScriptFunc(&Scr, sf->Name, bHighPrio);
        sfc->CopyBody(*sf);
        // link the copy to a local function
        if (sf->LinkedTo) {
          sfc->LinkedTo = sf->LinkedTo;
          sf->LinkedTo = sfc;
        } else {
          sfc->LinkedTo = sf;
          sf->LinkedTo = sfc;
        }
      }
  // mark as linked
  // increase code size needed
  Scr.CodeSize += CodeSize + 1;
  // append all local vars (if any existing)
  assert(!Def || this == &Def->Script);
  assert(&Scr.Def->Script == &Scr);
  if (LocalNamed.iSize == 0) return;
  if (!Scr.Def) {
    Warn("could not append local variables to global script!", "");
    return;
  }
  // copy local var definitions
  for (int ivar = 0; ivar < LocalNamed.iSize; ivar++)
    Scr.LocalNamed.AddName(LocalNamed.pNames[ivar]);
}