YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
NPLA1.cpp
浏览该文件的文档.
1 /*
2  © 2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #include "NPL/YModules.h"
29 #include YFM_NPL_NPLA1
30 #include YFM_NPL_SContext
31 
32 using namespace YSLib;
33 
34 namespace NPL
35 {
36 
39 {
40  auto s(node.GetSize());
41 
42  if(s == 0)
43  return {0, "", node ? Deliteralize(Access<string>(node)) : string()};
44 
45  auto i(node.begin());
46 
47  if(s == 1)
48  return TransformNPLA1(*i);
49 
50  const auto& new_name([&]()->string{
51  try
52  {
53  const auto& str(Access<string>(*i));
54 
55  yunseq(++i, --s);
56  return str;
57  }
58  catch(ystdex::bad_any_cast&)
59  {}
60  return string();
61  }());
62 
63  if(s == 1)
64  {
65  auto&& n(TransformNPLA1(*i));
66 
67  if(n.GetName().empty())
68  return {0, new_name, std::move(n.Value)};
69  return {0, new_name, ValueNode::Container{std::move(n)}};
70  }
71 
72  auto p_node_cont(make_unique<ValueNode::Container>());
73 
74  std::for_each(i, node.end(), [&](const ValueNode& nd){
75  auto&& n(TransformNPLA1(nd));
76 
77  p_node_cont->insert(n.GetName().empty() ? ValueNode{0,
78  '$' + std::to_string(p_node_cont->size()), std::move(n.Value)}
79  : std::move(n));
80  });
81  return {0, new_name, std::move(p_node_cont), PointerTag()};
82 }
83 
84 
87 {
88  ValueNode root;
89 
90  try
91  {
92  root = TransformNPLA1(tree);
93  }
94  catch(ystdex::bad_any_cast& e)
95  {
96  // TODO: Avoid memory allocation.
98  "Bad configuration found: cast failed from [%s] to [%s] .",
99  e.from(), e.to()), Warning);
100  }
101  return root;
102 }
103 
104 } // namespace NPL;
105 
set< ValueNode > Container
Definition: ValueNode.h:48
动态泛型转换失败异常。
Definition: any.h:741
const char * to() const
Definition: any.h:768
YF_API string Deliteralize(const string &)
去除字面量边界分隔符。
Definition: Lexical.cpp:185
YF_API ValueNode LoadNPLA1(ValueNode &&)
读取 NPLA1 翻译单元。
Definition: NPLA1.cpp:86
指示指针的标记。
Definition: yobject.h:63
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:748
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
值类型节点。
Definition: ValueNode.h:45
std::string to_string(unsigned char val)
转换为字符串。
Definition: string.hpp:353
YF_API ValueNode TransformNPLA1(const ValueNode &)
转换设置: S 表达式抽象语法树变换为 NPLA1 语义结构。
Definition: NPLA1.cpp:38
Container Value const string name size_t GetSize() const ynothrow
Definition: ValueNode.cpp:47
记录日志的异常事件类。
Definition: yexcept.h:58
std::basic_string< _tChar > sfmt(const _tChar *fmt,...)
以 C 标准输出格式的输出 std::basic_string 实例的对象。
Definition: string.hpp:399
const char * from() const
Definition: any.h:762