Skip to content

Commit e3a5d72

Browse files
committed
True Initial Commit
1 parent 4d1dd51 commit e3a5d72

File tree

9 files changed

+994
-0
lines changed

9 files changed

+994
-0
lines changed

Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

VCMangler.cabal

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: VCMangler
2+
version: 0.1.0.0
3+
synopsis: Initial project template from stack
4+
description: Please see README.md
5+
homepage: https://github.com/githubuser/VCMangler#readme
6+
license: BSD3
7+
license-file: LICENSE
8+
author: Micah Hahn
9+
maintainer: [email protected]
10+
copyright: 2016 Micah Hahn
11+
category: Web
12+
build-type: Simple
13+
-- extra-source-files:
14+
cabal-version: >=1.10
15+
16+
library
17+
hs-source-dirs: src, src/VCMangler
18+
exposed-modules: VCMangler, VCMangler.Types, VCMangler.Maps, VCMangler.Parsers
19+
build-depends: base >= 4.7 && < 5
20+
, parsec
21+
default-language: Haskell2010
22+
23+
executable VCMangler-exe
24+
hs-source-dirs: app
25+
main-is: Main.hs
26+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
27+
build-depends: base
28+
, VCMangler
29+
default-language: Haskell2010
30+
31+
test-suite VCMangler-test
32+
type: exitcode-stdio-1.0
33+
hs-source-dirs: test
34+
main-is: Spec.hs
35+
build-depends: base
36+
, HUnit
37+
, VCMangler
38+
, parsec
39+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
40+
default-language: Haskell2010
41+
42+
source-repository head
43+
type: git
44+
location: https://github.com/githubuser/VCMangler

app/Main.hs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# LANGUAGE GADTs #-}
2+
3+
module Main where
4+
5+
import System.Environment (getArgs)
6+
7+
import VCMangler
8+
9+
parse l = case parseMangledName l of
10+
(Left a) -> show a
11+
(Right b) -> show b
12+
13+
main :: IO ()
14+
main = do
15+
[inputFile, outputFile] <- getArgs
16+
content <- readFile inputFile
17+
writeFile outputFile $ unlines $ map (\l -> parse l ++ " " ++ l) (lines content)

src/VCMangler.hs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module VCMangler
2+
(
3+
parseMangledName,
4+
UnmangledName(..),
5+
QualifiedName(..),
6+
Convention(..),
7+
Distance(..),
8+
Access(..),
9+
MethodType(..),
10+
FunctionModifiers(..),
11+
Type(..),
12+
Modifier(..),
13+
CompositeType(..),
14+
TemplateArgument(..),
15+
Operator(..)
16+
) where
17+
18+
import Text.Parsec
19+
20+
import VCMangler.Types
21+
import VCMangler.Parsers
22+
23+
parseMangledName :: String -> Either String UnmangledName
24+
parseMangledName s = case runParser mangledParser (MangledState [] []) "(source)" s of
25+
(Left error) -> Left (show error)
26+
(Right u) -> Right u

