MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / AddLabel

Method AddLabel

source/script.cpp:4172–4198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4170
4171
4172ResultType Script::AddLabel(LPTSTR aLabelName, bool aAllowDupe)
4173// Returns OK or FAIL.
4174{
4175 if (!*aLabelName)
4176 return FAIL; // For now, silent failure because callers should check this beforehand.
4177 Label *&first_label = g->CurrentFunc ? g->CurrentFunc->mFirstLabel : mFirstLabel;
4178 Label *&last_label = g->CurrentFunc ? g->CurrentFunc->mLastLabel : mLastLabel;
4179 if (!aAllowDupe && FindLabel(aLabelName))
4180 {
4181 // Don't attempt to dereference label->mJumpToLine because it might not
4182 // exist yet. Example:
4183 // label1:
4184 // label1: <-- This would be a dupe-error but it doesn't yet have an mJumpToLine.
4185 // return
4186 return ScriptError(_T("Duplicate label."), aLabelName);
4187 }
4188 LPTSTR new_name = SimpleHeap::Alloc(aLabelName);
4189 Label *the_new_label = new Label(new_name); // Pass it the dynamic memory area we created.
4190 the_new_label->mPrevLabel = last_label; // Whether NULL or not.
4191 if (first_label == NULL)
4192 first_label = the_new_label;
4193 else
4194 last_label->mNextLabel = the_new_label;
4195 // This must be done after the above:
4196 last_label = the_new_label;
4197 return OK;
4198}
4199
4200
4201

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected