Skip to content

Commit 1051323

Browse files
committed
ast-exporter + transpile: Rename some things
1 parent 0a9f93a commit 1051323

5 files changed

Lines changed: 38 additions & 38 deletions

File tree

c2rust-ast-exporter/src/AstExporter.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
711711
class TranslateASTVisitor final
712712
: public RecursiveASTVisitor<TranslateASTVisitor> {
713713

714-
struct MacroExpansionInfo {
714+
struct MacroDeclInfo {
715715
StringRef Name;
716716
};
717717

@@ -723,13 +723,13 @@ class TranslateASTVisitor final
723723
// Mapping from SourceManager FileID to index in files
724724
DenseMap<FileID, size_t> file_id_mapping;
725725
std::set<std::pair<void *, ASTEntryTag>> exportedTags;
726-
std::unordered_map<MacroInfo*, MacroExpansionInfo> macros;
726+
std::unordered_map<MacroInfo*, MacroDeclInfo> macros;
727727

728728
// This stores a raw encoding of the macro call site SourceLocation, since
729729
// SourceLocation isn't hashable.
730730
std::unordered_set<unsigned> macroCallSites;
731-
SmallVector<MacroInfo*, 1> curMacroExpansionStack;
732-
StringRef curMacroExpansionSource;
731+
SmallVector<MacroInfo*, 1> curMacroInvocationStack;
732+
StringRef curMacroInvocationSource;
733733

734734
// Returns true when a new entry is added to exportedTags
735735
bool markForExport(void *ptr, ASTEntryTag tag) {
@@ -769,7 +769,7 @@ class TranslateASTVisitor final
769769
// Template required because Decl and Stmt don't share a common base class
770770
void encode_entry_raw(void *ast, ASTEntryTag tag, SourceRange loc,
771771
const QualType ty, bool rvalue,
772-
bool isVaList, bool encodeMacroExpansions,
772+
bool isVaList, bool encodeMacroInvocations,
773773
const std::vector<void *> &childIds,
774774
std::function<void(CborEncoder *)> extra) {
775775
if (!markForExport(ast, tag))
@@ -808,21 +808,21 @@ class TranslateASTVisitor final
808808
// 9 - Is Rvalue (only for expressions)
809809
cbor_encode_boolean(&local, rvalue);
810810

811-
// 10 - Macro expansion stack, starting with initial macro call and ending
811+
// 10 - Macro invocation stack, starting with initial macro call and ending
812812
// with the innermost replacement.
813813
cbor_encoder_create_array(&local, &childEnc,
814-
encodeMacroExpansions ? curMacroExpansionStack.size() : 0);
815-
if (encodeMacroExpansions) {
816-
for (auto I = curMacroExpansionStack.rbegin(), E = curMacroExpansionStack.rend();
814+
encodeMacroInvocations ? curMacroInvocationStack.size() : 0);
815+
if (encodeMacroInvocations) {
816+
for (auto I = curMacroInvocationStack.rbegin(), E = curMacroInvocationStack.rend();
817817
I != E; ++I) {
818818
cbor_encode_uint(&childEnc, uintptr_t(*I));
819819
}
820820
}
821821
cbor_encoder_close_container(&local, &childEnc);
822822

823-
// 11 - Macro expansion source string, if applicable.
824-
if (!curMacroExpansionSource.empty()) {
825-
cbor_encode_string(&local, curMacroExpansionSource.str());
823+
// 11 - Macro invocation source string, if applicable.
824+
if (!curMacroInvocationSource.empty()) {
825+
cbor_encode_string(&local, curMacroInvocationSource.str());
826826
} else {
827827
cbor_encode_null(&local);
828828
}
@@ -846,7 +846,7 @@ class TranslateASTVisitor final
846846
std::function<void(CborEncoder *)> extra = [](CborEncoder *) {}) {
847847
auto ty = ast->getType();
848848
auto isVaList = false;
849-
auto encodeMacroExpansions = true;
849+
auto encodeMacroInvocations = true;
850850
#if CLANG_VERSION_MAJOR < 13
851851
bool isRValue = ast->isRValue();
852852
#else
@@ -860,7 +860,7 @@ class TranslateASTVisitor final
860860
auto span = ast->getSourceRange();
861861
expandSpanToFinalChar(span, Context);
862862
encode_entry_raw(ast, tag, span, ty, isRValue, isVaList,
863-
encodeMacroExpansions, childIds, extra);
863+
encodeMacroInvocations, childIds, extra);
864864
typeEncoder.VisitQualTypeOf(ty, ast);
865865
}
866866

@@ -870,23 +870,23 @@ class TranslateASTVisitor final
870870
QualType s = QualType(static_cast<clang::Type *>(nullptr), 0);
871871
auto rvalue = false;
872872
auto isVaList = false;
873-
auto encodeMacroExpansions = false;
873+
auto encodeMacroInvocations = false;
874874
auto span = ast->getSourceRange();
875875
expandSpanToFinalChar(span, Context);
876876
encode_entry_raw(ast, tag, span, s, rvalue, isVaList,
877-
encodeMacroExpansions, childIds, extra);
877+
encodeMacroInvocations, childIds, extra);
878878
}
879879

880880
void encode_entry(
881881
Decl *ast, ASTEntryTag tag, const std::vector<void *> &childIds,
882882
const QualType T,
883883
std::function<void(CborEncoder *)> extra = [](CborEncoder *) {}) {
884884
auto rvalue = false;
885-
auto encodeMacroExpansions = false;
885+
auto encodeMacroInvocations = false;
886886
auto span = ast->getSourceRange();
887887
expandSpanToFinalChar(span, Context);
888888
encode_entry_raw(ast, tag, span, T, rvalue,
889-
isVaList(ast, T), encodeMacroExpansions, childIds, extra);
889+
isVaList(ast, T), encodeMacroInvocations, childIds, extra);
890890
}
891891

892892
/// Explicitly override the source location of this decl for cases where the
@@ -897,10 +897,10 @@ class TranslateASTVisitor final
897897
const std::vector<void *> &childIds, const QualType T,
898898
std::function<void(CborEncoder *)> extra = [](CborEncoder *) {}) {
899899
auto rvalue = false;
900-
auto encodeMacroExpansions = false;
900+
auto encodeMacroInvocations = false;
901901
expandSpanToFinalChar(loc, Context);
902902
encode_entry_raw(ast, tag, loc, T, rvalue,
903-
isVaList(ast, T), encodeMacroExpansions, childIds, extra);
903+
isVaList(ast, T), encodeMacroInvocations, childIds, extra);
904904
}
905905