src/VCMangler/Maps.hs

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
module VCMangler.Maps
2+
(
3+
operatorCodeRange,
4+
operatorUCodeRange,
5+
codeToOperator,
6+
encodingToHex,
7+
typeCodeRange,
8+
typeUCodeRange,
9+
codeToType,
10+
compositeCodeRange,
11+
codeToComposite,
12+
codeToPointerModifier,
13+
pointerModifierCodeRange,
14+
modifiersCodeRange,
15+
codeToModifiers,
16+
globalFunctionModifiersCodeRange,
17+
codeToGlobalFunctionModifiers,
18+
memberFunctionModifiersCodeRange,
19+
codeToMemberFunctionModifiers,
20+
callingConventionCodeRange,
21+
codeToCallingConvention
22+
) where
23+
24+
import VCMangler.Types
25+
import Data.Maybe (fromMaybe)
26+
27+
lookupOrFail :: (Eq a) => [(a, b)] -> a -> b
28+
lookupOrFail abs a = fromMaybe (error "Out or range") (lookup a abs)
29+
30+
operatorMap =
31+
[ ("0", OpConstructor)
32+
, ("1", OpDestructor)
33+
, ("2", OpNew)
34+
, ("3", OpDelete)
35+
, ("4", OpAssign)
36+
, ("5", OpRightShift)
37+
, ("6", OpLeftShift)
38+
, ("7", OpNot)
39+
, ("8", OpEquals)
40+
, ("9", OpNotEquals)
41+
, ("A", OpIndex)
42+
, ("B", OpType)
43+
, ("C", OpArrow)
44+
, ("D", OpStar)
45+
, ("E", OpIncrement)
46+
, ("F", OpDecrement)
47+
, ("G", OpMinus)
48+
, ("H", OpPlus)
49+
, ("I", OpAmpersand)
50+
, ("J", OpArrowStar)
51+
, ("K", OpDivide)
52+
, ("L", OpModulus)
53+
, ("M", OpLess)
54+
, ("N", OpGreater)
55+
, ("O", OpLessEqual)
56+
, ("P", OpGreaterEqual)
57+
, ("Q", OpComma)
58+
, ("R", OpCall)
59+
, ("S", OpComplement)
60+
, ("T", OpBitXor)
61+
, ("U", OpBitOr)
62+
, ("V", OpAnd)
63+
, ("W", OpOr)
64+
, ("X", OpMultiplyAssign)
65+
, ("Y", OpPlusAssign)
66+
, ("Z", OpMinusAssign)
67+
, ("_0", OpDivideAssign)
68+
, ("_1", OpModulusAssign)
69+
, ("_2", OpRightShiftAssign)
70+
, ("_3", OpLeftShiftAssign)
71+
, ("_4", OpBitAndAssign)
72+
, ("_5", OpBitOrAssign)
73+
, ("_6", OpBitXorAssign)
74+
, ("_7", OpVirtualTable)
75+
]
76+
77+
operatorCodeRange = ['0'..'9'] ++ ['A'..'Z']
78+
operatorUCodeRange = ['0'..'7']
79+
80+
codeToOperator :: String -> Operator
81+
codeToOperator = lookupOrFail operatorMap
82+
83+
hexEncodingMap =
84+
[ ('A', '0')
85+
, ('B', '1')
86+
, ('C', '2')
87+
, ('D', '3')
88+
, ('E', '4')
89+
, ('F', '5')
90+
, ('G', '6')
91+
, ('H', '7')
92+
, ('I', '8')
93+
, ('J', '9')
94+
, ('K', 'A')
95+
, ('L', 'B')
96+
, ('M', 'C')
97+
, ('N', 'D')
98+
, ('O', 'E')
99+
, ('P', 'F')
100+
]
101+
102+
encodingToHex :: Char -> Char
103+
encodingToHex = lookupOrFail hexEncodingMap
104+
105+
typeMap =
106+
[ ("C", SChar_)
107+
, ("D", Char_)
108+
, ("E", UChar_)
109+
, ("F", Short_)
110+
, ("G", UShort_)
111+
, ("H", Int_)
112+
, ("I", UInt_)
113+
, ("J", Long_)
114+
, ("K", ULong_)
115+
, ("M", Float_)
116+
, ("N", Double_)
117+
, ("X", Void_)
118+
, ("Z", VarArgs_)
119+
, ("_N", Bool_)
120+
, ("_J", LongLong_)
121+
, ("_K", ULongLong_)
122+
, ("_W", WCharT_)
123+
]
124+
125+
typeCodeRange = "MNXZ" ++ ['C'..'K']
126+
typeUCodeRange = "NJKW"
127+
128+
codeToType :: String -> Type
129+
codeToType = lookupOrFail typeMap
130+
131+
compositeMap =
132+
[ ("T", Union)
133+
, ("U", Struct)
134+
, ("V", Class)
135+
, ("W4", Enum)
136+
]
137+
138+
compositeCodeRange = ['T'..'V']
139+
140+
codeToComposite :: String -> CompositeType
141+
codeToComposite = lookupOrFail compositeMap
142+
143+
pointerModifierMap =
144+
[ ('P', [])
145+
, ('Q', [Const])
146+
, ('R', [Volatile])
147+
, ('S', [Const, Volatile])
148+
]
149+
150+
pointerModifierCodeRange = ['P'..'S']
151+
152+
codeToPointerModifier :: Char -> [Modifier]
153+
codeToPointerModifier = lookupOrFail pointerModifierMap
154+
155+
modifiersMap =
156+
[ ('A', [])
157+
, ('B', [Const])
158+
, ('C', [Volatile])
159+
, ('D', [Const, Volatile])
160+
]
161+
162+
modifiersCodeRange = ['A'..'D']
163+
164+
codeToModifiers :: Char -> [Modifier]
165+
codeToModifiers = lookupOrFail modifiersMap
166+
167+
globalFunctionModifiersMap =
168+
[ ('Y', Near)
169+
, ('Z', Far)
170+
]
171+
172+
globalFunctionModifiersCodeRange = ['Y', 'Z']
173+
174+
codeToGlobalFunctionModifiers :: Char -> Distance
175+
codeToGlobalFunctionModifiers = lookupOrFail globalFunctionModifiersMap
176+
177+
memberFunctionModifiersMap =
178+
[ ('A', (Method, Near, Private))
179+
, ('B', (Method, Far, Private))
180+
, ('C', (Static, Near, Private))
181+
, ('D', (Static, Far, Private))
182+
, ('E', (Virtual, Near, Private))
183+
, ('F', (Virtual, Far, Private))
184+
, ('I', (Method, Near, Protected))
185+
, ('J', (Method, Far, Protected))
186+
, ('K', (Static, Near, Protected))
187+
, ('L', (Static, Far, Protected))
188+
, ('M', (Virtual, Near, Protected))
189+
, ('N', (Virtual, Far, Protected))
190+
, ('Q', (Method, Near, Public))
191+
, ('R', (Method, Far, Public))
192+
, ('S', (Static, Near, Public))
193+
, ('T', (Static, Far, Public))
194+
, ('U', (Virtual, Near, Public))
195+
, ('V', (Virtual, Far, Public))
196+
]
197+
198+
memberFunctionModifiersCodeRange = ['A'..'F'] ++ ['I'..'N'] ++ ['Q'..'V']
199+
200+
codeToMemberFunctionModifiers :: Char -> (MethodType, Distance, Access)
201+
codeToMemberFunctionModifiers = lookupOrFail memberFunctionModifiersMap
202+
203+
callingConventionMap =
204+
[ ('A', CDecl)
205+
, ('C', Pascal)
206+
, ('E', ThisCall)
207+
, ('G', StdCall)
208+
, ('I', FastCall)
209+
]
210+
211+
callingConventionCodeRange = ['A', 'C', 'E', 'G', 'I']
212+
213+
codeToCallingConvention :: Char -> Convention
214+
codeToCallingConvention = lookupOrFail callingConventionMap

0 commit comments

Comments
 (0)