• R/O
  • SSH
  • HTTPS

adp: Commit


Commit MetaInfo

Revision292 (tree)
Time2012-06-06 19:04:53
Authorohfuji

Log Message

さらに整理した

Change Summary

Incremental Difference

--- trunk/adp_unify.cpp (revision 291)
+++ trunk/adp_unify.cpp (revision 292)
@@ -157,12 +157,12 @@
157157 bool PInteger::unify(const PEVeriable &horn, ExecContextRoot *c) const { return vunify(horn, *this, c, horn.vl, c->gl); }
158158
159159 /*************************************** PList ******************************************/
160-inline bool PList_unify(const PList &goal, const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
160+static inline bool PList_unify(const PList &goal, const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
161161 {
162162 if ( typeid(*goal.lvalue) == typeid(PNil) && typeid(*goal.rvalue) == typeid(PNil) ) return true;
163163 return false;
164164 }
165-inline bool PList_unify(const PList &goal, const PList &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
165+static inline bool PList_unify(const PList &goal, const PList &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
166166 {
167167 if ( horn.lvalue->unify( *goal.lvalue, c, hlocal, glocal) && horn.rvalue->unify( *goal.rvalue, c, hlocal, glocal) ) return true;
168168 return false;
@@ -181,7 +181,7 @@
181181
182182
183183 /*************************************** PArray ******************************************/
184-inline bool PArray_unify(const PArray &goal, const PArray &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
184+static inline bool PArray_unify(const PArray &goal, const PArray &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
185185 {
186186 size_t gsiz = goal.value.size();
187187 size_t hsiz = horn.value.size();
@@ -243,7 +243,7 @@
243243 bool PArray::unify(const PEVeriable &horn, ExecContextRoot *c) const { return vunify_getval(horn, *this, c, horn.vl, c->gl); }
244244
245245 /*************************************** PPredicate ******************************************/
246-inline bool PPredicate_unify(const PPredicate &goal, const PPredicate &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
246+static inline bool PPredicate_unify(const PPredicate &goal, const PPredicate &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal)
247247 {
248248 // 呼び出し側(goal)がnamespaceを指定した場合、namespaceが一致している必要がある。
249249 if ( !goal.nspace.empty() && strcmp( horn.nspace.c_str(), goal.nspace.c_str()) != 0 ) { return false; }
@@ -318,121 +318,71 @@
318318 }
319319
320320 /*************************************** getval ******************************************/
321-const PObject *PList::getval( ExecContextRoot *c) const
321+static inline const PObject *PList_getval( const PList &goal, ExecContextRoot *c, VLocal *vlocal)
322322 {
323- if ( constant ) return this;
323+ if ( goal.constant ) return &goal;
324324 PList *lo = 0;
325- const PObject *l = lvalue->getval(c);
326- const PObject *r = rvalue->getval(c);
327- if ( l != lvalue || r != rvalue ) {
325+ const PObject *l = goal.lvalue->getval2(c, vlocal);
326+ const PObject *r = goal.rvalue->getval2(c, vlocal);
327+ if ( l != goal.lvalue || r != goal.rvalue ) {
328328 lo = pmm.newPList(c->pobjs, const_cast<PObject*>(l), const_cast<PObject*>(r));
329329 }
330- return lo ? lo : this;
330+ return lo ? lo : &goal;
331331 }
332+const PObject *PList::getval( ExecContextRoot *c) const { return PList_getval( *this, c, c->gl); }
333+const PObject *PList::getval2( ExecContextRoot *c, VLocal *vlocal) const { return PList_getval( *this, c, vlocal); }
332334
333-const PObject *PList::getval2( ExecContextRoot *c, VLocal *vlocal) const
334-{
335- if ( constant ) return this;
336- PList *lo = 0;
337- const PObject *l = lvalue->getval2(c, vlocal);
338- const PObject *r = rvalue->getval2(c, vlocal);
339- if ( l != lvalue || r != rvalue ) {
340- lo = pmm.newPList(c->pobjs, const_cast<PObject*>(l), const_cast<PObject*>(r));
341- }
342- return lo ? lo : this;
343-}
344335
345-const PObject *PArray::getval( ExecContextRoot *c) const
336+static inline const PObject *PArray_getval( const PArray &goal, ExecContextRoot *c, VLocal *vlocal)
346337 {
347- if ( constant ) return this;
338+ if ( goal.constant ) return &goal;
348339 PArray *po = 0;
349340
350- for ( PObjectArray::const_iterator i = value.begin(); i < value.end(); i++ ) {
351- const PObject *p = (*i)->getval( c);
352- if ( p != *i && po == 0 ) {
353- po = pmm.newPArray(c->pobjs, *this);
354- po->constant = true;
355- }
356- if ( po ) {
357- po->value[i - value.begin()] = p;
358- po->constant = po->constant && p->isc();
359- }
360- }
361- return po ? po : this;
362-}
363-
364-
365-const PObject *PArray::getval2( ExecContextRoot *c, VLocal *vlocal) const
366-{
367- if ( constant ) return this;
368- PArray *po = 0;
369-
370- for ( PObjectArray::const_iterator i = value.begin(); i < value.end(); i++ ) {
341+ for ( PObjectArray::const_iterator i = goal.value.begin(); i < goal.value.end(); i++ ) {
371342 const PObject *p = (*i)->getval2( c, vlocal);
372343 if ( p != *i && po == 0 ) {
373- po = pmm.newPArray(c->pobjs, *this);
344+ po = pmm.newPArray(c->pobjs, goal);
374345 }
375346 if ( po ) {
376- po->value[i - value.begin()] = p;
347+ po->value[i - goal.value.begin()] = p;
377348 po->constant = po->constant && p->isc();
378349 }
379350 }
380- return po ? po : this;
351+ return po ? po : &goal;
381352 }
353+const PObject *PArray::getval( ExecContextRoot *c) const { return PArray_getval( *this, c, c->gl); }
354+const PObject *PArray::getval2( ExecContextRoot *c, VLocal *vlocal) const { return PArray_getval( *this, c, vlocal); }
382355
383-const PObject *PPredicate::getval( ExecContextRoot *c) const
356+static inline const PObject *PPredicate_getval( const PPredicate &goal, ExecContextRoot *c, VLocal *vlocal)
384357 {
385- if ( constant ) return this;
358+ if ( goal.constant ) return &goal;
386359
387- const PObject *no = name->getval(c);
388- const PArray *ao = dynamic_cast<const PArray *>(arglist.getval( c));
360+ const PObject *no = goal.name->getval2(c, vlocal);
361+ const PArray *ao = dynamic_cast<const PArray *>(goal.arglist.getval2( c, vlocal));
389362
390- if ( no != name || ao != &arglist ) {
391- PPredicate *po = pmm.newPPredicate(c->pobjs,nspace,no,ao,opt);
363+ if ( no != goal.name || ao != &goal.arglist ) {
364+ PPredicate *po = pmm.newPPredicate(c->pobjs,goal.nspace,no,ao,goal.opt);
392365 return po;
393366 }
394367
395- return this;
368+ return &goal;
396369 }
370+const PObject *PPredicate::getval( ExecContextRoot *c) const { return PPredicate_getval( *this, c, c->gl); }
371+const PObject *PPredicate::getval2( ExecContextRoot *c, VLocal *vlocal) const { return PPredicate_getval( *this, c, vlocal); }
397372
398-const PObject *PPredicate::getval2( ExecContextRoot *c, VLocal *vlocal) const
373+static inline const PObject *PVeriable_getval( const PVeriable &goal, ExecContextRoot *c, VLocal *vlocal)
399374 {
400- if ( constant ) return this;
401-
402- const PObject *no = name->getval2(c, vlocal);
403- const PArray *ao = dynamic_cast<const PArray *>(arglist.getval2( c, vlocal));
404-
405- if ( no != name || ao != &arglist ) {
406- PPredicate *po = pmm.newPPredicate(c->pobjs,nspace,no,ao,opt);
407- return po;
408- }
409-
410- return this;
411-}
412-
413-const PObject *PVeriable::getval( ExecContextRoot *c) const
414-{
415- assert( idx < c->gl->size());
416- const PObject *item = (*c->gl)[idx];
417- if ( item == 0 ) {
418- PObject *po = pmm.newPEVeriable(c->pobjs, *this, c->gl);
419- return po;
420- } else {
421- return item->getval(c);
422- }
423-}
424-
425-const PObject *PVeriable::getval2( ExecContextRoot *c, VLocal *vlocal) const
426-{
427375 assert( idx < vlocal->size());
428- const PObject *item = (*vlocal)[idx];
376+ const PObject *item = (*vlocal)[goal.idx];
429377 if ( item == 0 ) {
430- PObject *po = pmm.newPEVeriable(c->pobjs, *this, vlocal);
378+ PObject *po = pmm.newPEVeriable(c->pobjs, goal, vlocal);
431379 return po;
432380 } else {
433381 return item->getval2(c, vlocal);
434382 }
435383 }
384+const PObject *PVeriable::getval( ExecContextRoot *c) const { return PVeriable_getval( *this, c, c->gl); }
385+const PObject *PVeriable::getval2( ExecContextRoot *c, VLocal *vlocal) const { return PVeriable_getval( *this, c, vlocal); }
436386
437387 const PObject *PEVeriable::getval( ExecContextRoot *c) const { return GetValsOne<const PObject *>( *this, c, vl, &PObject::getval, this); }
438388 const PObject *PEVeriable::getval2( ExecContextRoot *c, VLocal *) const { return GetValsTwo<const PObject *>( *this, c, vl, vl, &PObject::getval2, this); }
--- trunk/adp_compile.h (revision 291)
+++ trunk/adp_compile.h (revision 292)
@@ -106,7 +106,6 @@
106106
107107 // PObject ADPの各言語要素のオブジェクト
108108 class PObject {
109- friend class PMemoryManager;
110109 public:
111110 // コンパイル関係
112111 virtual bool isMyObject(char keychar) const = 0; // 文字からオブジェクトを決める
@@ -322,8 +321,6 @@
322321 EXTERN PNil pnil;
323322
324323 class PString : public PObject {
325- friend class PMemoryManager;
326-
327324 public:
328325 string value;
329326 PString() : value() {}
@@ -448,8 +445,6 @@
448445 };
449446
450447 class PDouble : public PObject {
451- friend class PMemoryManager;
452-
453448 public:
454449 double value;
455450
@@ -561,7 +556,6 @@
561556 };
562557
563558 class PInteger : public PObject {
564- friend class PMemoryManager;
565559 public:
566560 PINTEGER value;
567561
@@ -710,14 +704,11 @@
710704 EXTERN PInteger ptrue;
711705
712706 class PList : public PObject {
713- friend class PMemoryManager;
714- friend bool PList_unify(const PList &goal, const PNil &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal);
715- friend bool PList_unify(const PList &goal, const PList &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal);
716-
707+public:
717708 PObject *lvalue;
718709 PObject *rvalue;
719710 bool constant;
720-public:
711+
721712 void init() { lvalue = &pnil; rvalue = &pnil; constant = false; }
722713 void init(const PList &rhs) { lvalue = rhs.lvalue; rvalue = rhs.rvalue; constant = rhs.constant; }
723714 void init(PObject *lvalue_, PObject *rvalue_) { lvalue = lvalue_; rvalue = rvalue_; constant = lvalue->isc() && rvalue->isc(); }
@@ -904,17 +895,13 @@
904895
905896
906897 class PArray : public PObject {
907- friend class PMemoryManager;
908- friend class PList;
909- friend class PPredicate;
910- friend bool PArray_unify(const PArray &goal, const PArray &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal);
911898 public:
912899 HashArrayMap hamap_;
913900 const HashArrayMap *hamap;
914-private:
901+
915902 bool constant;
916903 bool args;
917-public:
904+
918905 bool type;
919906 bool brace;
920907 PObjectArray value;
@@ -1260,14 +1247,6 @@
12601247 class ExpressionCompileContext;
12611248
12621249 class PPredicate : public PObject {
1263- friend class PHorn;
1264- friend class PMemoryManager;
1265- friend class PGoal;
1266- friend class ExpressionCompileContext;
1267- friend struct ExecContextRoot;
1268- friend struct ExecContextBase;
1269- friend bool PPredicate_unify(const PPredicate &goal, const PPredicate &horn, ExecContextRoot *c, VLocal *glocal, VLocal *hlocal);
1270-
12711250 public:
12721251 string nspace; // 名前空間
12731252 const PObject *name; // コンパイル時にPStringまたは、PVeriableに
@@ -1276,7 +1255,7 @@
12761255 PredicateOption opt; // ポストフィックスオプション
12771256 mutable ExecContext_Factory *factory; // ExecContext_Factoryへのポインタ
12781257 mutable PHorns *horns; // 評価中のHornsへのポインタ
1279-public:
1258+
12801259 void init() { nspace = ""; name = 0; arglist.clear(); constant = false; opt.clear(); factory = 0; horns = 0; }
12811260 void init( const PPredicate &rhs) { nspace = ""; name = rhs.name; arglist = rhs.arglist; constant = rhs.constant; opt = rhs.opt; factory = 0; horns = 0; } // 浅いコピー
12821261 void init( const string &nspace_, const PObject *name_, const PArray *arglist_, const PredicateOption &opt_) { nspace = nspace_; name =name_; arglist = *arglist_; constant = name_->isc() && arglist_->isc(); opt = opt_; factory = 0; horns = 0; }
@@ -1420,17 +1399,11 @@
14201399
14211400
14221401 class PVeriable : public PObject {
1423- friend class PMemoryManager;
1424- friend class PWildCard;
1425- friend class PEVeriable;
1426- friend class PPredicate;
1427-protected:
1402+public:
14281403 string name;
14291404 bool args;
1430-public:
14311405 size_t idx;
14321406
1433-public:
14341407 PVeriable() : name(),idx(0), args(false) { --idx; }
14351408 explicit PVeriable( const PVeriable &rhs) : name(rhs.name), idx(rhs.idx), args(rhs.args) {}
14361409
@@ -1521,9 +1494,9 @@
15211494 };
15221495
15231496 class PWildCard : public PObject {
1497+public:
15241498 bool args;
15251499
1526-public:
15271500 PWildCard() : args(false) {}
15281501 explicit PWildCard( const PVeriable &rhs) : args(rhs.args) {}
15291502
@@ -1600,15 +1573,12 @@
16001573 EXTERN PWildCard pwildcard;
16011574
16021575 class PEVeriable : public PObject {
1603- friend class PMemoryManager;
1604-protected:
1576+public:
16051577 string name;
16061578 bool args;
1607-public:
16081579 size_t idx;
16091580 VLocal *vl;
16101581
1611-public:
16121582 PEVeriable() : name(),idx(0), args(false), vl(0) { --idx;}
16131583
16141584 void init( const PVeriable &rhs, VLocal *vl_) { name =rhs.name; idx = rhs.idx; args = rhs.args; vl = vl_; }
@@ -1687,16 +1657,11 @@
16871657
16881658
16891659 class PGoal : public PObject {
1690- friend class PHorn;
1691- friend class PMemoryManager;
1692- friend struct ExecContext;
1693- friend struct GlobalContext;
1694-
1660+public:
16951661 PObjectArray body;
16961662 bool constant;
16971663 bool nobacktrack; // バックトラックを受け付けない(ゴールの一番最後が!で終わっている)
16981664
1699-public:
17001665 PGoal() : body(), constant(false), nobacktrack(false) {}
17011666 explicit PGoal( const PGoal &rhs) : body(rhs.body), constant(rhs.constant), nobacktrack(rhs.nobacktrack) {}
17021667
@@ -1754,17 +1719,16 @@
17541719 const PObject *getPredicate( size_t idx) const { return body[idx]; }
17551720 void make_prt_code(const string &str);
17561721 };
1757-typedef vector<PGoal *> PGoalsp;
17581722
17591723
17601724 class PHorn : public PObject {
1761- friend struct ExecContext;
1725+public:
17621726 PPredicate head;
17631727 PGoal body;
17641728 size_t vcnt;
17651729 VNames vnames;
17661730 bool constant;
1767-public:
1731+
17681732 PHorn() : head(), body(), vcnt(0), vnames(), constant(false) {}
17691733 explicit PHorn( const PHorn &rhs) : head(rhs.head), body(rhs.body), vcnt(rhs.vcnt), vnames(rhs.vcnt), constant(rhs.constant) {}
17701734
--- trunk/adp.cpp (revision 291)
+++ trunk/adp.cpp (revision 292)
@@ -23,12 +23,12 @@
2323
2424 // 定数
2525 #ifdef ___X64____
26-#define VERSION_TEXT "ADP Ver 0.82.0291 X64 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
26+#define VERSION_TEXT "ADP Ver 0.82.0292 X64 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
2727 #else
2828 #if _WIN32
29-#define VERSION_TEXT "ADP Ver 0.82.0291 x86 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
29+#define VERSION_TEXT "ADP Ver 0.82.0292 x86 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
3030 #else
31-#define VERSION_TEXT "ADP Ver 0.82.0291 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
31+#define VERSION_TEXT "ADP Ver 0.82.0292 (http://www.adp.la/)\nCopyright (C) 2010-2012 Katsuhisa Ohfuji. This progman is distributed under GPL.\n"
3232 #endif
3333 #endif
3434
Show on old repository browser