瀏覽代碼

Add global parsimony variables to track struct/union/enum declarations.

master
Ian Piumarta 2 年之前
父節點
當前提交
516867784d
共有 1 個檔案被更改,包括 47 行新增3 行删除
  1. +47
    -3
      src/ccmeta.leg

+ 47
- 3
src/ccmeta.leg 查看文件

@ -3,7 +3,7 @@
# Copyright (c) 2016-2021 Ian Piumarta and other contributors (see AUTHORS)
# All rights reserved (see LICENSE)
#
# Last edited: 2023-03-22 17:03:00 by piumarta on zora-10.local
# Last edited: 2023-03-22 17:14:46 by piumarta on zora-10.local
%{
/* compile: leg -o ccmeta.c ccmeta.leg
@ -101,8 +101,16 @@ jb_record *jbs= NULL;
assert(jbs == &jbrec); \
jbs= jbrec.next
// this is the global scope
// this is the global scope and other global variable for parsimony lang
oop globals= 0;
oop program = 0;
oop prog_last = 0;
oop prog_unions = 0;
oop prog_enums = 0;
oop prog_structs = 0;
oop union_last = 0;
oop enum_last = 0;
oop struct_last = 0;
#define DO_SYMBOLS() \
DO_PROTOS() _DO(__proto__) _DO(__name__) _DO(__default__) _DO(__arguments__) \
@ -123,7 +131,7 @@ oop globals= 0;
_DO(rlparen) _DO(rrparen) _DO(attributeL) _DO(attributeTok) _DO(typeOfTok) _DO(asmTok) _DO(element) \
_DO(volatileTok) _DO(gotoTok) _DO(declarationL) _DO(compoundS) _DO(switchTok) _DO(continueTok) \
_DO(breakTok) _DO(returnTok) _DO(caseTok) _DO(defaultTok) _DO(attribute1) _DO(attribute2) \
_DO(structTok) _DO(enumList) _DO(enumTok)
_DO(structTok) _DO(enumList) _DO(enumTok) _DO(last)
#define _DO(NAME) oop NAME##_symbol;
@ -835,6 +843,16 @@ oop new_C_structSpec(oop structTok, oop attributeSpecifier1, oop id, oop leftCur
map_set(object, declarationL_symbol,declarationList);
map_set(object, rightCurly_symbol, rightCurly);
map_set(object, attribute2_symbol, attributeSpecifier2);
// remember this declaration in program.unions or program.structs and their .last members
if (strcmp(get(map_get(structTok, text_symbol), String, value), "union") == 0 ) {
if (id != null) map_set(prog_unions, map_get(id, identifier_symbol), object);
map_set(prog_unions, last_symbol, object);
} else {
if (id != null) map_set(prog_structs, map_get(id, identifier_symbol), object);
map_set(prog_structs, last_symbol, object);
}
// remember this declaration in program.last
map_set(program, last_symbol, object);
return object;
}
@ -853,6 +871,11 @@ oop new_C_enumSpec(oop enumTok, oop id, oop leftCurly, oop enumeratorList, oop r
map_set(object, leftCurly_symbol, leftCurly);
map_set(object, enumList_symbol, enumeratorList);
map_set(object, rightCurly_symbol, rightCurly);
if (id != null) {
map_set(prog_enums, map_get(id, identifier_symbol), object);
}
map_set(prog_enums, last_symbol, object);
map_set(program, last_symbol, object);
return object;
}
@ -4668,6 +4691,27 @@ void init(void)
DO_PROTOS()
#undef _DO
// Initialisation of parsimony global variable
program = makeMap();
prog_enums = makeMap();
prog_structs = makeMap();
prog_unions = makeMap();
prog_last = makeMap();
enum_last = makeMap();
struct_last = makeMap();
union_last = makeMap();
map_set(globals , intern("program"), program );
map_set(program , intern("structs"), prog_structs);
map_set(prog_structs, intern("last" ), struct_last );
map_set(program , intern("unions" ), prog_unions );
map_set(prog_unions , intern("last" ), union_last );
map_set(program , intern("enums" ), prog_enums );
map_set(prog_enums , intern("last" ), enum_last );
fixScope(globals);
/* File scope */

Loading…
取消
儲存