906906
bool VisitMacro(StringRef name, SourceLocation loc, MacroInfo *mac, Expr *E) {
@@ -973,11 +973,11 @@ class TranslateASTVisitor final
973973

974974
void encodeMacros() {
975975
// Sort macros by source location
976-
std::vector<std::pair<MacroInfo *, MacroExpansionInfo>> macro_vec(
976+
std::vector<std::pair<MacroInfo *, MacroDeclInfo>> macro_vec(
977977
macros.begin(), macros.end());
978978
std::sort(macro_vec.begin(), macro_vec.end(),
979-
[](const std::pair<MacroInfo *, MacroExpansionInfo> &a,
980-
const std::pair<MacroInfo *, MacroExpansionInfo> &b) {
979+
[](const std::pair<MacroInfo *, MacroDeclInfo> &a,
980+
const std::pair<MacroInfo *, MacroDeclInfo> &b) {
981981
return a.first->getDefinitionLoc() <
982982
b.first->getDefinitionLoc();
983983
});
@@ -1369,8 +1369,8 @@ class TranslateASTVisitor final
13691369
//
13701370

13711371
bool VisitExpr(Expr *E) {
1372-
curMacroExpansionStack.clear();
1373-
curMacroExpansionSource = StringRef();
1372+
curMacroInvocationStack.clear();
1373+
curMacroInvocationSource = StringRef();
13741374

13751375
// We only translate constant macro objects to Rust consts, so this
13761376
// expression must be constant.
@@ -1396,7 +1396,7 @@ class TranslateASTVisitor final
13961396
return true;
13971397
}
13981398

1399-
curMacroExpansionSource =
1399+
curMacroInvocationSource =
14001400
Lexer::getSourceText(ExpansionStack[0].range, Mgr, Context->getLangOpts());
14011401

14021402
for (auto &elem : ExpansionStack) {
@@ -1418,7 +1418,7 @@ class TranslateASTVisitor final
14181418
}
14191419

14201420
if (VisitMacro(IdentifierInfo->getName(), loc, MacroInfo, E)) {
1421-
curMacroExpansionStack.push_back(MacroInfo);
1421+
curMacroInvocationStack.push_back(MacroInfo);
14221422
}
14231423
}
14241424

c2rust-ast-exporter/src/clang_ast.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub struct AstNode {
108108
// Stack of macros this node was expanded from, beginning with the initial
109109
// macro call and ending with the leaf. This needs to be a stack for nested
110110
// macro definitions.
111-
pub macro_expansions: Vec<u64>,
112-
pub macro_expansion_text: Option<String>,
111+
pub macro_invocations: Vec<u64>,
112+
pub macro_invocation_text: Option<String>,
113113
pub extras: Vec<Value>,
114114
}
115115

@@ -260,9 +260,9 @@ pub fn process(items: Value) -> error::Result<AstContext> {
260260
};
261261

262262
// entry[10]
263-
let macro_expansions = from_value::<Vec<u64>>(entry.pop_front().unwrap()).unwrap();
263+
let macro_invocations = from_value::<Vec<u64>>(entry.pop_front().unwrap()).unwrap();
264264

265-
let macro_expansion_text = expect_opt_str(&entry.pop_front().unwrap())
265+
let macro_invocation_text = expect_opt_str(&entry.pop_front().unwrap())
266266
.unwrap()
267267
.map(|s| s.to_string());
268268

@@ -278,8 +278,8 @@ pub fn process(items: Value) -> error::Result<AstContext> {
278278
},
279279
type_id,
280280
rvalue,
281-
macro_expansions,
282-
macro_expansion_text,
281+
macro_invocations,
282+
macro_invocation_text,
283283
extras: entry.into_iter().collect(),
284284
};
285285

c2rust-transpile/src/c_ast/conversion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ impl ConversionContext {
10241024
};
10251025

10261026
if expected_ty & EXPR != 0 {
1027-
for mac_id in &node.macro_expansions {
1027+
for mac_id in &node.macro_invocations {
10281028
let mac = CDeclId(self.visit_node_type(*mac_id, MACRO_DECL));
10291029
self.typed_context
10301030
.macro_invocations
@@ -1034,9 +1034,9 @@ impl ConversionContext {
10341034
}
10351035
}
10361036

1037-
if let Some(text) = &node.macro_expansion_text {
1037+
if let Some(text) = &node.macro_invocation_text {
10381038
self.typed_context
1039-
.macro_expansion_text
1039+
.macro_invocation_text
10401040
.insert(CExprId(new_id), text.clone());
10411041
}
10421042

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct TypedAstContext {
110110

111111
/// map expressions to the text of the macro invocation they expanded from,
112112
/// if any
113-
pub macro_expansion_text: IndexMap<CExprId, String>,
113+
pub macro_invocation_text: IndexMap<CExprId, String>,
114114

115115
pub comments: Vec<Located<String>>,
116116

c2rust-transpile/src/translator/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ impl<'c> Translation<'c> {
29392939
}
29402940

29412941
{
2942-
let text = self.ast_context.macro_expansion_text.get(&expr_id);
2942+
let text = self.ast_context.macro_invocation_text.get(&expr_id);
29432943
if let Some(converted) =
29442944
text.and_then(|text| self.convert_fn_macro_invocation(ctx, text))
29452945
{

0 commit comments

Comments
 (0)