-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontext.c
91 lines (83 loc) · 2.34 KB
/
context.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (C) 1999-2012 Core Technologies.
//
// This file is part of tpasm.
//
// tpasm is free software; you can redistribute it and/or modify
// it under the terms of the tpasm LICENSE AGREEMENT.
//
// tpasm is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// tpasm LICENSE AGREEMENT for more details.
//
// You should have received a copy of the tpasm LICENSE AGREEMENT
// along with tpasm; see the file "LICENSE.TXT".
// Handle assembly context management subroutines
#include "include.h"
bool PushContextRecord(unsigned int contextBytes)
// Create a new context record, push it onto the stack
// If there was a problem, return false
{
CONTEXT_RECORD
*record;
if((record=(CONTEXT_RECORD *)NewPtr(sizeof(CONTEXT_RECORD)+contextBytes)))
{
record->contextType=0;
record->active=false;
record->whereFrom.file=currentVirtualFile;
record->whereFrom.fileLineNumber=currentVirtualFileLine;
record->next=contextStack;
record->flush=NULL;
contextStack=record;
return(true);
}
return(false);
}
void PopContextRecord(void)
// Pull a context record off the stack and destroy it
// NOTE: if the stack is empty, do nothing
{
CONTEXT_RECORD
*tempRecord;
if(contextStack)
{
tempRecord=contextStack->next;
DisposePtr(contextStack);
contextStack=tempRecord;
}
}
void FlushContextRecords()
// Get rid of any lingering if context records, report errors
{
while(contextStack)
{
if(contextStack->next&&contextStack->next->active) // only report if this context is in an active context
{
switch(contextStack->contextType)
{
case CT_ROOT:
break;
case CT_IF:
AssemblyComplaint(&contextStack->whereFrom,true,"Unterminated conditional\n");
break;
case CT_SWITCH:
AssemblyComplaint(&contextStack->whereFrom,true,"Unterminated switch\n");
break;
case CT_MACRO:
AssemblyComplaint(&contextStack->whereFrom,true,"Unterminated macro\n");
break;
case CT_REPEAT:
AssemblyComplaint(&contextStack->whereFrom,true,"Unterminated repeat\n");
break;
default:
AssemblyComplaint(&contextStack->whereFrom,true,"Unterminated context\n");
break;
}
}
if(contextStack->flush)
{
contextStack->flush(contextStack); // flush this
}
PopContextRecord();
}
}