/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 2002-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* *18***********************************************************************/19#pragma prototyped20/*21* dss misc support22*/2324#include "dsshdr.h"2526/*27* compile an expression28* input is from string s or stream sp if s==029*/3031Dssexpr_t*32dsscomp(Dss_t* dss, const char* s, Sfio_t* sp)33{34Cxexpr_t* expr;35char* file;36void* pop;3738if (!sp && s && *s == '<')39{40while (isspace(*++s));41if (!(sp = sfopen(NiL, s, "r")))42{43if (dss->disc->errorf)44(*dss->disc->errorf)(dss, dss->disc, 2, "%s: cannot read expression file", s);45return 0;46}47file = (char*)s;48s = 0;49}50else51file = 0;52if (!(pop = cxpush(dss->cx, file, sp, s, -1, CX_INCLUDE)))53return 0;54expr = cxcomp(dss->cx);55cxpop(dss->cx, pop);56return expr;57}5859/*60* called once before the first dsseval(expr)61*/6263int64dssbeg(Dss_t* dss, Dssexpr_t* expr)65{66return cxbeg(dss->cx, expr, dss->meth->name);67}6869/*70* evaluate expr71*/7273int74dsseval(Dss_t* dss, Dssexpr_t* expr, Dssrecord_t* record)75{76Cxoperand_t cv;7778if (!expr->begun && dssbeg(dss, expr))79return -1;80return cxeval(dss->cx, expr, record, &cv);81}8283/*84* called once after the last dsseval(expr)85* there can be multiple dssbeg ... dsseval ... dssend sequences86*/8788int89dssend(Dss_t* dss, Dssexpr_t* expr)90{91return cxend(dss->cx, expr);92}9394/*95* list expr96*/9798int99dsslist(Dss_t* dss, Dssexpr_t* expr, Sfio_t* sp)100{101return cxlist(dss->cx, expr, sp);102}103104/*105* free expr106*/107108int109dssfree(Dss_t* dss, Dssexpr_t* expr)110{111return cxfree(dss->cx, expr);112}113114/*115* return variable value in value116* type!=0 casts to type, variable->type by default117* details!=0 is optional type format details118*/119120int121dssget(Dssrecord_t* record, Dssvariable_t* variable, Dsstype_t* type, const char* details, Dssvalue_t* value)122{123Cxoperand_t ret;124125if (cxcast(record->file->dss->cx, &ret, variable, type, record, details))126return -1;127*value = ret.value;128return 0;129}130131/*132* return type pointer given name133*/134135Dsstype_t*136dsstype(Dss_t* dss, const char* name)137{138return cxtype(dss->cx, name, dss->disc);139}140141/*142* return variable pointer given name143*/144145Dssvariable_t*146dssvariable(Dss_t* dss, const char* name)147{148return cxvariable(dss->cx, name, NiL, dss->disc);149}150151152