forked from gfwilliams/tiny-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptPosition.cpp
More file actions
66 lines (57 loc) · 1.24 KB
/
ScriptPosition.cpp
File metadata and controls
66 lines (57 loc) · 1.24 KB
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
/*
* File: ScriptPosition.cpp
* Author: ghernan
*
* Classes to handle source and object code positions.
*
* Created on March 1, 2017, 7:58 PM
*/
#include "ascript_pch.hpp"
#include "ScriptPosition.h"
using namespace std;
/**
* String representation of a Script position.
* @return
*/
string ScriptPosition::toString()const
{
char buffer [128];
sprintf_s(buffer, "(line: %d, col: %d): ", this->line, this->column);
return string(buffer);
}
/**
* Gets an script position from an WM position
* @param vmPos
* @return
*/
const ScriptPosition& CodeMap::get(const VmPosition& vmPos)const
{
const static ScriptPosition nullPosition;
if (m_vm2sc.empty())
return nullPosition;
else
{
auto it = m_vm2sc.upper_bound(vmPos);
if (it != m_vm2sc.begin())
--it;
return it->second;
}
}
/**
* Adds a new entry to the map.
* @param vmPos
* @param scPos
* @return
*/
bool CodeMap::add (const VmPosition& vmPos, const ScriptPosition& scPos)
{
auto it = m_sc2vm.find(scPos);
if (it == m_sc2vm.end() || vmPos < it->second)
{
m_sc2vm[scPos] = vmPos;
m_vm2sc[vmPos] = scPos;
return true;
}
else
return false;
}