File: lspfundec.cc

package info (click to toggle)
asymptote 3.05%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,420 kB
  • sloc: cpp: 172,663; ansic: 69,690; python: 14,957; sh: 5,605; javascript: 4,871; lisp: 1,507; perl: 1,417; makefile: 1,026; yacc: 610; lex: 449; xml: 182; asm: 8
file content (108 lines) | stat: -rw-r--r-- 2,664 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
 * @file lspfundec.cc
 * @brief For createSymMap and other lsp-related functions
 * specific to Lsp in *fundef classes.
 * @author Supakorn 'Jamie' Rassameemasmuang (jamievlin at outlook.com)
 */

#include "common.h"
#include "fundec.h"
#include "stm.h"

#define DEC_CREATE_SYM_MAP_FUNDEC(derived_class)                               \
  void derived_class::createSymMap(AsymptoteLsp::SymbolContext* symContext)

namespace absyntax
{
#ifdef HAVE_LSP

DEC_CREATE_SYM_MAP_FUNDEC(formals)
{
  for (auto& field : fields) {
    field->createSymMap(symContext);
  }

  if (rest) {
    rest->createSymMap(symContext);
  }
}

void formals::addArgumentsToFnInfo(AsymptoteLsp::FunctionInfo& fnInfo)
{
  for (auto const& field : fields) {
    fnInfo.arguments.emplace_back(field->fnInfo());
  }

  if (rest) {
    fnInfo.restArgs= rest->fnInfo();
  }
  // handle rest case as well
}

void fundef::addArgumentsToFnInfo(AsymptoteLsp::FunctionInfo& fnInfo)
{
  params->addArgumentsToFnInfo(fnInfo);
  // handle rest case as well
}


DEC_CREATE_SYM_MAP_FUNDEC(fundef)
{
  auto* declCtx(symContext->newContext<AsymptoteLsp::AddDeclContexts>(
          getPos().LineColumn()
  ));
  params->createSymMap(declCtx);
  body->createSymMap(declCtx);
}

DEC_CREATE_SYM_MAP_FUNDEC(fundec)
{
  AsymptoteLsp::FunctionInfo& fnInfo= symContext->symMap.addFunDef(
          static_cast<std::string>(id), getPos().LineColumn(),
          static_cast<std::string>(*fun.result)
  );
  fun.addArgumentsToFnInfo(fnInfo);
  fun.createSymMap(symContext);
}

DEC_CREATE_SYM_MAP_FUNDEC(formal)
{
  if (start) {
    start->createSymMap(symContext);
  }
}

std::pair<std::string, optional<std::string>> formal::fnInfo() const
{
  std::string typeName(static_cast<std::string>(*base));
  return start != nullptr
                 ? std::make_pair(
                           typeName,
                           make_optional(
                                   static_cast<std::string>(start->getName())
                           )
                   )
                 : std::make_pair(typeName, nullopt);
}

#else

#  define DEC_CREATE_SYM_MAP_FUNDEC_EMPTY(derived_class)                       \
    DEC_CREATE_SYM_MAP_FUNDEC(derived_class) {}

DEC_CREATE_SYM_MAP_FUNDEC_EMPTY(formals)
DEC_CREATE_SYM_MAP_FUNDEC_EMPTY(fundef)
DEC_CREATE_SYM_MAP_FUNDEC_EMPTY(fundec)
DEC_CREATE_SYM_MAP_FUNDEC_EMPTY(formal)

void formals::addArgumentsToFnInfo(AsymptoteLsp::FunctionInfo& fnInfo) {}
void fundef::addArgumentsToFnInfo(AsymptoteLsp::FunctionInfo& fnInfo) {}

std::pair<std::string, optional<std::string>> formal::fnInfo() const
{
  return std::make_pair("", nullopt);
}

#endif

}// namespace absyntax