# # # The Nimrod Compiler # (c) Copyright 2010 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # # this module does the semantic checking of statements proc semExprNoType(c: PContext, n: PNode): PNode = result = semExpr(c, n) if result.typ != nil and result.typ.kind != tyStmt: liMessage(n.info, errDiscardValue) proc semWhen(c: PContext, n: PNode): PNode = result = nil for i in countup(0, sonsLen(n) - 1): var it = n.sons[i] if it == nil: illFormedAst(n) case it.kind of nkElifBranch: checkSonsLen(it, 2) var e = semConstExpr(c, it.sons[0]) checkBool(e) if (e.kind != nkIntLit): InternalError(n.info, "semWhen") if (e.intVal != 0) and (result == nil): result = semStmt(c, it.sons[1]) # do not open a new scope! of nkElse: checkSonsLen(it, 1) if result == nil: result = semStmt(c, it.sons[0]) # do not open a new scope! else: illFormedAst(n) if result == nil: result = newNodeI(nkNilLit, n.info) # The ``when`` statement implements the mechanism for platform dependant # code. Thus we try to ensure here consistent ID allocation after the # ``when`` statement. IDsynchronizationPoint(200) proc semIf(c: PContext, n: PNode): PNode = result = n for i in countup(0, sonsLen(n) - 1): var it = n.sons[i] if it == nil: illFormedAst(n) case it.kind of nkElifBranch: checkSonsLen(it, 2) openScope(c.tab) it.sons[0] = semExprWithType(c, it.sons[0]) checkBool(it.sons[0]) it.sons[1] = semStmt(c, it.sons[1]) closeScope(c.tab) of nkElse: if sonsLen(it) == 1: it.sons[0] = semStmtScope(c, it.sons[0]) else: illFormedAst(it) else: illFormedAst(n) proc semDiscard(c: PContext, n: PNode): PNode = result = n checkSonsLen(n, 1) n.sons[0] = semExprWithType(c, n.sons[0]) if n.sons[0].typ == nil: liMessage(n.info, errInvalidDiscard) proc semBreakOrContinue(c: PContext, n: PNode): PNode = result = n checkSonsLen(n, 1) if n.sons[0] != nil: var s: PSym case n.sons[0].kind of nkIdent: s = lookUp(c, n.sons[0]) of nkSym: s = n.sons[0].sym else: illFormedAst(n) if (s.kind == skLabel) and (s.owner.id == c.p.owner.id): var x = newSymNode(s) x.info = n.info incl(s.flags, sfUsed) n.sons[0] = x else: liMessage(n.info, errInvalidControlFlowX, s.name.s) elif (c.p.nestedLoopCounter <= 0) and (c.p.nestedBlockCounter <= 0): liMessage(n.info, errInvalidControlFlowX, renderTree(n, {renderNoComments})) proc semBlock(c: PContext, n: PNode): PNode = result = n Inc(c.p.nestedBlockCounter) checkSonsLen(n, 2) openScope(c.tab) # BUGFIX: label is in the scope of block! if n.sons[0] != nil: var labl = newSymS(skLabel, n.sons[0], c) addDecl(c, labl) n.sons[0] = newSymNode(labl) # BUGFIX n.sons[1] = semStmt(c, n.sons[1]) closeScope(c.tab) Dec(c.p.nestedBlockCounter) proc semAsm(con: PContext, n: PNode): PNode = result = n checkSonsLen(n, 2) var marker = pragmaAsm(con, n.sons[0]) if marker == '\0': marker = '`' # default marker case n.sons[1].kind of nkStrLit, nkRStrLit, nkTripleStrLit: result = copyNode(n) var str = n.sons[1].strVal if str == "": liMessage(n.info, errEmptyAsm) # now parse the string literal and substitute symbols: var a = 0 while true: var b = strutils.find(str, marker, a) var sub = if b < 0: copy(str, a) else: copy(str, a, b - 1) if sub != "": addSon(result, newStrNode(nkStrLit, sub)) if b < 0: break var c = strutils.find(str, marker, b + 1) if c < 0: sub = copy(str, b + 1) else: sub = copy(str, b + 1, c - 1) if sub != "": var e = SymtabGet(con.tab, getIdent(sub)) if e != nil: if e.kind == skStub: loadStub(e) addSon(result, newSymNode(e)) else: addSon(result, newStrNode(nkStrLit, sub)) if c < 0: break a = c + 1 else: illFormedAst(n) proc semWhile(c: PContext, n: PNode): PNode = result = n checkSonsLen(n, 2) openScope(c.tab) n.sons[0] = semExprWithType(c, n.sons[0]) CheckBool(n.sons[0]) inc(c.p.nestedLoopCounter) n.sons[1] = semStmt(c, n.sons[1]) dec(c.p.nestedLoopCounter) closeScope(c.tab) proc semCase(c: PContext, n: PNode): PNode = # check selector: result = n checkMinSonsLen(n, 2) openScope(c.tab) n.sons[0] = semExprWithType(c, n.sons[0]) var chckCovered = false var covered: biggestint = 0 case skipTypes(n.sons[0].Typ, abstractVarRange).Kind of tyInt..tyInt64, tyChar, tyEnum: chckCovered = true of tyFloat..tyFloat128, tyString: nil else: liMessage(n.info, errSelectorMustBeOfCertainTypes) for i in countup(1, sonsLen(n) - 1): var
# gridwm - grid window manager
# (C)opyright MMVI Anselm R. Garbe
include config.mk
WMSRC = bar.c client.c draw.c event.c util.c wm.c
WMOBJ = ${WMSRC:.c=.o}
MENSRC = menu.c draw.c util.c
MENOBJ = ${MENSRC:.c=.o}
MAN1 = gridwm.1 gridmenu.1
BIN = gridwm gridmenu
all: config gridwm gridmenu
@echo finished
config:
@echo gridwm build options:
@echo "LIBS = ${LIBS}"
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
.c.o:
@echo CC $<
@${CC} -c ${CFLAGS} $<
${WMOBJ}: wm.h draw.h config.h util.h
gridmenu: ${MENOBJ}
@echo LD $@
@${CC} -o $@ ${MENOBJ} ${LDFLAGS}
gridwm: ${WMOBJ}
@echo LD $@
@${CC} -o $@ ${WMOBJ} ${LDFLAGS}
clean:
rm -f gridwm gridmenu *.o core
dist: clean
mkdir -p gridwm-${VERSION}
cp -R Makefile README LICENSE config.mk *.h *.c ${MAN} gridwm-${VERSION}
tar -cf gridwm-${VERSION}.tar gridwm-${VERSION}
gzip gridwm-${VERSION}.tar
rm -rf gridwm-${VERSION}
install: all
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
@echo installed executable files to ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1
@echo installed manual pages to ${DESTDIR}${MANPREFIX}/man1
uninstall:
for i in ${BIN}; do \
rm -f ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
done
for i in ${MAN1}; do \
rm -f ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
done